Skip to content

Latest commit

 

History

History
698 lines (481 loc) · 23.6 KB

README.md

File metadata and controls

698 lines (481 loc) · 23.6 KB

binary

import "github.com/cloudwego/dynamicgo/proto/binary"

Index

Variables

var (
    ErrConvert = meta.NewError(meta.ErrConvert, "convert type error", nil)
)

func AppendSpeculativeLength(b []byte) ([]byte, int)

When encoding length-prefixed fields, we speculatively set aside some number of bytes for the length, encode the data, and then encode the length (shifting the data if necessary to make room).

func FinishSpeculativeLength(b []byte, pos int) []byte

func FreeBinaryProtocol(bp *BinaryProtocol)

Serizalize data to byte array and reuse the memory

type BinaryProtocol struct {
    Buf  []byte
    Read int
}

func NewBinaryProtocolBuffer() *BinaryProtocol

func NewBinaryProtol(buf []byte) *BinaryProtocol

BinaryProtocol Method

func (*BinaryProtocol) AppendTag

func (p *BinaryProtocol) AppendTag(num proto.FieldNumber, typ proto.WireType) error

Append Tag

func (*BinaryProtocol) AppendTagByKind

func (p *BinaryProtocol) AppendTagByKind(number proto.FieldNumber, kind proto.ProtoKind) error

Append Tag With FieldDescriptor by kind, you must use kind to write tag, because the typedesc when list has no tag

func (*BinaryProtocol) ConsumeTag

func (p *BinaryProtocol) ConsumeTag() (proto.FieldNumber, proto.WireType, int, error)

ConsumeTag parses b as a varint-encoded tag, reporting its length.

func (*BinaryProtocol) ConsumeTagWithoutMove

func (p *BinaryProtocol) ConsumeTagWithoutMove() (proto.FieldNumber, proto.WireType, int, error)

ConsumeChildTag parses b as a varint-encoded tag, don't move p.Read

func (*BinaryProtocol) Left

func (p *BinaryProtocol) Left() int

Left returns the left bytes to read

func (*BinaryProtocol) RawBuf

func (p *BinaryProtocol) RawBuf() []byte

RawBuf returns the raw buffer of the protocol

func (*BinaryProtocol) ReadAnyWithDesc

func (p *BinaryProtocol) ReadAnyWithDesc(desc *proto.TypeDescriptor, hasMessageLen bool, copyString bool, disallowUnknown bool, useFieldName bool) (interface{}, error)

ReadAnyWithDesc read any type by desc and val, the first Tag is parsed outside when use ReadBaseTypeWithDesc

  • LIST/SET will be converted to []interface{}
  • MAP will be converted to map[string]interface{} or map[int]interface{} or map[interface{}]interface{}
  • MESSAGE will be converted to map[proto.FieldNumber]interface{} or map[string]interface{}

func (*BinaryProtocol) ReadBaseTypeWithDesc

func (p *BinaryProtocol) ReadBaseTypeWithDesc(desc *proto.TypeDescriptor, hasMessageLen bool, copyString bool, disallowUnknown bool, useFieldName bool) (interface{}, error)

ReadBaseType with desc, not thread safe

func (*BinaryProtocol) ReadBool

func (p *BinaryProtocol) ReadBool() (bool, error)

ReadBool

func (*BinaryProtocol) ReadByte

func (p *BinaryProtocol) ReadByte() (value byte, err error)

ReadByte

func (*BinaryProtocol) ReadBytes

func (p *BinaryProtocol) ReadBytes() ([]byte, error)

ReadBytes return bytesData and the sum length of L、V in TLV

func (*BinaryProtocol) ReadDouble

func (p *BinaryProtocol) ReadDouble() (float64, error)

ReadDouble

func (*BinaryProtocol) ReadEnum

func (p *BinaryProtocol) ReadEnum() (proto.EnumNumber, error)

ReadEnum

func (*BinaryProtocol) ReadFixed32

func (p *BinaryProtocol) ReadFixed32() (int32, error)

ReadFixed32

