Documentation ¶
Overview ¶
This library provides utilities for length-prefixed de/serialization for messages with user-specific serialization format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMsgTooBig = fmt.Errorf("serde: message exceeds max allowed size")
ErrMsgTooBig is signaled in case user tries to de/serialize message with size bigger than MaxMessageSize.
var MaxMessageSize uint64 = 1 << 20
TODO: 1mb is reasonable, but it still makes sense to make it configurable per use-case, rather than globally MaxMessageSize limits allowed size for messages that can de/serialized.
Functions ¶
func Read ¶
Read deserializes the given msg from the given Reader. It efficiently reuses allocated buffer with buffer pooling.
Types ¶
type ByteReader ¶
func NewByteReader ¶
func NewByteReader(r io.Reader) *ByteReader
func (*ByteReader) ReadByte ¶
func (b *ByteReader) ReadByte() (byte, error)
type Message ¶
type Message interface { // Size reports the size of a Message. Size() int // MarshalTo serializes a Message to the given slice. // It also reports amount of bytes written. MarshalTo([]byte) (int, error) // Unmarshal deserialized a Message from a given slice. Unmarshal([]byte) error }
Message defines an abstract Message to be de/serialized using arbitrary format. NOTE: Currently, Message is aligned and tested for protobuf(gogo/proto) support in the first place.
type PlainMessage ¶
type PlainMessage struct {
Data []byte
}
PlainMessage is the simplest implementation for Message which only copies bytes as a serialization.
func (*PlainMessage) Equals ¶
func (f *PlainMessage) Equals(to *PlainMessage) bool
func (*PlainMessage) Size ¶
func (f *PlainMessage) Size() int
func (*PlainMessage) Unmarshal ¶
func (f *PlainMessage) Unmarshal(data []byte) error