proto

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 11 Imported by: 61

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadWireType  = errors.New("bad wire type")
	ErrUnknownField = errors.New("unknown field")
	ErrBadBoolValue = errors.New("bad bool value")
)

Functions

func CompactTextString

func CompactTextString(obj interface{}) string

func DecodeVarint

func DecodeVarint(buf []byte) (x uint64, n int)

func EncodeVarint

func EncodeVarint(x uint64) []byte

EncodeVarint returns the varint encoding of x. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types. Not used by the package itself, but helpful to clients wishing to use the same encoding.

func Marshal

func Marshal(raw interface{}) ([]byte, error)

func MarshalBool

func MarshalBool(b *Buffer, fieldIndex uint64, value bool) error

func MarshalBoolSlice

func MarshalBoolSlice(b *Buffer, fieldIndex uint64, value []bool) error

func MarshalBytes

func MarshalBytes(b *Buffer, fieldIndex uint64, value []byte) error

func MarshalFloat32

func MarshalFloat32(b *Buffer, fieldIndex uint64, value float32) error

func MarshalFloat32Slice

func MarshalFloat32Slice(b *Buffer, fieldIndex uint64, value []float32) error

func MarshalFloat64

func MarshalFloat64(b *Buffer, fieldIndex uint64, value float64) error

func MarshalFloat64Slice

func MarshalFloat64Slice(b *Buffer, fieldIndex uint64, value []float64) error

func MarshalInt32

func MarshalInt32(b *Buffer, fieldIndex uint64, value int32) error

func MarshalInt32Slice

func MarshalInt32Slice(b *Buffer, fieldIndex uint64, value []int32) error

func MarshalInt64

func MarshalInt64(b *Buffer, fieldIndex uint64, value int64) error

func MarshalInt64Slice

func MarshalInt64Slice(b *Buffer, fieldIndex uint64, value []int64) error

func MarshalString

func MarshalString(b *Buffer, fieldIndex uint64, value string) error

func MarshalStringSlice

func MarshalStringSlice(b *Buffer, fieldIndex uint64, value []string) error

func MarshalStruct

func MarshalStruct(b *Buffer, fieldIndex uint64, msg Struct) error

func MarshalTextString

func MarshalTextString(obj interface{}) string

func MarshalUInt32

func MarshalUInt32(b *Buffer, fieldIndex uint64, value uint32) error

func MarshalUInt32Slice

func MarshalUInt32Slice(b *Buffer, fieldIndex uint64, value []uint32) error

func MarshalUInt64

func MarshalUInt64(b *Buffer, fieldIndex uint64, value uint64) error

func MarshalUInt64Slice

func MarshalUInt64Slice(b *Buffer, fieldIndex uint64, value []uint64) error

func Size

func Size(raw interface{}) int

func SizeBool

func SizeBool(fieldIndex uint64, value bool) int

func SizeBoolSlice

func SizeBoolSlice(fieldIndex uint64, value []bool) int

func SizeBytes

func SizeBytes(fieldIndex uint64, value []byte) int

func SizeFloat32

func SizeFloat32(fieldIndex uint64, value float32) int

func SizeFloat32Slice

func SizeFloat32Slice(fieldIndex uint64, value []float32) (ret int)

func SizeFloat64

func SizeFloat64(fieldIndex uint64, value float64) int

func SizeFloat64Slice

func SizeFloat64Slice(fieldIndex uint64, value []float64) (ret int)

func SizeInt32

func SizeInt32(fieldIndex uint64, value int32) int

func SizeInt32Slice

func SizeInt32Slice(fieldIndex uint64, value []int32) (ret int)

func SizeInt64

func SizeInt64(fieldIndex uint64, value int64) int

func SizeInt64Slice

func SizeInt64Slice(fieldIndex uint64, value []int64) (ret int)

func SizeString

func SizeString(fieldIndex uint64, value string) int

func SizeStringSlice

func SizeStringSlice(fieldIndex uint64, value []string) (ret int)

