Documentation
¶
Overview ¶
Package codec implements the wire format for agent <-> boundary communication.
Wire Format:
- 8 bits: big-endian tag
- 24 bits: big-endian length of the protobuf data (bit usage depends on tag)
- length bytes: encoded protobuf data
Note that while there are 24 bits available for the length, the actual maximum length depends on the tag. For TagV1, only 15 bits are used (MaxMessageSizeV1).
Index ¶
- Constants
- Variables
- func ReadMessage(r io.Reader, buf []byte) (proto.Message, []byte, error)
- func WriteFrame(w io.Writer, tag Tag, data []byte) error
- func WriteMessage(w io.Writer, tag Tag, msg proto.Message) error
- type BoundaryMessage
- func (*BoundaryMessage) Descriptor() ([]byte, []int)deprecated
- func (x *BoundaryMessage) GetLogs() *proto.ReportBoundaryLogsRequest
- func (m *BoundaryMessage) GetMsg() isBoundaryMessage_Msg
- func (x *BoundaryMessage) GetStatus() *BoundaryStatus
- func (*BoundaryMessage) ProtoMessage()
- func (x *BoundaryMessage) ProtoReflect() protoreflect.Message
- func (x *BoundaryMessage) Reset()
- func (x *BoundaryMessage) String() string
- type BoundaryMessage_Logs
- type BoundaryMessage_Status
- type BoundaryStatus
- func (*BoundaryStatus) Descriptor() ([]byte, []int)deprecated
- func (x *BoundaryStatus) GetDroppedBatchFull() int64
- func (x *BoundaryStatus) GetDroppedChannelFull() int64
- func (*BoundaryStatus) ProtoMessage()
- func (x *BoundaryStatus) ProtoReflect() protoreflect.Message
- func (x *BoundaryStatus) Reset()
- func (x *BoundaryStatus) String() string
- type Tag
Constants ¶
const ( // DataLength is the number of bits used for the length of encoded protobuf data. DataLength = 24 // MaxMessageSizeV1 is the maximum size of the encoded protobuf messages sent // over the wire for the TagV1 tag. While the wire format allows 24 bits for // length, TagV1 only uses 15 bits. MaxMessageSizeV1 uint32 = 1 << 15 // MaxMessageSizeV2 is the maximum data length for TagV2. MaxMessageSizeV2 = MaxMessageSizeV1 )
Variables ¶
var ( // ErrMessageTooLarge is returned when the message exceeds the maximum size // allowed for the tag. ErrMessageTooLarge = xerrors.New("message too large") // ErrUnsupportedTag is returned when an unrecognized tag is encountered. ErrUnsupportedTag = xerrors.New("unsupported tag") )
var File_agent_boundarylogproxy_codec_boundary_proto protoreflect.FileDescriptor
Functions ¶
func ReadMessage ¶ added in v2.32.0
ReadMessage reads a framed message and unmarshals it based on tag. The returned buf should be passed back on the next call for buffer reuse.
func WriteFrame ¶
WriteFrame writes a framed message with the given tag and data. The data must not exceed 2^DataLength in length.
Types ¶
type BoundaryMessage ¶ added in v2.32.0
type BoundaryMessage struct {
// Types that are assignable to Msg:
//
// *BoundaryMessage_Logs
// *BoundaryMessage_Status
Msg isBoundaryMessage_Msg `protobuf_oneof:"msg"`
// contains filtered or unexported fields
}
BoundaryMessage is the envelope for all TagV2 messages sent over the boundary <-> agent unix socket. TagV1 carries a bare ReportBoundaryLogsRequest for backwards compatibility; TagV2 wraps everything in this envelope so the protocol can be extended with new message types without adding more tags.
func (*BoundaryMessage) Descriptor
deprecated
added in
v2.32.0
func (*BoundaryMessage) Descriptor() ([]byte, []int)
Deprecated: Use BoundaryMessage.ProtoReflect.Descriptor instead.
func (*BoundaryMessage) GetLogs ¶ added in v2.32.0
func (x *BoundaryMessage) GetLogs() *proto.ReportBoundaryLogsRequest
func (*BoundaryMessage) GetMsg ¶ added in v2.32.0
func (m *BoundaryMessage) GetMsg() isBoundaryMessage_Msg
func (*BoundaryMessage) GetStatus ¶ added in v2.32.0
func (x *BoundaryMessage) GetStatus() *BoundaryStatus
func (*BoundaryMessage) ProtoMessage ¶ added in v2.32.0
func (*BoundaryMessage) ProtoMessage()
func (*BoundaryMessage) ProtoReflect ¶ added in v2.32.0
func (x *BoundaryMessage) ProtoReflect() protoreflect.Message
func (*BoundaryMessage) Reset ¶ added in v2.32.0
func (x *BoundaryMessage) Reset()
func (*BoundaryMessage) String ¶ added in v2.32.0
func (x *BoundaryMessage) String() string
type BoundaryMessage_Logs ¶ added in v2.32.0
type BoundaryMessage_Logs struct {
Logs *proto.ReportBoundaryLogsRequest `protobuf:"bytes,1,opt,name=logs,proto3,oneof"`
}
type BoundaryMessage_Status ¶ added in v2.32.0
type BoundaryMessage_Status struct {
Status *BoundaryStatus `protobuf:"bytes,2,opt,name=status,proto3,oneof"`
}
type BoundaryStatus ¶ added in v2.32.0
type BoundaryStatus struct {
// Logs dropped because boundary's internal channel buffer was full.
DroppedChannelFull int64 `protobuf:"varint,1,opt,name=dropped_channel_full,json=droppedChannelFull,proto3" json:"dropped_channel_full,omitempty"`
// Logs dropped because boundary's batch buffer was full after a
// failed flush attempt.
DroppedBatchFull int64 `protobuf:"varint,2,opt,name=dropped_batch_full,json=droppedBatchFull,proto3" json:"dropped_batch_full,omitempty"`
// contains filtered or unexported fields
}
BoundaryStatus carries operational metadata from boundary to the agent. The agent records these values as Prometheus metrics. This message is never forwarded to coderd.
func (*BoundaryStatus) Descriptor
deprecated
added in
v2.32.0
func (*BoundaryStatus) Descriptor() ([]byte, []int)
Deprecated: Use BoundaryStatus.ProtoReflect.Descriptor instead.
func (*BoundaryStatus) GetDroppedBatchFull ¶ added in v2.32.0
func (x *BoundaryStatus) GetDroppedBatchFull() int64
func (*BoundaryStatus) GetDroppedChannelFull ¶ added in v2.32.0
func (x *BoundaryStatus) GetDroppedChannelFull() int64
func (*BoundaryStatus) ProtoMessage ¶ added in v2.32.0
func (*BoundaryStatus) ProtoMessage()
func (*BoundaryStatus) ProtoReflect ¶ added in v2.32.0
func (x *BoundaryStatus) ProtoReflect() protoreflect.Message
func (*BoundaryStatus) Reset ¶ added in v2.32.0
func (x *BoundaryStatus) Reset()
func (*BoundaryStatus) String ¶ added in v2.32.0
func (x *BoundaryStatus) String() string
type Tag ¶
type Tag uint8
const ( // TagV1 identifies the first revision of the protocol. The payload is a // bare ReportBoundaryLogsRequest. This version has a maximum data length // of MaxMessageSizeV1. TagV1 Tag = 1 // TagV2 identifies the second revision of the protocol. The payload is // a BoundaryMessage envelope. This version has a maximum data length of // MaxMessageSizeV2. TagV2 Tag = 2 )
func ReadFrame ¶
ReadFrame reads a framed message, returning the decoded tag and data. If the message size exceeds MaxMessageSizeV1, ErrMessageTooLarge is returned. The provided buf is used if it has sufficient capacity; otherwise a new buffer is allocated. To reuse the buffer across calls, pass in the returned data slice:
buf := make([]byte, initialSize)
for {
_, buf, _ = ReadFrame(r, buf)
}