func (*BinaryProtocol) ReadFixed64

func (p *BinaryProtocol) ReadFixed64() (int64, error)

ReadFixed64

func (*BinaryProtocol) ReadFloat

func (p *BinaryProtocol) ReadFloat() (float32, error)

ReadFloat

func (*BinaryProtocol) ReadInt

func (p *BinaryProtocol) ReadInt(t proto.Type) (value int, err error)

ReadInt containing INT32, SINT32, SFIX32, INT64, SINT64, SFIX64, UINT32, UINT64

func (*BinaryProtocol) ReadInt32

func (p *BinaryProtocol) ReadInt32() (int32, error)

ReadI32

func (*BinaryProtocol) ReadInt64

func (p *BinaryProtocol) ReadInt64() (int64, error)

ReadI64

func (*BinaryProtocol) ReadLength

func (p *BinaryProtocol) ReadLength() (int, error)

ReadLength return dataLength, and move pointer in the begin of data

func (*BinaryProtocol) ReadList

func (p *BinaryProtocol) ReadList(desc *proto.TypeDescriptor, copyString bool, disallowUnknown bool, useFieldName bool) ([]interface{}, error)

ReadList

func (*BinaryProtocol) ReadMap

func (p *BinaryProtocol) ReadMap(desc *proto.TypeDescriptor, copyString bool, disallowUnknown bool, useFieldName bool) (map[interface{}]interface{}, error)

ReadMap

func (*BinaryProtocol) ReadPair

func (p *BinaryProtocol) ReadPair(keyDesc *proto.TypeDescriptor, valueDesc *proto.TypeDescriptor, copyString bool, disallowUnknown bool, useFieldName bool) (interface{}, interface{}, error)

func (*BinaryProtocol) ReadSfixed32

func (p *BinaryProtocol) ReadSfixed32() (int32, error)

ReadSFixed32

func (*BinaryProtocol) ReadSfixed64

func (p *BinaryProtocol) ReadSfixed64() (int64, error)

ReadSFixed64

func (*BinaryProtocol) ReadSint32

func (p *BinaryProtocol) ReadSint32() (int32, error)

ReadSint32

func (*BinaryProtocol) ReadSint64

func (p *BinaryProtocol) ReadSint64() (int64, error)

ReadSint64

func (*BinaryProtocol) ReadString

func (p *BinaryProtocol) ReadString(copy bool) (value string, err error)

ReadString

func (*BinaryProtocol) ReadUint32

func (p *BinaryProtocol) ReadUint32() (uint32, error)

ReadUint32

func (*BinaryProtocol) ReadUint64

func (p *BinaryProtocol) ReadUint64() (uint64, error)

ReadUint64

func (*BinaryProtocol) ReadVarint

func (p *BinaryProtocol) ReadVarint() (uint64, error)

ReadVarint

func (*BinaryProtocol) Recycle

func (p *BinaryProtocol) Recycle()

func (*BinaryProtocol) Reset

func (p *BinaryProtocol) Reset()

Reset resets the buffer and read position

func (*BinaryProtocol) Skip

func (p *BinaryProtocol) Skip(wireType proto.WireType, useNative bool) (err error)

skip (L)V once by wireType, useNative is not implemented

func (*BinaryProtocol) SkipAllElements

func (p *BinaryProtocol) SkipAllElements(fieldNumber proto.FieldNumber, ispacked bool) (size int, err error)

fast skip all elements in LIST/MAP

func (*BinaryProtocol) SkipBytesType

func (p *BinaryProtocol) SkipBytesType() (int, error)

func (*BinaryProtocol) SkipFixed32Type

func (p *BinaryProtocol) SkipFixed32Type() (int, error)

func (*BinaryProtocol) SkipFixed64Type

func (p *BinaryProtocol) SkipFixed64Type() (int, error)

func (*BinaryProtocol) WriteAnyWithDesc

func (p *BinaryProtocol) WriteAnyWithDesc(desc *proto.TypeDescriptor, val interface{}, NeedMessageLen bool, cast bool, disallowUnknown bool, useFieldName bool) error

