protokit

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ObjectMarker = illegalUtf8FirstByte | byte(WireVarint) // 16:varint
	//  _Marker		 = illegalUtf8FirstByte | byte(WireFixed64)	// 16:fixed64
	//  _Marker		 = illegalUtf8FirstByte | byte(WireBytes)	// 16:bytes
	//	DO_NOT_USE	 = illegalUtf8FirstByte | byte(WireStartGroup)	// 16:groupStart
	BinaryMarker = illegalUtf8FirstByte | byte(WireEndGroup) // 16:groupEnd

)
View Source
const (
	WireTypeBits  = 3
	MaxVarintSize = binary.MaxVarintLen64
	MinVarintSize = 1
	MaxFieldID    = math.MaxUint32 >> WireTypeBits
)
View Source
const ExplicitEmptyBinaryProtoSize = 1
View Source
const (
	GeneralBinaryMarker = BinaryMarker | iota<<WireTypeBits
)

As a valid pbuf payload cant start with groupEnd tag, so we can use it as an indicator of a non-parsable payload. Number of BinaryMarkers is limited by valid UTF-8 codes, starting at 0xC0

View Source
const MaxPolymorphFieldSize = 2 + MaxVarintSize
View Source
const MaxSafeForPolymorphFieldID = (legalUtf8 >> WireTypeBits) - 1
View Source
const MinPolymorphFieldSize = 2 + MinVarintSize
View Source
const PolymorphFieldID = illegalUtf8FirstByte >> WireTypeBits // = 16

Variables

View Source
var ErrUnexpectedHeader = errors.New("unexpected header")

Functions

func BinaryMarshalTo

func BinaryMarshalTo(b []byte, allowEmpty bool, marshalTo func([]byte) (int, error)) (int, error)

func BinaryMarshalToSizedBuffer

func BinaryMarshalToSizedBuffer(b []byte, allowEmpty bool, marshalToSizedBuffer func([]byte) (int, error)) (int, error)

func BinaryProtoSize

func BinaryProtoSize(n int) int

func BinaryUnmarshal

func BinaryUnmarshal(b []byte, unmarshal func([]byte) error) error

func DecodeFixed32

func DecodeFixed32(r io.ByteReader) (v uint64, err error)

func DecodeFixed32FromBytes

func DecodeFixed32FromBytes(b []byte) (uint64, int)

func DecodeFixed32FromBytesWithError

func DecodeFixed32FromBytesWithError(b []byte) (v uint64, n int, err error)

func DecodeFixed64

func DecodeFixed64(r io.ByteReader) (uint64, error)

func DecodeFixed64FromBytes

func DecodeFixed64FromBytes(b []byte) (uint64, int)

func DecodeFixed64FromBytesWithError

func DecodeFixed64FromBytesWithError(b []byte) (v uint64, n int, err error)

func DecodePolymorphFromBytes

func DecodePolymorphFromBytes(b []byte, onlyVarint bool) (id uint64, size int, err error)

func DecodeVarint

func DecodeVarint(r io.ByteReader) (uint64, error)

func DecodeVarintFromBytes

func DecodeVarintFromBytes(bb []byte) (u uint64, n int)

func DecodeVarintFromBytesWithError

func DecodeVarintFromBytesWithError(bb []byte) (u uint64, n int, err error)

func EncodeFixed32

func EncodeFixed32(w io.ByteWriter, u uint32) error

func EncodeFixed32ToBytes

func EncodeFixed32ToBytes(b []byte, u uint32) (int, error)

func EncodeFixed64

func EncodeFixed64(w io.ByteWriter, u uint64) error

func EncodeFixed64ToBytes

func EncodeFixed64ToBytes(b []byte, u uint64) (int, error)

func EncodeVarint

func EncodeVarint(w io.ByteWriter, u uint64) error

func EncodeVarintToBytes

func EncodeVarintToBytes(b []byte, u uint64) (n int)

