Documentation
¶
Index ¶
- Constants
- func GetFirstBytesField(b []byte) ([]byte, error)
- func GetUint64Field(buf []byte, num protowire.Number) (uint64, error)
- func NewRepeatedFieldError(n protowire.Number) error
- func NewUnorderedFieldsError(n1, n2 protowire.Number) error
- func NewUnsupportedFieldError(n protowire.Number, t protowire.Type) error
- func ParseAPIVersionField(buf []byte, fNum protowire.Number, fTyp protowire.Type) (version.Version, int, error)
- func ParseAttribute(buf []byte, fNum protowire.Number, fTyp protowire.Type) ([]byte, []byte, int, error)
- func ParseChecksum(buf []byte, fNum protowire.Number, fTyp protowire.Type) (checksum.Checksum, int, error)
- func ParseEnum[T ~int32](buf []byte) (T, int, error)
- func ParseEnumField[T ~int32](buf []byte, num protowire.Number, typ protowire.Type) (T, int, error)
- func ParseLEN(buf []byte) (int, int, error)
- func ParseLENField(buf []byte, num protowire.Number, typ protowire.Type) (int, int, error)
- func ParseTag(buf []byte) (protowire.Number, protowire.Type, int, error)
- func ParseUint32(buf []byte) (uint32, int, error)
- func ParseUint32Field(buf []byte, num protowire.Number, typ protowire.Type) (uint32, int, error)
- func ParseUint64Field(buf []byte, num protowire.Number, typ protowire.Type) (uint64, int, error)
- func ParseUserIDField(buf []byte, fNum protowire.Number, fTyp protowire.Type) ([]byte, int, error)
- func ParseVarint(buf []byte) (uint64, int, error)
- func SeekFieldByNumber(buf []byte, seekNum protowire.Number) (int, int, protowire.Type, error)
- func SkipField(buf []byte, num protowire.Number, typ protowire.Type) (int, error)
- type BufferedCodec
- type BuffersSlice
- func (x BuffersSlice) CopyTo(buf []byte) int
- func (x BuffersSlice) IsEmpty() bool
- func (x BuffersSlice) Len() int
- func (x *BuffersSlice) MoveNext(n int) (BuffersSlice, bool)
- func (x *BuffersSlice) ParseBoolField(num protowire.Number, typ protowire.Type) (bool, error)
- func (x *BuffersSlice) ParseEnumField(num protowire.Number, typ protowire.Type) (int32, error)
- func (x *BuffersSlice) ParseLENField(num protowire.Number, typ protowire.Type) (BuffersSlice, error)
- func (x *BuffersSlice) ParseStringField(num protowire.Number, typ protowire.Type) ([]byte, error)
- func (x *BuffersSlice) ParseTag() (protowire.Number, protowire.Type, error)
- func (x *BuffersSlice) ParseUint32Field(num protowire.Number, typ protowire.Type) (uint32, error)
- func (x *BuffersSlice) ParseUint64Field(num protowire.Number, typ protowire.Type) (uint64, error)
- func (x *BuffersSlice) ReadOnlyData() []byte
- func (x *BuffersSlice) SkipRepeatedEnum(num protowire.Number, typ protowire.Type) error
- func (x BuffersSlice) WriteTo(w io.Writer) (int64, error)
- type FieldBounds
- type MemBuffer
- type MemBufferPool
Constants ¶
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.
const ( FieldResponseBody = 1 FieldResponseMetaHeader = 2 FieldResponseVerificationHeader = 3 )
Common response field numbers.
const ( TagBytes1 = 10 TagBytes2 = 18 TagBytes3 = 26 TagBytes4 = 34 TagBytes5 = 42 TagBytes6 = 50 )
One-byte tags for LEN fields.
const ( TagVarint1 = 8 TagVarint2 = 16 TagVarint3 = 24 TagVarint4 = 32 TagVarint5 = 40 TagVarint6 = 48 )
One-byte tags for VARINT fields.
const (
ObjectIDLength = 1 + 1 + oid.Size
)
Fixed message lengths.
Variables ¶
This section is empty.
Functions ¶
func GetFirstBytesField ¶
GetFirstBytesField gets VARLEN field with number = 1 from b.
GetFirstBytesField returns slice of b, not copy.
func GetUint64Field ¶ added in v0.53.0
GetUint64Field seeks uint64 field in buf by number and parses it. 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 NewRepeatedFieldError ¶ added in v0.52.0
NewRepeatedFieldError returns common error for field #n repeated more than once.
func NewUnorderedFieldsError ¶ added in v0.52.0
NewUnorderedFieldsError returns common error for field order violation when field #n2 goes after #n1.
func NewUnsupportedFieldError ¶ added in v0.52.0
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
ParseEnum parses enum value from buf. Returns parsed value and number of bytes read.
func ParseEnumField ¶ added in v0.52.0
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
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
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
ParseTag parses field tag from buf. Returns field number, type and number of bytes read.
func ParseUint32 ¶ added in v0.52.0
ParseUint32 parses varint-encoded uint32 from buf. Returns parsed value and number of bytes read.
func ParseUint32Field ¶ added in v0.52.0
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
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
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
ParseVarint parses varint-encoded uint64 from buf. Returns parsed value and number of bytes read.
func SeekFieldByNumber ¶ added in v0.52.0
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.
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 BuffersSlice ¶ added in v0.53.0
type BuffersSlice struct {
// contains filtered or unexported fields
}
BuffersSlice is a wrapper over mem.BufferSlice providing protobuf reading interface.
Zero instance is correct: it corresponds to empty data.
func NewBuffersSlice ¶ added in v0.53.0
func NewBuffersSlice(buffers mem.BufferSlice) BuffersSlice
NewBuffersSlice initializes BuffersSlice with given buffers.
func (BuffersSlice) CopyTo ¶ added in v0.53.0
func (x BuffersSlice) CopyTo(buf []byte) int
CopyTo copies all bytes remaining in x into buf. Returns number of bytes copied.
CopyTo panics if buf cannot fit all the bytes.
func (BuffersSlice) IsEmpty ¶ added in v0.53.0
func (x BuffersSlice) IsEmpty() bool
IsEmpty checks whether x is fully read.
func (BuffersSlice) Len ¶ added in v0.53.0
func (x BuffersSlice) Len() int
Len returns number of bytes remaining in x.
func (*BuffersSlice) MoveNext ¶ added in v0.53.0
func (x *BuffersSlice) MoveNext(n int) (BuffersSlice, bool)
MoveNext moves x forward n bytes and returns cut BuffersSlice. If there is less than n bytes left, MoveNext returns false.
func (*BuffersSlice) ParseBoolField ¶ added in v0.53.0
ParseBoolField parses following bool field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ParseEnumField ¶ added in v0.53.0
ParseEnumField parses following enum field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ParseLENField ¶ added in v0.53.0
func (x *BuffersSlice) ParseLENField(num protowire.Number, typ protowire.Type) (BuffersSlice, error)
ParseLENField parses following bytes or nested message field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ParseStringField ¶ added in v0.53.0
ParseStringField parses following string field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ParseTag ¶ added in v0.53.0
ParseTag parses following field tag.
If no error, positions x right after the tag.
func (*BuffersSlice) ParseUint32Field ¶ added in v0.53.0
ParseUint32Field parses following uint32 field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ParseUint64Field ¶ added in v0.53.0
ParseUint64Field parses following uint64 field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (*BuffersSlice) ReadOnlyData ¶ added in v0.53.0
func (x *BuffersSlice) ReadOnlyData() []byte
ReadOnlyData returns read-only buffer of data remaining in x.
func (*BuffersSlice) SkipRepeatedEnum ¶ added in v0.53.0
SkipRepeatedEnum verifies following repeated enum field with preread number and type.
If no error, positions x right after the field.
If there is an error, its text contains num and typ.
func (BuffersSlice) WriteTo ¶ added in v0.53.0
func (x BuffersSlice) WriteTo(w io.Writer) (int64, error)
WriteTo implements io.WriterTo by writing all data in x into w.
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
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
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.
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.