WriteAnyWithDesc explain desc and val and write them into buffer

  • LIST will be converted from []interface{}
  • MAP will be converted from map[string]interface{} or map[int]interface{} or map[interface{}]interface{}
  • MESSAGE will be converted from map[FieldNumber]interface{} or map[string]interface{}

func (*BinaryProtocol) WriteBaseTypeWithDesc

func (p *BinaryProtocol) WriteBaseTypeWithDesc(desc *proto.TypeDescriptor, val interface{}, NeedMessageLen bool, cast bool, disallowUnknown bool, useFieldName bool) error

WriteBaseType Fields with FieldDescriptor format: (L)V

func (*BinaryProtocol) WriteBool

func (p *BinaryProtocol) WriteBool(value bool) error

WriteBool

func (*BinaryProtocol) WriteBytes

func (p *BinaryProtocol) WriteBytes(value []byte) error

WriteBytes

func (*BinaryProtocol) WriteDouble

func (p *BinaryProtocol) WriteDouble(value float64) error

WriteDouble

func (*BinaryProtocol) WriteEnum

func (p *BinaryProtocol) WriteEnum(value proto.EnumNumber) error

WriteEnum

func (*BinaryProtocol) WriteFixed32

func (p *BinaryProtocol) WriteFixed32(value int32) error

Writefixed32

func (*BinaryProtocol) WriteFixed64

func (p *BinaryProtocol) WriteFixed64(value uint64) error

Writefixed64

func (*BinaryProtocol) WriteFloat

func (p *BinaryProtocol) WriteFloat(value float32) error

WriteFloat

func (*BinaryProtocol) WriteInt32

func (p *BinaryProtocol) WriteInt32(value int32) error

WriteInt32

func (*BinaryProtocol) WriteInt64

func (p *BinaryProtocol) WriteInt64(value int64) error

WriteInt64

func (*BinaryProtocol) WriteList

func (p *BinaryProtocol) WriteList(desc *proto.TypeDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error
  • WriteList
  • packed format:[tag][length][value value value value....]
  • unpacked format:[tag][(length)][value][tag][(length)][value][tag][(length)][value]....
  • accpet val type: []interface{}

func (*BinaryProtocol) WriteMap

func (p *BinaryProtocol) WriteMap(desc *proto.TypeDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error
  • WriteMap
  • Map bytes format: [Pairtag][Pairlength][keyTag(L)V][valueTag(L)V] [Pairtag][Pairlength][T(L)V][T(L)V]...
  • Pairtag = MapFieldnumber << 3 | wiretype, wiertype = proto.BytesType
  • accpet val type: map[string]interface{} or map[int]interface{} or map[interface{}]interface{}

func (*BinaryProtocol) WriteMessageFields

func (p *BinaryProtocol) WriteMessageFields(desc *proto.MessageDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error
  • Write Message
  • accpet val type: map[string]interface{} or map[proto.FieldNumber]interface{}
  • message fields format: [fieldTag(L)V][fieldTag(L)V]...

func (*BinaryProtocol) WriteSfixed32

func (p *BinaryProtocol) WriteSfixed32(value int32) error

WriteSfixed32

func (*BinaryProtocol) WriteSfixed64

func (p *BinaryProtocol) WriteSfixed64(value int64) error

WriteSfixed64

func (*BinaryProtocol) WriteSint32

func (p *BinaryProtocol) WriteSint32(value int32) error

WriteSint32

func (*BinaryProtocol) WriteSint64

func (p *BinaryProtocol) WriteSint64(value int64) error

WriteSint64

func (*BinaryProtocol) WriteString

func (p *BinaryProtocol) WriteString(value string) error

WriteString

func (*BinaryProtocol) WriteUint32

func (p *BinaryProtocol) WriteUint32(value uint32) error

WriteUint32

func (*BinaryProtocol) WriteUint64

func (p *BinaryProtocol) WriteUint64(value uint64) error

WriteUint64

Generated by gomarkdoc