protobuf

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSignatureLength = 1 + 2 + neofscrypto.MaxVerificationScriptLength +
		1 + 2 + neofscrypto.MaxInvocationScriptLength +
		1 + 5 // scheme tag + varint max int32
	MaxObjectWithoutPayloadLength = 1 + 1 + ObjectIDLength +
		1 + 2 + MaxSignatureLength +
		1 + 3 + object.MaxHeaderLen
)

Message length limits.

View Source
const (
	TagBytes1 = 10
	TagBytes2 = 18
	TagBytes3 = 26
	TagBytes4 = 34
	TagBytes5 = 42
	TagBytes6 = 50
)

One-byte tags for LEN fields.

View Source
const (
	TagVarint1 = 8
	TagVarint2 = 16
	TagVarint3 = 24
	TagVarint4 = 32
	TagVarint5 = 40
	TagVarint6 = 48
)

One-byte tags for VARINT fields.

View Source
const (
	ObjectIDLength = 1 + 1 + oid.Size
)

Fixed message lengths.

Variables

This section is empty.

Functions

func GetFirstBytesField

func GetFirstBytesField(b []byte) ([]byte, error)

GetFirstBytesField gets VARLEN field with number = 1 from b.

GetFirstBytesField returns slice of b, not copy.

func NewRepeatedFieldError added in v0.52.0

func NewRepeatedFieldError(n protowire.Number) error

NewRepeatedFieldError returns common error for field #n repeated more than once.

func NewUnorderedFieldsError added in v0.52.0

func NewUnorderedFieldsError(n1, n2 protowire.Number) error

NewUnorderedFieldsError returns common error for field order violation when field #n2 goes after #n1.

func NewUnsupportedFieldError added in v0.52.0

func NewUnsupportedFieldError(n protowire.Number, t protowire.Type) error

NewUnsupportedFieldError returns common error for unsupported field #n of type t.

func ParseAPIVersionField added in v0.52.0

func ParseAPIVersionField(buf []byte, fNum protowire.Number, fTyp protowire.Type) (version.Version, int, error)

ParseAPIVersionField parses version.Version from the next field with known number and type at given offset. Also returns field length.

func ParseAttribute added in v0.52.0

func ParseAttribute(buf []byte, fNum protowire.Number, fTyp protowire.Type) ([]byte, []byte, int, error)

ParseChecksum parses key-value attribute from the next field with known number and type at given offset. Also returns field length.

func ParseChecksum added in v0.52.0

func ParseChecksum(buf []byte, fNum protowire.Number, fTyp protowire.Type) (checksum.Checksum, int, error)

ParseChecksum parses checksum.Checksum from the next field with known number and type at given offset. Also returns field length.

func ParseEnum added in v0.52.0

func ParseEnum[T ~int32](buf []byte) (T, int, error)

ParseEnum parses enum value from buf. Returns parsed value and number of bytes read.

func ParseEnumField added in v0.52.0

func ParseEnumField[T ~int32](buf []byte, num protowire.Number, typ protowire.Type) (T, int, error)

ParseEnumField parses value of enum field with preread number and type from buf. Returns parsed value and number of bytes read.

If there is an error, its text contains num and typ.

func ParseLEN added in v0.52.0

func ParseLEN(buf []byte) (int, int, error)

ParseLEN parses varint-encoded length from buf and check its overflow. Returns parsed value and number of bytes read.

func ParseLENField added in v0.52.0

func ParseLENField(buf []byte, num protowire.Number, typ protowire.Type) (int, int, error)

ParseLENField parses length of LEN field with preread number and type from buf. Returns parsed value and number of bytes read.

If there is an error, its text contains num and typ.

func ParseTag added in v0.52.0

func ParseTag(buf []byte) (protowire.Number, protowire.Type, int, error)

ParseTag parses field tag from buf. Returns field number, type and number of bytes read.

func ParseUint32 added in v0.52.0

func ParseUint32(buf []byte) (uint32, int, error)

ParseUint32 parses varint-encoded uint32 from buf. Returns parsed value and number of bytes read.

func ParseUint32Field added in v0.52.0

func ParseUint32Field(buf []byte, num protowire.Number, typ protowire.Type) (uint32, int, error)

ParseUint32Field parses value of uint32 field from buf. Returns parsed value and number of bytes read.

If there is an error, its text contains num and typ.

func ParseUint64Field added in v0.52.0

func ParseUint64Field(buf []byte, num protowire.Number, typ protowire.Type) (uint64, int, error)

ParseUint64Field parses value of uint64 field with preread number and type from buf. Returns value and its length.

If there is an error, its text contains num and typ.

func ParseUserIDField added in v0.52.0

func ParseUserIDField(buf []byte, fNum protowire.Number, fTyp protowire.Type) ([]byte, int, error)

ParseUserIDField parses user ID from the next field with known number and type at given offset. Also returns field length.

func ParseVarint added in v0.52.0

func ParseVarint(buf []byte) (uint64, int, error)

ParseVarint parses varint-encoded uint64 from buf. Returns parsed value and number of bytes read.

func SeekFieldByNumber added in v0.52.0

func SeekFieldByNumber(buf []byte, seekNum protowire.Number) (int, int, protowire.Type, error)

SeekFieldByNumber seeks field in buf by number and returns its offset, tag length and type. If field is missing, negative offset returns.

Message should have ascending field order, otherwise error returns.

Note that SeekFieldByNumber does not check value of found field, but checks intermediate ones for correct message traverse.

func SkipField added in v0.52.0

func SkipField(buf []byte, num protowire.Number, typ protowire.Type) (int, error)

SkipField parses length of skipped field with preread number and type from buf and checks its overflow. Returns number of bytes read.

If there is an error, its text contains num and typ.

Types

type BufferedCodec added in v0.52.0

type BufferedCodec struct{}

BufferedCodec is encoding.CodecV2 extending default one provided by proto package with custom buffers' support.

func (BufferedCodec) Marshal added in v0.52.0

func (BufferedCodec) Marshal(msg any) (mem.BufferSlice, error)

Marshal implements encoding.CodecV2.

func (BufferedCodec) Name added in v0.52.0

func (BufferedCodec) Name() string

Name implements encoding.CodecV2.

func (BufferedCodec) Unmarshal added in v0.52.0

func (BufferedCodec) Unmarshal(data mem.BufferSlice, msg any) error

Unmarshal implements encoding.CodecV2.

type FieldBounds added in v0.52.0

type FieldBounds struct {
	From      int // first byte index
	ValueFrom int // first value byte index
	To        int // last byte index
}

FieldBounds represents boundaries of a field in a particular buffer.

func GetLENFieldBounds added in v0.52.0

func GetLENFieldBounds(buf []byte, num protowire.Number) (FieldBounds, error)

GetLENFieldBounds seeks LEN field in buf by number and parses its boundaries. If field is missing, no error is returned.

Message should have ascending field order, otherwise error returns.

If there is an error, its text contains num.

func ParseLENFieldBounds added in v0.52.0

func ParseLENFieldBounds(buf []byte, off int, tagLn int, num protowire.Number, typ protowire.Type) (FieldBounds, error)

ParseLENFieldBounds parses boundaries of LEN field with preread tag length, number and type at given offset from buf.

If there is an error, its text contains num and typ.

func (FieldBounds) IsMissing added in v0.52.0

func (x FieldBounds) IsMissing() bool

IsMissing returns field absence flag.

type MemBuffer added in v0.52.0

type MemBuffer struct {
	mem.SliceBuffer
	// contains filtered or unexported fields
}

MemBuffer is a buffer for some protobuf message. MemBuffer must be initialized using MemBufferPool.

func (*MemBuffer) Free added in v0.52.0

func (x *MemBuffer) Free()

Free decrements ref counter for x. If counter reaches zero, x is freed, i.e. it is returned back to MemBufferPool.

Free panics if x has already been freed.

Free implements mem.Buffer.

func (*MemBuffer) Len added in v0.52.0

func (x *MemBuffer) Len() int

Len returns final length of the underlying message. Len returns undefined value before MemBuffer.SetBounds.

Len implements mem.Buffer.

func (*MemBuffer) ReadOnlyData added in v0.52.0

func (x *MemBuffer) ReadOnlyData() []byte

ReadOnlyData returns final length of the underlying message. ReadOnlyData returns undefined value before MemBuffer.SetBounds.

ReadOnlyData implements mem.Buffer.

func (*MemBuffer) Ref added in v0.52.0

func (x *MemBuffer) Ref()

Ref increments ref counter for x.

Ref panics if x has already been freed.

Ref implements mem.Buffer.

func (*MemBuffer) SetBounds added in v0.52.0

func (x *MemBuffer) SetBounds(from, to int)

SetBounds seals underlying message with given bounds.

type MemBufferPool added in v0.52.0

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

MemBufferPool is a sync.Pool for MemBuffer instances.

func NewBufferPool added in v0.52.0

func NewBufferPool(ln int) *MemBufferPool

NewBufferPool constructs MemBufferPool allocating all buffers of a given length.

func (*MemBufferPool) Get added in v0.52.0

func (x *MemBufferPool) Get() *MemBuffer

Get selects MemBuffer from x and returns it.

Instant MemBuffer.Free call returns the buffer to x. Use MemBuffer.Ref / to prevent release.

Jump to

Keyboard shortcuts

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