func SizeStruct

func SizeStruct(fieldIndex uint64, msg Struct) int

func SizeUInt32

func SizeUInt32(fieldIndex uint64, value uint32) int

func SizeUInt32Slice

func SizeUInt32Slice(fieldIndex uint64, value []uint32) (ret int)

func SizeUInt64

func SizeUInt64(fieldIndex uint64, value uint64) int

func SizeUInt64Slice

func SizeUInt64Slice(fieldIndex uint64, value []uint64) (ret int)

func SizeVarint

func SizeVarint(x uint64) int

SizeVarint returns the varint encoding size of an integer.

func Unmarshal

func Unmarshal(data []byte, raw interface{}) (err error)

func UnmarshalBool

func UnmarshalBool(b *Buffer, wt WireType, ret *bool) error

func UnmarshalBoolSlice

func UnmarshalBoolSlice(b *Buffer, wt WireType, ret *[]bool) error

func UnmarshalBytes

func UnmarshalBytes(b *Buffer, wt WireType, ret *[]byte) error

func UnmarshalFloat32

func UnmarshalFloat32(b *Buffer, wt WireType, ret *float32) error

func UnmarshalFloat32Slice

func UnmarshalFloat32Slice(b *Buffer, wt WireType, ret *[]float32) error

func UnmarshalFloat64

func UnmarshalFloat64(b *Buffer, wt WireType, ret *float64) error

func UnmarshalFloat64Slice

func UnmarshalFloat64Slice(b *Buffer, wt WireType, ret *[]float64) error

func UnmarshalInt32

func UnmarshalInt32(b *Buffer, wt WireType, ret *int32) error

func UnmarshalInt32Slice

func UnmarshalInt32Slice(b *Buffer, wt WireType, ret *[]int32) error

func UnmarshalInt64

func UnmarshalInt64(b *Buffer, wt WireType, ret *int64) error

func UnmarshalInt64Slice

func UnmarshalInt64Slice(b *Buffer, wt WireType, ret *[]int64) error

func UnmarshalString

func UnmarshalString(b *Buffer, wt WireType, ret *string) error

func UnmarshalStringSlice

func UnmarshalStringSlice(b *Buffer, wt WireType, ret *[]string) error

func UnmarshalStruct

func UnmarshalStruct(b *Buffer, wt WireType, msgPtr Struct) error

func UnmarshalUInt32

func UnmarshalUInt32(b *Buffer, wt WireType, ret *uint32) error

func UnmarshalUInt32Slice

func UnmarshalUInt32Slice(b *Buffer, wt WireType, ret *[]uint32) error

func UnmarshalUInt64

func UnmarshalUInt64(b *Buffer, wt WireType, ret *uint64) error

func UnmarshalUInt64Slice

func UnmarshalUInt64Slice(b *Buffer, wt WireType, ret *[]uint64) error

func Zigzag32

func Zigzag32(x uint64) uint64

func Zigzag64

func Zigzag64(x uint64) uint64

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

A Buffer is a buffer manager for marshaling and unmarshaling protocol buffers. It may be reused between invocations to reduce memory usage. It is not necessary to use a Buffer; the global functions Marshal and Unmarshal create a temporary Buffer and are fine for most applications.

func NewBuffer

func NewBuffer(e []byte) *Buffer

NewBuffer allocates a new Buffer and initializes its internal data to the contents of the argument slice.

func (*Buffer) Bytes

func (self *Buffer) Bytes() []byte

Bytes returns the contents of the Buffer.

func (*Buffer) BytesRemains

func (self *Buffer) BytesRemains() int

func (*Buffer) ConsumeBytes

func (self *Buffer) ConsumeBytes(size int) (ret []byte)

func (*Buffer) DecodeFixed32

func (self *Buffer) DecodeFixed32() (x uint64, err error)

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

func (self *Buffer) DecodeFixed64() (x uint64, err error)

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

func (self *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error)

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) DecodeStringBytes

