Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeVarint(b []byte) (uint64, int)
- func EncodeVarint(v uint64) []byte
- func SizeVarint(v uint64) int
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (*Buffer) DebugPrint(s string, b []byte)
- func (b *Buffer) DecodeFixed32() (uint64, error)
- func (b *Buffer) DecodeFixed64() (uint64, error)
- func (b *Buffer) DecodeGroup(m protoadapt.MessageV1) error
- func (b *Buffer) DecodeMessage(m protoadapt.MessageV1) error
- func (b *Buffer) DecodeRawBytes(alloc bool) ([]byte, error)
- func (b *Buffer) DecodeStringBytes() (string, error)
- func (b *Buffer) DecodeVarint() (uint64, error)
- func (b *Buffer) DecodeZigzag32() (uint64, error)
- func (b *Buffer) DecodeZigzag64() (uint64, error)
- func (b *Buffer) EncodeFixed32(v uint64) error
- func (b *Buffer) EncodeFixed64(v uint64) error
- func (b *Buffer) EncodeMessage(m protoadapt.MessageV1) error
- func (b *Buffer) EncodeRawBytes(v []byte) error
- func (b *Buffer) EncodeStringBytes(v string) error
- func (b *Buffer) EncodeVarint(v uint64) error
- func (b *Buffer) EncodeZigzag32(v uint64) error
- func (b *Buffer) EncodeZigzag64(v uint64) error
- func (b *Buffer) Marshal(m protoadapt.MessageV1) error
- func (b *Buffer) Reset()
- func (b *Buffer) SetBuf(buf []byte)
- func (b *Buffer) SetDeterministic(deterministic bool)
- func (b *Buffer) Unmarshal(m protoadapt.MessageV1) error
- func (b *Buffer) Unread() []byte
- type RequiredNotSetError
Constants ¶
const ( WireVarint = 0 WireFixed32 = 5 WireFixed64 = 1 WireBytes = 2 WireStartGroup = 3 WireEndGroup = 4 )
Variables ¶
var (
ErrNil = errors.New("proto: Marshal called with nil")
)
Functions ¶
func DecodeVarint ¶
DecodeVarint parses a varint encoded integer from b, returning the integer value and the length of the varint. It returns (0, 0) if there is a parse error.
func EncodeVarint ¶
EncodeVarint returns the varint encoded bytes of v.
func SizeVarint ¶
SizeVarint returns the length of the varint encoded bytes of v. This is equal to len(EncodeVarint(v)).
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a buffer for encoding and decoding the protobuf wire format. It may be reused between invocations to reduce memory usage.
func NewBuffer ¶
NewBuffer allocates a new Buffer initialized with buf, where the contents of buf are considered the unread portion of the buffer.
func (*Buffer) DebugPrint ¶
DebugPrint dumps the encoded bytes of b with a header and footer including s to stdout. This is only intended for debugging.
func (*Buffer) DecodeFixed32 ¶
DecodeFixed32 consumes a 32-bit little-endian integer from the buffer.
func (*Buffer) DecodeFixed64 ¶
DecodeFixed64 consumes a 64-bit little-endian integer from the buffer.
func (*Buffer) DecodeGroup ¶
func (b *Buffer) DecodeGroup(m protoadapt.MessageV1) error
DecodeGroup consumes a message group from the buffer. It assumes that the start group marker has already been consumed and consumes all bytes until (and including the end group marker). It does not reset m before unmarshaling.
func (*Buffer) DecodeMessage ¶
func (b *Buffer) DecodeMessage(m protoadapt.MessageV1) error
DecodeMessage consumes a length-prefixed message from the buffer. It does not reset m before unmarshaling.
func (*Buffer) DecodeRawBytes ¶
DecodeRawBytes consumes a length-prefixed raw bytes from the buffer. If alloc is specified, it returns a copy the raw bytes rather than a sub-slice of the buffer.
func (*Buffer) DecodeStringBytes ¶
DecodeStringBytes consumes a length-prefixed raw bytes from the buffer. It does not validate whether the raw bytes contain valid UTF-8.
func (*Buffer) DecodeVarint ¶
DecodeVarint consumes an encoded unsigned varint from the buffer.
func (*Buffer) DecodeZigzag32 ¶
DecodeZigzag32 consumes an encoded 32-bit zig-zag varint from the buffer.
func (*Buffer) DecodeZigzag64 ¶
DecodeZigzag64 consumes an encoded 64-bit zig-zag varint from the buffer.
func (*Buffer) EncodeFixed32 ¶
EncodeFixed32 appends a 32-bit little-endian integer to the buffer.
func (*Buffer) EncodeFixed64 ¶
EncodeFixed64 appends a 64-bit little-endian integer to the buffer.
func (*Buffer) EncodeMessage ¶
func (b *Buffer) EncodeMessage(m protoadapt.MessageV1) error
EncodeMessage appends a length-prefixed encoded message to the buffer.
func (*Buffer) EncodeRawBytes ¶
EncodeRawBytes appends a length-prefixed raw bytes to the buffer.
func (*Buffer) EncodeStringBytes ¶
EncodeStringBytes appends a length-prefixed raw bytes to the buffer. It does not validate whether v contains valid UTF-8.
func (*Buffer) EncodeVarint ¶
EncodeVarint appends an unsigned varint encoding to the buffer.
func (*Buffer) EncodeZigzag32 ¶
EncodeZigzag32 appends a 32-bit zig-zag varint encoding to the buffer.
func (*Buffer) EncodeZigzag64 ¶
EncodeZigzag64 appends a 64-bit zig-zag varint encoding to the buffer.
func (*Buffer) Marshal ¶
func (b *Buffer) Marshal(m protoadapt.MessageV1) error
Marshal appends the wire-format encoding of m to the buffer.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset clears the internal buffer of all written and unread data.
func (*Buffer) SetBuf ¶
SetBuf sets buf as the internal buffer, where the contents of buf are considered the unread portion of the buffer.
func (*Buffer) SetDeterministic ¶
SetDeterministic specifies whether to use deterministic serialization.
Deterministic serialization guarantees that for a given binary, equal messages will always be serialized to the same bytes. This implies:
- Repeated serialization of a message will return the same bytes.
- Different processes of the same binary (which may be executing on different machines) will serialize equal messages to the same bytes.
Note that the deterministic serialization is NOT canonical across languages. It is not guaranteed to remain stable over time. It is unstable across different builds with schema changes due to unknown fields. Users who need canonical serialization (e.g., persistent storage in a canonical form, fingerprinting, etc.) should define their own canonicalization specification and implement their own serializer rather than relying on this API.
If deterministic serialization is requested, map entries will be sorted by keys in lexographical order. This is an implementation detail and subject to change.
type RequiredNotSetError ¶
type RequiredNotSetError struct {
// contains filtered or unexported fields
}
RequiredNotSetError is an error type returned when marshaling or unmarshaling a message with missing required fields.
func (*RequiredNotSetError) Error ¶
func (e *RequiredNotSetError) Error() string
func (*RequiredNotSetError) RequiredNotSet ¶
func (e *RequiredNotSetError) RequiredNotSet() bool