Documentation ¶
Index ¶
- Constants
- Variables
- func Encode(m Message, reservedHeadLen int) ([]byte, error)
- func EncodeAppend(buf []byte, m Message) ([]byte, error)
- func EncodeSize(buf []byte, size int) int
- func EncodeType(buf []byte, typ Type) int
- func FreeBuffer(b *Buffer)
- func Marshal(m Message) ([]byte, error)
- func Nameof(m Message) string
- func PeekSize(peeker Peeker) (n int, size int, err error)
- func ReadSize(r io.ByteReader) (size int, err error)
- func Register(module string, typ Type, creator func() Message)
- func Sizeof(m Message) int
- func Unmarshal(b []byte, m Message) error
- type Body
- type Buffer
- type Message
- type Peeker
- type Type
Constants ¶
View Source
const ( // max size of content: 1G MaxSize = 1 << 30 // max message type MaxType = 1 << 31 )
Variables ¶
Functions ¶
func Encode ¶
Encode returns the wire-format encoding of m with size and type.
|<-- body -->| |body.len|type|content|
func EncodeSize ¶
EncodeSize encodes type as varint to buf and returns number of bytes written.
func EncodeType ¶
EncodeType encodes type as varint to buf and returns number of bytes written.
func FreeBuffer ¶
func FreeBuffer(b *Buffer)
FreeBuffer puts buffer to pool if cap of buffer less than 64k
func ReadSize ¶
func ReadSize(r io.ByteReader) (size int, err error)
ReadSize reads message size from reader
Types ¶
type Body ¶
type Body interface { io.ByteReader io.Reader // Len returns remain length of body Len() int // Peek returns the next n bytes without advancing the reader. The bytes stop // being valid at the next read call. If Peek returns fewer than n bytes, it // also returns an error explaining why the read is short. Peek(n int) ([]byte, error) // Discard skips the next n bytes, returning the number of bytes discarded. // If Discard skips fewer than n bytes, it also returns an error. Discard(n int) (discarded int, err error) }
Body represents message body
type Message ¶
Message represents a message interface
func Decode ¶
Decode decodes one message with size and type from buf and returns number of bytes read and unmarshaled message.
func DecodeBody ¶
Decode decodes one message that contains type from buf and returns unmarshaled message.
Click to show internal directories.
Click to hide internal directories.