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 ErrUnrecognizedType(typ Type) error
- func FreeBuffer(b *Buffer)
- func IsTextproto(contentType ContentType) bool
- func Marshal(m Message) ([]byte, error)
- func Moduleof(typ Type) string
- func PeekSize(peeker Peeker) (n int, size int, err error)
- func ReadSize(r io.ByteReader) (size int, err error)
- func Register(mod string, typ Type, creator func() Message)
- func Unmarshal(buf []byte, m Message) error
- type Arena
- type ArenaFunc
- type Body
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Encode(m Message, contentType ContentType) error
- func (b *Buffer) Len() int
- func (b *Buffer) Marshal(m Message) error
- func (b *Buffer) Reserve(n int)
- func (b *Buffer) Reset()
- func (b *Buffer) Unmarshal(m Message) error
- func (b *Buffer) Write(p []byte) (n int, err error)
- type ContentType
- type Dispatcher
- type Listener
- type Message
- type MessageInfo
- type Peeker
- type Pool
- type Type
- type UnrecognizedTypeError
Constants ¶
const ( // max size of content: 1G MaxSize = 1 << 30 // max message type MaxType = 1 << 31 )
Variables ¶
var ( ErrVarintOverflow = errors.New("proto: varint overflow") ErrSizeOverflow = errors.New("proto: size overflow") ErrTypeOverflow = errors.New("proto: type overflow") ErrOutOfRange = errors.New("proto: out of range") ErrUnsupportedContentType = errors.New("proto: unsupported content type") )
Functions ¶
func Encode ¶
Encode returns the wire-format encoding of m with type and size.
|type|body.size|body|
func EncodeAppend ¶
EncodeAppend encodes m to buf
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 ErrUnrecognizedType ¶
func FreeBuffer ¶
func FreeBuffer(b *Buffer)
FreeBuffer puts buffer to pool if cap of buffer less than 64k
func IsTextproto ¶ added in v0.0.18
func IsTextproto(contentType ContentType) bool
IsTextproto reports whether the contentType is a textproto type
func ReadSize ¶
func ReadSize(r io.ByteReader) (size int, err error)
ReadSize reads message size from reader
Types ¶
type ArenaFunc ¶ added in v0.0.18
ArenaFunc wraps function as an Arena
type Body ¶
type Body interface { io.Reader io.ByteReader // 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 ContentType ¶ added in v0.0.18
type ContentType int
ContentType represents encoding type of content
const ( ContentTypeProtobuf ContentType = iota ContentTypeText )
type Dispatcher ¶ added in v0.3.1
type Dispatcher = event.Dispatcher[Type]
Dispatcher aliases event.Dispatcher for Type
type Message ¶
type Message interface { // Type of message Typeof() Type // Size of message Sizeof() int // Name of message Nameof() string // MarshalAppend marshals message to buf MarshalAppend(buf []byte, useCachedSize bool) ([]byte, error) // Unmarshal unmarshals message from buf Unmarshal(buf []byte) error }
Message represents a message interface
type MessageInfo ¶ added in v0.0.18
func Messages ¶ added in v0.0.18
func Messages() []MessageInfo
Messages returns all registered message informations
type Pool ¶ added in v0.0.18
type Pool struct {
// contains filtered or unexported fields
}
Pool implements Arena interface to reuse message objects
type Type ¶
type Type = uint32
Type represents message type
type UnrecognizedTypeError ¶ added in v0.0.18
type UnrecognizedTypeError struct {
Type Type
}
func (*UnrecognizedTypeError) Error ¶ added in v0.0.18
func (err *UnrecognizedTypeError) Error() string