func (self *Buffer) DecodeStringBytes() (s string, err error)

DecodeStringBytes reads an encoded string from the Buffer. This is the format used for the proto2 string type.

func (*Buffer) DecodeVarint

func (self *Buffer) DecodeVarint() (x uint64, err error)

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.

func (*Buffer) DecodeZigzag32

func (self *Buffer) DecodeZigzag32() (x uint64, err error)

DecodeZigzag32 reads a zigzag-encoded 32-bit integer from the Buffer. This is the format used for the sint32 protocol buffer type.

func (*Buffer) DecodeZigzag64

func (self *Buffer) DecodeZigzag64() (x uint64, err error)

DecodeZigzag64 reads a zigzag-encoded 64-bit integer from the Buffer. This is the format used for the sint64 protocol buffer type.

func (*Buffer) EncodeFixed32

func (self *Buffer) EncodeFixed32(x uint64) error

EncodeFixed32 writes a 32-bit integer to the Buffer. This is the format for the fixed32, sfixed32, and float protocol buffer types.

func (*Buffer) EncodeFixed64

func (self *Buffer) EncodeFixed64(x uint64) error

EncodeFixed64 writes a 64-bit integer to the Buffer. This is the format for the fixed64, sfixed64, and double protocol buffer types.

func (*Buffer) EncodeRawBytes

func (self *Buffer) EncodeRawBytes(b []byte) error

EncodeRawBytes writes a count-delimited byte buffer to the Buffer. This is the format used for the bytes protocol buffer type and for embedded messages.

func (*Buffer) EncodeStringBytes

func (self *Buffer) EncodeStringBytes(s string) error

EncodeStringBytes writes an encoded string to the Buffer. This is the format used for the proto2 string type.

func (*Buffer) EncodeVarint

func (self *Buffer) EncodeVarint(x uint64) error

EncodeVarint writes a varint-encoded integer to the Buffer. This is the format for the int32, int64, uint32, uint64, bool, and enum protocol buffer types.

func (*Buffer) EncodeZigzag32

func (self *Buffer) EncodeZigzag32(x uint64) error

EncodeZigzag32 writes a zigzag-encoded 32-bit integer to the Buffer. This is the format used for the sint32 protocol buffer type.

func (*Buffer) EncodeZigzag64

func (self *Buffer) EncodeZigzag64(x uint64) error

EncodeZigzag64 writes a zigzag-encoded 64-bit integer to the Buffer. This is the format used for the sint64 protocol buffer type.

func (*Buffer) Reset

func (self *Buffer) Reset()

Reset resets the Buffer, ready for marshaling a new protocol buffer.

func (*Buffer) SetBuf

func (self *Buffer) SetBuf(s []byte)

SetBuf replaces the internal buffer with the slice, ready for unmarshaling the contents of the slice.

type Struct

type Struct interface {
	Marshal(buffer *Buffer) error

	Unmarshal(buffer *Buffer, fieldIndex uint64, wt WireType) error

	Size() int
}

type TextMarshaler

type TextMarshaler struct {
	Compact          bool // use compact text format (one line).
	IgnoreDefault    bool // Do not output value when value equals its default value
	OriginalString   bool // Do not output string as byte
	CompactBytesSize int  // 将二进制在指定大小后缩减显示
}

TextMarshaler is a configurable text format marshaler.

func (*TextMarshaler) Marshal

func (self *TextMarshaler) Marshal(w io.Writer, obj interface{}) error

func (*TextMarshaler) Text

func (self *TextMarshaler) Text(obj interface{}) string

type WireType

type WireType = uint64
const (
	WireVarint   WireType = iota + 1 // int32, int64, uint32, uint64, bool, enum
	WireBytes                        // Length-delimited   string, bytes, slice, struct
	WireZigzag32                     // 32位负数
	WireZigzag64                     // 64位负数
	WireFixed32                      // 32位定长 float32
	WireFixed64                      // 64位定长 float64
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL