Documentation
¶
Overview ¶
Package proto contains helper functions for Protocol Buffers (https://protobuf.dev) in addition to the ones from google.golang.org/protobuf/encoding/protowire package.
Index ¶
- Constants
- func CalculateRepeatedFieldsLength(num protowire.Number, count int, lenFn RepeatedMessageLenFunc) int
- func CalculateRequestBodyFieldLength(ln int) int
- func CalculateRequestBodyWithMetaHeaderLength(bodyLen int, metaHdrLen int) int
- func CalculateRequestLength(bodyLen int, metaHdrLen int, verifHdrLen int) int
- func CalculateRequestMetaHeaderFieldLength(ln int) int
- func CalculateRequestVerificationHeaderFieldLength(ln int) int
- func EncodeRequest[B, M Message](buf []byte, reqBody B, reqMetaHeader M) ([]byte, int)
- func Marshal[M Message, T interface{ ... }](v T) []byte
- func MarshalJSON[M proto.Message, T interface{ ... }](v T) ([]byte, error)
- func MarshalMessage(m Message) []byte
- func MarshalMessageJSON(m proto.Message) ([]byte, error)
- func MarshalToBool(b []byte, num protowire.Number, v bool) int
- func MarshalToBytes[T Bytes](b []byte, num protowire.Number, v T) int
- func MarshalToDouble(b []byte, num protowire.Number, v float64) int
- func MarshalToEmbedded(b []byte, num protowire.Number, v Message) int
- func MarshalToEmbeddedLength(b []byte, num protowire.Number, sz int, v Message) int
- func MarshalToFixed32(b []byte, num protowire.Number, v uint32) int
- func MarshalToFixed64(b []byte, num protowire.Number, v uint64) int
- func MarshalToFloat(b []byte, num protowire.Number, v float32) int
- func MarshalToOptionalVarint[T Varint](b []byte, num protowire.Number, v *T) int
- func MarshalToRepeatedBytes[T Bytes](b []byte, num protowire.Number, v []T) int
- func MarshalToRepeatedMessages[T any, M interface{ ... }](b []byte, num protowire.Number, v []M) int
- func MarshalToRepeatedVarint[T Varint](b []byte, num protowire.Number, v []T) int
- func MarshalToVarint[T Varint](b []byte, num protowire.Number, v T) int
- func SizeBool(num protowire.Number, v bool) int
- func SizeBytes[T Bytes](num protowire.Number, v T) int
- func SizeDouble(num protowire.Number, v float64) int
- func SizeEmbedded(num protowire.Number, v Message) int
- func SizeEmbeddedLENField(num protowire.Number, ln int) int
- func SizeFixed32(num protowire.Number, v uint32) int
- func SizeFixed64(num protowire.Number, v uint64) int
- func SizeFloat(num protowire.Number, v float32) int
- func SizeOptionalVarint[T Varint](num protowire.Number, v *T) int
- func SizeRepeatedBytes[T Bytes](num protowire.Number, v []T) int
- func SizeRepeatedMessages[T any, M interface{ ... }](num protowire.Number, v []M) int
- func SizeRepeatedVarint[T Varint](num protowire.Number, v []T) int
- func SizeVarint[T Varint](num protowire.Number, v T) int
- func Unmarshal[M_ any, M interface{ ... }, T interface{ ... }](b []byte, v T) error
- func UnmarshalJSON[M_ any, M interface{ ... }, T interface{ ... }](b []byte, v T) error
- func UnmarshalJSONOptional[M_ any, M interface{ ... }, T interface{ ... }](b []byte, v T, dec func(T, M, bool) error) error
- func UnmarshalMessage(b []byte, m proto.Message) error
- func UnmarshalMessageJSON(b []byte, m proto.Message) error
- func UnmarshalOptional[M_ any, M interface{ ... }, T interface{ ... }](b []byte, v T, dec func(T, M, bool) error) error
- func WriteMessageField(buf []byte, num protowire.Number, ln int, writeFn WriteMessageFunc) int
- func WriteRepeatedFields(buf []byte, num protowire.Number, count int, lenFn RepeatedMessageLenFunc, ...) int
- func WriteRequestBodyMessage(buf []byte, m Message) int
- func WriteRequestBodyTagAndLength(buf []byte, ln int) int
- func WriteRequestMetaHeaderMessage(buf []byte, m Message) int
- func WriteRequestMetaHeaderTagAndLength(buf []byte, metaHdrLen int) int
- func WriteRequestVerificationHeaderMessage(buf []byte, m Message) int
- func WriteRequestVerificationHeaderTagAndLength(buf []byte, ln int) int
- func WriteStablyMarshalledMessageField(buf []byte, num protowire.Number, m Message) int
- func WriteTag(buf []byte, num protowire.Number, typ protowire.Type) int
- func WriteTagAndLength(buf []byte, num protowire.Number, ln int) int
- func WriteTagAndVarint[T Varint](buf []byte, num protowire.Number, typ protowire.Type, v T) int
- type Bytes
- type Message
- type RepeatedMessageLenFunc
- type Varint
- type WriteMessageFunc
- type WriteRepeatedMessageFunc
Constants ¶
const ( FieldRequestBody = 1 FieldRequestMetaHeader = 2 FieldRequestVerificationHeader = 3 )
Common request field numbers.
Variables ¶
This section is empty.
Functions ¶
func CalculateRepeatedFieldsLength ¶
func CalculateRepeatedFieldsLength(num protowire.Number, count int, lenFn RepeatedMessageLenFunc) int
CalculateRepeatedFieldsLength returns length of specified number of repeated messages with given field number.
func CalculateRequestBodyFieldLength ¶
CalculateRequestBodyFieldLength returns length of field for the request body with given length.
func CalculateRequestBodyWithMetaHeaderLength ¶
CalculateRequestBodyWithMetaHeaderLength returns length of request body and meta header fields with specified lengths.
func CalculateRequestLength ¶
CalculateRequestLength returns length of request body, meta header and verification header fields with specified lengths.
func CalculateRequestMetaHeaderFieldLength ¶
CalculateRequestMetaHeaderFieldLength returns length of field for the request meta header with given length.
func CalculateRequestVerificationHeaderFieldLength ¶
CalculateRequestVerificationHeaderFieldLength returns length of field for the request verification header with given length.
func EncodeRequest ¶
EncodeRequest ONLY correctly encodes requests that have strictly ordered two fields (excepting verification header): field #1 is body, field #2 is meta header. Any other requests must be encoded differently. The second returned value means buffer len occupied for req.
func Marshal ¶
Marshal encodes v transmitted via NeoFS API protocol into a dynamically allocated buffer.
func MarshalJSON ¶
MarshalJSON encodes v into protojson with unpopulated fields' emission.
func MarshalMessage ¶
MarshalMessage encodes m into a dynamically allocated buffer.
func MarshalMessageJSON ¶
MarshalMessageJSON encodes m into protojson with unpopulated fields' emission.
func MarshalToBool ¶
MarshalToBool encodes 'bool' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToBool will panic.
func MarshalToBytes ¶
MarshalToBytes encodes 'bytes' or 'string' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToBytes will panic.
func MarshalToDouble ¶
MarshalToDouble encodes 'double' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToDouble will panic.
func MarshalToEmbedded ¶
MarshalToEmbedded encodes embedded message being a protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToEmbedded will panic.
func MarshalToEmbeddedLength ¶
MarshalToEmbeddedLength encodes embedded message being a protobuf field with given number, length and value into b and returns the number of bytes written. If the buffer is too small, MarshalToEmbeddedLength will panic.
Does not write field if message length is zero.
func MarshalToFixed32 ¶
MarshalToFixed32 encodes 'fixed32' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToFixed32 will panic.
func MarshalToFixed64 ¶
MarshalToFixed64 encodes 'fixed64' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToFixed64 will panic.
func MarshalToFloat ¶
MarshalToFloat encodes 'float' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToFloat will panic.
func MarshalToOptionalVarint ¶
MarshalToOptionalVarint encodes an optional varint protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToOptionalVarint will panic.
func MarshalToRepeatedBytes ¶
MarshalToRepeatedBytes encodes 'repeated bytes' or 'repeated string' protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToRepeatedBytes will panic.
func MarshalToRepeatedMessages ¶
func MarshalToRepeatedMessages[T any, M interface { *T Message }](b []byte, num protowire.Number, v []M) int
MarshalToRepeatedMessages encodes 'repeated M' protobuf field with given number and values into b and returns the number of bytes written. If the buffer is too small, MarshalToRepeatedMessages will panic.
func MarshalToRepeatedVarint ¶
MarshalToRepeatedVarint encodes 'repeated' varint protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToRepeatedVarint will panic.
func MarshalToVarint ¶
MarshalToVarint encodes varint protobuf field with given number and value into b and returns the number of bytes written. If the buffer is too small, MarshalToVarint will panic.
func SizeBool ¶
SizeBool returns the encoded size of 'bool' protobuf field with given number and value.
func SizeBytes ¶
SizeBytes returns the encoded size of 'bytes' or 'string' protobuf field with given number and value.
func SizeDouble ¶
SizeDouble returns the encoded size of 'double' protobuf field with given number and value.
func SizeEmbedded ¶
SizeEmbedded returns the encoded size of embedded message being a protobuf field with given number and value.
func SizeEmbeddedLENField ¶
SizeEmbeddedLENField returns the encoded size of embedded LEN protobuf field with given number and length. Returns zero for zero length.
func SizeFixed32 ¶
SizeFixed32 returns the encoded size of 'fixed32' protobuf field with given number and value.
func SizeFixed64 ¶
SizeFixed64 returns the encoded size of 'fixed64' protobuf field with given number and value.
func SizeFloat ¶
SizeFloat returns the encoded size of 'float' protobuf field with given number and value.
func SizeOptionalVarint ¶
SizeOptionalVarint returns the encoded size of an optional varint protobuf field with given number and value.
func SizeRepeatedBytes ¶
SizeRepeatedBytes returns the encoded size of 'repeated bytes' or 'repeated string' protobuf field with given number and value.
func SizeRepeatedMessages ¶
SizeRepeatedMessages returns the encoded size of 'repeated M' protobuf field with given number and values.
func SizeRepeatedVarint ¶
SizeRepeatedVarint returns the encoded size of 'repeated' varint protobuf field with given number and value.
func SizeVarint ¶
SizeVarint returns the encoded size of varint protobuf field with given number and value.
func Unmarshal ¶
func Unmarshal[M_ any, M interface { *M_ proto.Message Message }, T interface{ FromProtoMessage(M) error }](b []byte, v T) error
Unmarshal decodes v transmitted via NeoFS API protocol from b.
func UnmarshalJSON ¶
func UnmarshalJSON[M_ any, M interface { *M_ proto.Message Message }, T interface{ FromProtoMessage(M) error }](b []byte, v T) error
UnmarshalJSON decodes v from protojson.
func UnmarshalJSONOptional ¶
func UnmarshalJSONOptional[M_ any, M interface { *M_ proto.Message Message }, T interface{ FromProtoMessage(M) error }](b []byte, v T, dec func(T, M, bool) error) error
UnmarshalJSONOptional decodes v from protojson with ignored missing required fields.
func UnmarshalMessage ¶
UnmarshalMessage decodes m from b.
func UnmarshalMessageJSON ¶
UnmarshalMessageJSON decodes m from protojson.
func UnmarshalOptional ¶
func UnmarshalOptional[M_ any, M interface { *M_ proto.Message Message }, T interface{ FromProtoMessage(M) error }](b []byte, v T, dec func(T, M, bool) error) error
UnmarshalOptional decodes v from protojson with ignored missing required fields.
func WriteMessageField ¶
WriteMessageField writes LEN message with given field number into buf. Returns number of bytes written.
func WriteRepeatedFields ¶
func WriteRepeatedFields(buf []byte, num protowire.Number, count int, lenFn RepeatedMessageLenFunc, writeFn WriteRepeatedMessageFunc) int
WriteRepeatedFields writes specified number of repeated messages with given field number into buf.
func WriteRequestBodyMessage ¶
WriteRequestBodyMessage writes request body field into buf. Returns number of bytes written.
func WriteRequestBodyTagAndLength ¶
WriteRequestBodyTagAndLength writes request body field tag and length into buf. Returns number of bytes written.
func WriteRequestMetaHeaderMessage ¶
WriteRequestMetaHeaderMessage writes request meta header field into buf. Returns number of bytes written.
func WriteRequestMetaHeaderTagAndLength ¶
WriteRequestMetaHeaderTagAndLength writes request meta header field tag and length into buf. Returns number of bytes written.
func WriteRequestVerificationHeaderMessage ¶
WriteRequestVerificationHeaderMessage writes request verification header field into buf. Returns number of bytes written.
func WriteRequestVerificationHeaderTagAndLength ¶
WriteRequestVerificationHeaderTagAndLength writes request verification header field tag and length into buf. Returns number of bytes written.
func WriteStablyMarshalledMessageField ¶
WriteStablyMarshalledMessageField writes m field with given number into buf. Returns number of bytes written.
func WriteTag ¶
WriteTag writes tag for the field of given number and type into buf. Returns number of bytes written.
func WriteTagAndLength ¶
WriteTagAndLength writes tag for the LEN field of given number and its length into buf. Returns number of bytes written.
Types ¶
type Message ¶
type Message interface {
// MarshaledSize returns size of the encoded Message in bytes.
MarshaledSize() int
// MarshalStable encodes the Message into b. If the buffer is too small,
// MarshalStable will panic.
MarshalStable(b []byte)
}
Message is provided by protobuf 'message' types used in NeoFS for so-called stable marshaling: protobuf with the order of fields in strict ascending order of their numbers.
type WriteMessageFunc ¶
Various function aliases.
func WriteStablyMarshalledMessageFunc ¶
func WriteStablyMarshalledMessageFunc(m Message) WriteMessageFunc
WriteStablyMarshalledMessageFunc returns function for m writing.
type WriteRepeatedMessageFunc ¶
Various function aliases.