Documentation
¶
Overview ¶
Package codec contains all the logic required for interacting with the protobuf raw encoding. It also contains all the encoding and field type specific constants required for using the molecule library.
Index ¶
- Variables
- func DecodeZigZag32(v uint64) int32
- func DecodeZigZag64(v uint64) int64
- type Buffer
- func (cb *Buffer) Bytes() []byte
- func (cb *Buffer) DecodeFixed32() (x uint64, err error)
- func (cb *Buffer) DecodeFixed64() (x uint64, err error)
- func (cb *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error)
- func (cb *Buffer) DecodeVarint() (uint64, error)
- func (cb *Buffer) EOF() bool
- func (cb *Buffer) Len() int
- func (cb *Buffer) Read(dest []byte) (int, error)
- func (cb *Buffer) ReadGroup(alloc bool) ([]byte, error)
- func (cb *Buffer) Reset(buf []byte)
- func (cb *Buffer) Skip(count int) error
- func (cb *Buffer) SkipGroup() error
- type FieldType
- type WireType
Constants ¶
This section is empty.
Variables ¶
var ErrBadWireType = errors.New("proto: bad wiretype")
ErrBadWireType is returned when decoding a wire-type from a buffer that is not valid.
var ErrOverflow = errors.New("proto: integer overflow")
ErrOverflow is returned when an integer is too large to be represented.
Functions ¶
func DecodeZigZag32 ¶
DecodeZigZag32 decodes a signed 32-bit integer from the given zig-zag encoded value.
func DecodeZigZag64 ¶
DecodeZigZag64 decodes a signed 64-bit integer from the given zig-zag encoded value.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a reader and a writer that wraps a slice of bytes and also provides API for decoding and encoding the protobuf binary format.
Its operation is similar to that of a bytes.Buffer: writing pushes data to the end of the buffer while reading pops data from the head of the buffer. So the same buffer can be used to both read and write.
func NewBuffer ¶
NewBuffer creates a new buffer with the given slice of bytes as the buffer's initial contents.
func (*Buffer) Bytes ¶
Bytes returns the slice of bytes remaining in the buffer. Note that this does not perform a copy: if the contents of the returned slice are modified, the modifications will be visible to subsequent reads via the buffer.
func (*Buffer) DecodeFixed32 ¶
DecodeFixed32 reads a 32-bit integer from the Buffer. This is the format for the fixed32, sfixed32, and float protocol buffer types.
func (*Buffer) DecodeFixed64 ¶
DecodeFixed64 reads a 64-bit integer from the Buffer. This is the format for the fixed64, sfixed64, and double protocol buffer types.
func (*Buffer) DecodeRawBytes ¶
DecodeRawBytes reads a count-delimited byte buffer from the Buffer. This is the format used for the bytes protocol buffer type and for embedded messages.
func (*Buffer) DecodeVarint ¶
DecodeVarint reads a varint-encoded integer from the Buffer. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types.
This implementation is inlined from https://github.com/dennwc/varint to avoid the call-site overhead
func (*Buffer) Read ¶
Read implements the io.Reader interface. If there are no bytes remaining in the buffer, it will return 0, io.EOF. Otherwise, it reads max(len(dest), cb.Len()) bytes from input and copies them into dest. It returns the number of bytes copied and a nil error in this case.
func (*Buffer) ReadGroup ¶
ReadGroup reads the input until a "group end" tag is found and returns the data up to that point. Subsequent reads from the buffer will read data after the group end tag. If alloc is true, the data is copied to a new slice before being returned. Otherwise, the returned slice is a view into the buffer's underlying byte slice.
This function correctly handles nested groups: if a "group start" tag is found, then that group's end tag will be included in the returned data.
func (*Buffer) Reset ¶
Reset resets this buffer back to empty. Any subsequent writes/encodes to the buffer will allocate a new backing slice of bytes.
type FieldType ¶
type FieldType int32
FieldType represents a protobuf field type.
const ( FieldType_DOUBLE FieldType = 1 FieldType_FLOAT FieldType = 2 FieldType_INT64 FieldType = 3 FieldType_UINT64 FieldType = 4 FieldType_INT32 FieldType = 5 FieldType_FIXED64 FieldType = 6 FieldType_FIXED32 FieldType = 7 FieldType_BOOL FieldType = 8 FieldType_STRING FieldType = 9 FieldType_GROUP FieldType = 10 FieldType_MESSAGE FieldType = 11 FieldType_BYTES FieldType = 12 FieldType_UINT32 FieldType = 13 FieldType_ENUM FieldType = 14 FieldType_SFIXED32 FieldType = 15 FieldType_SFIXED64 FieldType = 16 FieldType_SINT32 FieldType = 17 FieldType_SINT64 FieldType = 18 )
type WireType ¶
type WireType int8
WireType represents a protobuf encoding wire type.