func EncodeVarintToBytesWithError

func EncodeVarintToBytesWithError(b []byte, u uint64) (n int, err error)

func GetPolymorphFieldSize

func GetPolymorphFieldSize(id uint64) int

func IsValidFirstByteOfTag

func IsValidFirstByteOfTag(firstByte byte) bool

func SizeTag

func SizeTag(fieldID int) int

func SizeVarint32

func SizeVarint32(x uint32) int

func SizeVarint64

func SizeVarint64(x uint64) int

SizeVarint returns the varint encoding size of an integer.

Types

type ContentType

type ContentType uint8

Content type detection of a notation-friendly payload.

const (
	/* Content is unclear */
	ContentUndefined ContentType = iota
	/* Content is text */
	ContentText
	/* Content is binary */
	ContentBinary
	/* Content is protobuf message */
	ContentMessage
	/* Content is protobuf that follows the notation and has polymorph marker */
	ContentPolymorph
)

func PeekContentTypeAndPolymorphID

func PeekContentTypeAndPolymorphID(r io.ByteScanner) (ContentType, uint64, error)

func PeekContentTypeAndPolymorphIDFromBytes

func PeekContentTypeAndPolymorphIDFromBytes(b []byte) (ContentType, uint64, error)

type ContentTypeOptions

type ContentTypeOptions uint8
const (
	// ContentOptionText indicates that the content can be text
	ContentOptionText ContentTypeOptions = 1 << iota

	// ContentOptionMessage indicates that the content can be a protobuf message
	ContentOptionMessage

	// ContentOptionNotation indicates the content has either Polymorph or Binary markers
	ContentOptionNotation
)

func PeekPossibleContentTypes

func PeekPossibleContentTypes(r io.ByteScanner) (ContentTypeOptions, error)

func PossibleContentTypes

func PossibleContentTypes(firstByte byte) (ct ContentTypeOptions)

Provides content type detection of a notation-friendly payload.

type UintByteDecoderFunc

type UintByteDecoderFunc func([]byte) (uint64, int, error)

type UintByteEncoderFunc

type UintByteEncoderFunc func([]byte, uint64) (int, error)

type UintDecoderFunc

type UintDecoderFunc func(io.ByteReader) (uint64, error)

type UintEncoderFunc

type UintEncoderFunc func(io.ByteWriter, uint64) error

type WireTag

type WireTag uint32

func MustReadAnyTag

func MustReadAnyTag(r io.ByteReader) (wt WireTag, err error)

func MustReadAnyTagValue

func MustReadAnyTagValue(r io.ByteReader) (rt WireTag, u uint64, err error)

func SafeWireTag

func SafeWireTag(v uint64) (WireTag, error)

func TryReadAnyTag

func TryReadAnyTag(r io.ByteScanner) (wt WireTag, err error)

func TryReadAnyTagValue

func TryReadAnyTagValue(r io.ByteScanner) (rt WireTag, u uint64, err error)

func (WireTag) Check

func (v WireTag) Check(expectedType WireType, expectedID int) error

func (WireTag) CheckActualTagValue

func (v WireTag) CheckActualTagValue(actual uint64) error

func (WireTag) CheckTag

func (v WireTag) CheckTag(expected WireTag) error

func (WireTag) CheckType

func (v WireTag) CheckType(t WireType) error

func (WireTag) Ensure

func (v WireTag) Ensure(expectedType WireType, expectedID int)

func (WireTag) EnsureFixedFieldSize

func (v WireTag) EnsureFixedFieldSize(sz int) WireTag

func (WireTag) EnsureTag

func (v WireTag) EnsureTag(expected WireTag)

func (WireTag) EnsureType

func (v WireTag) EnsureType(expectedType WireType)

func (WireTag) FieldID

func (v WireTag) FieldID() int

func (WireTag) FieldSize

func (v WireTag) FieldSize(u uint64) uint64

func (WireTag) FixedFieldSize

func (v WireTag) FixedFieldSize() int

func (WireTag) IsValid

func (v WireTag) IsValid() bool

func (WireTag) IsValidFirstByte

func (v WireTag) IsValidFirstByte(firstByte byte) bool

func (WireTag) IsZero

func (v WireTag) IsZero() bool

func (WireTag) MaxFieldSize

func (v WireTag) MaxFieldSize() (isFixed bool, max int)

func (WireTag) MustRead

func (v WireTag) MustRead(r io.ByteReader) uint64

func (WireTag) MustWrite

func (v WireTag) MustWrite(w io.ByteWriter, u uint64)

func (WireTag) ReadTag

func (v WireTag) ReadTag(r io.ByteReader) error

func (WireTag) ReadTagValue

func (v WireTag) ReadTagValue(r io.ByteReader) (uint64, error)

func (WireTag) ReadValue

func (v WireTag) ReadValue(r io.ByteReader) (uint64, error)

func (WireTag) ReadValueFromBytes

func (v WireTag) ReadValueFromBytes(b []byte) (uint64, int, error)

func (WireTag) String

func (v WireTag) String() string

func (WireTag) TagSize

func (v WireTag) TagSize() int

func (WireTag) TryReadTag

func (v WireTag) TryReadTag(r io.ByteScanner) (WireTag, error)

func (WireTag) Type

func (v WireTag) Type() WireType

func (WireTag) WriteTagValue

func (v WireTag) WriteTagValue(w io.ByteWriter, u uint64) error

func (WireTag) WriteTagValueToBytes

func (v WireTag) WriteTagValueToBytes(b []byte, u uint64) (int, error)

func (WireTag) WriteValue

func (v WireTag) WriteValue(w io.ByteWriter, u uint64) error

func (WireTag) WriteValueToBytes

func (v WireTag) WriteValueToBytes(b []byte, u uint64) (int, error)

type WireType

type WireType uint8
const (
	WireVarint WireType = iota
	WireFixed64
	WireBytes
	WireStartGroup
	WireEndGroup
	WireFixed32

	MaxWireType = iota - 1
)

func (WireType) DataSize

func (v WireType) DataSize() (minSize, maxSize int)

func (WireType) FieldSize

func (v WireType) FieldSize(tagSize int, u uint64) uint64

func (WireType) IsValid

func (v WireType) IsValid() bool

func (WireType) IsValidFirstByte

func (v WireType) IsValidFirstByte(firstByte byte) bool

func (WireType) ReadTag

func (v WireType) ReadTag(r io.ByteReader) (WireTag, error)

func (WireType) ReadTagValue

func (v WireType) ReadTagValue(r io.ByteReader) (WireTag, uint64, error)

func (WireType) ReadValue

func (v WireType) ReadValue(r io.ByteReader) (uint64, error)

func (WireType) ReadValueFromBytes

func (v WireType) ReadValueFromBytes(b []byte) (uint64, int, error)

func (WireType) String

func (v WireType) String() string

func (WireType) Tag

func (v WireType) Tag(fieldID int) WireTag

func (WireType) TryReadTag

func (v WireType) TryReadTag(r io.ByteScanner) (WireTag, error)

func (WireType) UintByteDecoder

func (v WireType) UintByteDecoder() (UintByteDecoderFunc, error)

func (WireType) UintByteEncoder

func (v WireType) UintByteEncoder() (UintByteEncoderFunc, error)

func (WireType) UintDecoder

func (v WireType) UintDecoder() (UintDecoderFunc, error)

func (WireType) UintEncoder

func (v WireType) UintEncoder() (UintEncoderFunc, error)

func (WireType) WriteValue

func (v WireType) WriteValue(w io.ByteWriter, u uint64) error

func (WireType) WriteValueToBytes

func (v WireType) WriteValueToBytes(b []byte, u uint64) (int, error)

Jump to

Keyboard shortcuts

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