Documentation ¶
Index ¶
- Variables
- func Bool(v bool) *bool
- func ClearAllExtensions(msg interface{})
- func ClearExtension(msg interface{}, ext interface{})
- func EncodeTag(dest []byte, tag int, wireType WireType) int
- func EncodeVarint(dest []byte, v uint64) int
- func EncodeZigZag32(dest []byte, v int32) int
- func EncodeZigZag64(dest []byte, v int64) int
- func Equal(m1, m2 interface{}) bool
- func Float32(v float32) *float32
- func Float64(v float64) *float64
- func GetExtension(msg interface{}, ext interface{}) (interface{}, error)
- func HasExtension(msg interface{}, ext interface{}) bool
- func Int(v int) *int32
- func Int32(v int32) *int32
- func Int64(v int64) *int64
- func JSONMarshaler(msg interface{}, opts ...JSONOption) json.Marshaler
- func Marshal(msg interface{}) ([]byte, error)
- func MarshalText(msg interface{}) (string, error)
- func PointerTo[T NativeTypes](v T) *T
- func SetExtension(msg interface{}, ext interface{}, val interface{}) error
- func Size(msg interface{}) int
- func SizeOfTagKey(k int) int
- func SizeOfVarint(v uint64) int
- func SizeOfZigZag(v uint64) int
- func String(v string) *string
- func Uint32(v uint32) *uint32
- func Uint64(v uint64) *uint64
- func Unmarshal(data []byte, msg interface{}) error
- type Decoder
- func (d *Decoder) DecodeBool() (b bool, err error)
- func (d *Decoder) DecodeBytes() ([]byte, error)
- func (d *Decoder) DecodeFixed32() (uint32, error)
- func (d *Decoder) DecodeFixed64() (uint64, error)
- func (d *Decoder) DecodeFloat32() (float32, error)
- func (d *Decoder) DecodeFloat64() (float64, error)
- func (d *Decoder) DecodeInt32() (int32, error)
- func (d *Decoder) DecodeInt64() (int64, error)
- func (d *Decoder) DecodeNested(m interface{}) error
- func (d *Decoder) DecodePackedBool() ([]bool, error)
- func (d *Decoder) DecodePackedFixed32() ([]uint32, error)
- func (d *Decoder) DecodePackedFixed64() ([]uint64, error)
- func (d *Decoder) DecodePackedFloat32() ([]float32, error)
- func (d *Decoder) DecodePackedFloat64() ([]float64, error)
- func (d *Decoder) DecodePackedInt32() ([]int32, error)
- func (d *Decoder) DecodePackedInt64() ([]int64, error)
- func (d *Decoder) DecodePackedSint32() ([]int32, error)
- func (d *Decoder) DecodePackedSint64() ([]int64, error)
- func (d *Decoder) DecodePackedUint32() ([]uint32, error)
- func (d *Decoder) DecodePackedUint64() ([]uint64, error)
- func (d *Decoder) DecodeSInt32() (int32, error)
- func (d *Decoder) DecodeSInt64() (int64, error)
- func (d *Decoder) DecodeString() (string, error)
- func (d *Decoder) DecodeTag() (tag int, wireType WireType, err error)
- func (d *Decoder) DecodeUInt32() (uint32, error)
- func (d *Decoder) DecodeUInt64() (uint64, error)
- func (d *Decoder) More() bool
- func (d *Decoder) Reset()
- func (d *Decoder) SetMode(m DecoderMode)
- func (d *Decoder) Skip(tag int, wt WireType) ([]byte, error)
- type DecoderMode
- type DecoderSkipError
- type Encoder
- func (e *Encoder) EncodeBool(tag int, v bool)
- func (e *Encoder) EncodeBytes(tag int, v []byte)
- func (e *Encoder) EncodeFixed32(tag int, v uint32)
- func (e *Encoder) EncodeFixed64(tag int, v uint64)
- func (e *Encoder) EncodeFloat32(tag int, v float32)
- func (e *Encoder) EncodeFloat64(tag int, v float64)
- func (e *Encoder) EncodeInt32(tag int, v int32)
- func (e *Encoder) EncodeInt64(tag int, v int64)
- func (e *Encoder) EncodeMapEntryHeader(tag int, size int)
- func (e *Encoder) EncodeNested(tag int, m interface{}) error
- func (e *Encoder) EncodePackedBool(tag int, vs []bool)
- func (e *Encoder) EncodePackedFixed32(tag int, vs []uint32)
- func (e *Encoder) EncodePackedFixed64(tag int, vs []uint64)
- func (e *Encoder) EncodePackedFloat32(tag int, vs []float32)
- func (e *Encoder) EncodePackedFloat64(tag int, vs []float64)
- func (e *Encoder) EncodePackedInt32(tag int, vs []int32)
- func (e *Encoder) EncodePackedInt64(tag int, vs []int64)
- func (e *Encoder) EncodePackedSFixed32(tag int, vs []int32)
- func (e *Encoder) EncodePackedSFixed64(tag int, vs []int64)
- func (e *Encoder) EncodePackedSInt32(tag int, vs []int32)
- func (e *Encoder) EncodePackedSInt64(tag int, vs []int64)
- func (e *Encoder) EncodePackedUInt32(tag int, vs []uint32)
- func (e *Encoder) EncodePackedUInt64(tag int, vs []uint64)
- func (e *Encoder) EncodeRaw(d []byte)
- func (e *Encoder) EncodeSInt32(tag int, v int32)
- func (e *Encoder) EncodeSInt64(tag int, v int64)
- func (e *Encoder) EncodeString(tag int, s string)
- func (e *Encoder) EncodeUInt32(tag int, v uint32)
- func (e *Encoder) EncodeUInt64(tag int, v uint64)
- type GrpcCodec
- type JSONOption
- type Marshaler
- type MarshalerTo
- type MessageType
- type NativeTypes
- type ProtoV1Marshaler
- type ProtoV1Sizer
- type ProtoV1Unmarshaler
- type Sizer
- type Unmarshaler
- type WireType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidFieldTag is returned by the decoder when it fails to read a varint-encoded field tag/wire type value. ErrInvalidFieldTag = errors.New("unable to read protobuf field tag") // ErrInvalidVarintData is returned by the decoder when it fails to read a varint-encoded value. ErrInvalidVarintData = errors.New("unable to read protobuf varint value") // ErrValueOverflow is returned by DecodeUInt32() or DecodeInt32() when the decoded value is too large for a 32-bit value. ErrValueOverflow = errors.New("value overflow trying to read protobuf varint value") // ErrInvalidZigZagData is returned by the decoder when it fails to read a zigzag-encoded value. ErrInvalidZigZagData = errors.New("unable to read protobuf zigzag value") // ErrInvalidFixed32Data is returned by the decoder when it fails to read a fixed-size 32-bit value. ErrInvalidFixed32Data = errors.New("unable to read protobuf fixed 32-bit value") // ErrInvalidFixed64Data is returned by the decoder when it fails to read a fixed-size 64-bit value. ErrInvalidFixed64Data = errors.New("unable to read protobuf fixed 64-bit value") // ErrInvalidPackedData is returned by the decoder when it fails to read a packed repeated value. ErrInvalidPackedData = errors.New("unable to read protobuf packed value") )
var ( // ErrMarshaler is returned the Marshal() function when a message is passed in that does not // match any of the supported behaviors ErrMarshaler = errors.New("message does not implement csproto.Marshaler") // ErrUnmarshaler is returned the Unmarshal() function when a message is passed in that does not // match any of the supported behaviors ErrUnmarshaler = errors.New("message does not implement csproto.Unmarshaler") )
Functions ¶
func Bool ¶
Bool returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func ClearAllExtensions ¶ added in v0.8.0
func ClearAllExtensions(msg interface{})
ClearAllExtensions removes all proto2 extension fields from msg.
This operation can be very inefficient, especially for Google V2 messages, so it is generally better to explicitly clear individual extension fields.
func ClearExtension ¶ added in v0.3.0
func ClearExtension(msg interface{}, ext interface{})
ClearExtension removes a proto2 extension field from msg, if it exists, delegating to the appropriate underlying Protobuf API based on the concrete type of msg.
This function panics if the provded parameters are invalid, rather than returning an error, to be consistent with the signature of the ClearExtension() functions in the underlying Protobuf runtimes.
func EncodeTag ¶
EncodeTag combines tag and wireType then encodes the result into dest using the Protobuf varint format and returns the number of bytes written.
func EncodeVarint ¶
EncodeVarint encodes v into dest using the Protobuf base-128 varint format and returns the number of bytes written
func EncodeZigZag32 ¶
EncodeZigZag32 encodes v into dest using the Protobuf zig/zag encoding for more efficient encoding of negative numbers, and returns the number of bytes written.
func EncodeZigZag64 ¶
EncodeZigZag64 encodes v into dest using the Protobuf zig/zag encoding for more efficient encoding of negative numbers, and returns the number of bytes written.
func Equal ¶ added in v0.11.0
func Equal(m1, m2 interface{}) bool
Equal returns true iff m1 and m2 are equal.
If m1 and m2 are not the same "type" (generated for the same runtime) then they are not equal. Otherwise, we delegate comparison to the appropriate underlying Protobuf API based on the concrete type of the messages
func Float32 ¶
Float32 returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func Float64 ¶
Float64 returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func GetExtension ¶
func GetExtension(msg interface{}, ext interface{}) (interface{}, error)
GetExtension returns a proto2 extension field from msg, delegating to the appropriate underlying Protobuf API based on the concrete type of msg.
func HasExtension ¶
func HasExtension(msg interface{}, ext interface{}) bool
HasExtension returns true if msg contains the specified proto2 extension field, delegating to the appropriate underlying Protobuf API based on the concrete type of msg.
func Int ¶
Int returns a pointer to v as an int32 value (for use when assigning pointer fields on Protobuf message types)
func Int32 ¶
Int32 returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func Int64 ¶
Int64 returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func JSONMarshaler ¶ added in v0.2.0
func JSONMarshaler(msg interface{}, opts ...JSONOption) json.Marshaler
JSONMarshaler returns an implementation of the json.Marshaler interface that formats msg to JSON using the specified options.
func Marshal ¶
Marshal marshals msg to binary Protobuf format, delegating to the appropriate underlying Protobuf API based on the concrete type of msg.
func MarshalText ¶ added in v0.9.0
MarshalText converts the specified message to prototext string format
func PointerTo ¶
func PointerTo[T NativeTypes](v T) *T
PointerTo makes a copy of v and returns a pointer to that copy
func SetExtension ¶
func SetExtension(msg interface{}, ext interface{}, val interface{}) error
SetExtension sets a proto2 extension field in msg to the provided value, delegating to the appropriate underlying Protobuf API based on the concrete type of msg.
func SizeOfTagKey ¶
SizeOfTagKey returns the number of bytes required to hold the Protobuf varint encoding of k.
func SizeOfVarint ¶
SizeOfVarint returns the number of bytes required to hold the Protobuf varint encoding of v.
func SizeOfZigZag ¶
SizeOfZigZag returns the number of bytes required to hold the zig zag encoding of v.
func String ¶
String returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
func Uint32 ¶
Uint32 returns a pointer to v (for use when assigning pointer fields on Protobuf message types)
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder implements a binary Protobuf Decoder by sequentially reading from a provided []byte.
func NewDecoder ¶
NewDecoder initializes a new Protobuf decoder to read the provided buffer.
func (*Decoder) DecodeBool ¶
DecodeBool decodes a boolean value from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeBytes ¶
DecodeBytes decodes a length-delimited slice of bytes from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeFixed32 ¶
DecodeFixed32 decodes a 4-byte integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeFixed64 ¶
DecodeFixed64 decodes an 8-byte integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeFloat32 ¶
DecodeFloat32 decodes a 4-byte IEEE 754 floating point value from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeFloat64 ¶
DecodeFloat64 decodes an 8-byte IEEE 754 floating point value from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeInt32 ¶
DecodeInt32 decodes a varint-encoded 32-bit integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeInt64 ¶
DecodeInt64 decodes a varint-encoded 64-bit integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeNested ¶
DecodeNested decodes a nested Protobuf message from the stream into m. If m satisfies our csproto.Unmarshaler interface its Unmarshal() method will be called. Otherwise, this method delegates to Marshal().
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedBool ¶
DecodePackedBool decodes a packed encoded list of boolean values from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedFixed32 ¶
DecodePackedFixed32 decodes a packed encoded list of 32-bit fixed-width integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedFixed64 ¶
DecodePackedFixed64 decodes a packed encoded list of 64-bit fixed-width integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedFloat32 ¶
DecodePackedFloat32 decodes a packed encoded list of 32-bit floating point numbers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedFloat64 ¶
DecodePackedFloat64 decodes a packed encoded list of 64-bit floating point numbers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedInt32 ¶
DecodePackedInt32 decodes a packed encoded list of 32-bit integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedInt64 ¶
DecodePackedInt64 decodes a packed encoded list of 64-bit integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedSint32 ¶
DecodePackedSint32 decodes a packed encoded list of 32-bit signed integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedSint64 ¶
DecodePackedSint64 decodes a packed encoded list of 64-bit signed integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedUint32 ¶
DecodePackedUint32 decodes a packed encoded list of unsigned 32-bit integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodePackedUint64 ¶
DecodePackedUint64 decodes a packed encoded list of unsigned 64-bit integers from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeSInt32 ¶
DecodeSInt32 decodes a zigzag-encoded 32-bit integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeSInt64 ¶
DecodeSInt64 decodes a zigzag-encoded 32-bit integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeString ¶
DecodeString decodes a length-delimited string from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeTag ¶
DecodeTag decodes a field tag and Protobuf wire type from the stream and returns the values.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeUInt32 ¶
DecodeUInt32 decodes a varint-encoded 32-bit unsigned integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) DecodeUInt64 ¶
DecodeUInt64 decodes a varint-encoded 64-bit unsigned integer from the stream and returns the value.
io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
func (*Decoder) Reset ¶
func (d *Decoder) Reset()
Reset moves the read offset back to the beginning of the encoded data
func (*Decoder) SetMode ¶
func (d *Decoder) SetMode(m DecoderMode)
SetMode configures the decoding behavior, safe vs fastest.
func (*Decoder) Skip ¶
Skip skips over the encoded field value at the current offset, returning the raw bytes so that the caller can decide what to do with the data.
The tag and wire type are validated against the provided values and a DecoderSkipError error is returned if they do not match. This check is skipped when using "fast" mode.
io.ErrUnexpectedEOF is returned if the operation would advance past the end of the data.
type DecoderMode ¶
type DecoderMode int
DecoderMode defines the behavior of the decoder (safe vs fastest).
const ( // DecoderModeSafe instructs the decoder to only use safe operations when decoding values. DecoderModeSafe DecoderMode = iota // DecoderModeFast instructs the decoder to use unsafe operations to avoid allocations and copying data // for the fastest throughput. // // When using DecoderModeFast, the byte slice passed to the decoder must not be modified after // using the decoder to extract values. The behavior is undefined if the slice is modified. DecoderModeFast )
func (DecoderMode) String ¶
func (m DecoderMode) String() string
String returns a string representation of m, "safe" or "fast".
type DecoderSkipError ¶
type DecoderSkipError struct { ExpectedTag int ExpectedWireType WireType ActualTag int ActualWireType WireType }
DecoderSkipError defines an error returned by the decoder's Skip() method when the specified tag and wire type do not match the data in the stream at the current decoder offset.
func (*DecoderSkipError) Error ¶
func (e *DecoderSkipError) Error() string
Error satisfies the error interface
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder implements a binary Protobuf Encoder by sequentially writing to a wrapped []byte.
func NewEncoder ¶
NewEncoder initializes a new Protobuf encoder to write to the specified buffer, which must be pre-allocated by the caller with sufficient space to hold the message(s) being written.
func (*Encoder) EncodeBool ¶
EncodeBool writes a varint-encoded boolean value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeBytes ¶
EncodeBytes writes a length-delimited byte slice to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeFixed32 ¶
EncodeFixed32 writes a 32-bit unsigned integer value to the buffer using 4 bytes in little endian format, preceded by the varint-encoded tag key.
func (*Encoder) EncodeFixed64 ¶
EncodeFixed64 writes a 64-bit unsigned integer value to the buffer using 8 bytes in little endian format, preceded by the varint-encoded tag key.
func (*Encoder) EncodeFloat32 ¶
EncodeFloat32 writes a 32-bit IEEE 754 floating point value to the buffer using 4 bytes in little endian format, preceded by the varint-encoded tag key.
func (*Encoder) EncodeFloat64 ¶
EncodeFloat64 writes a 64-bit IEEE 754 floating point value to the buffer using 8 bytes in little endian format, preceded by the varint-encoded tag key.
func (*Encoder) EncodeInt32 ¶
EncodeInt32 writes a varint-encoded 32-bit signed integer value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeInt64 ¶
EncodeInt64 writes a varint-encoded 64-bit signed integer value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeMapEntryHeader ¶
EncodeMapEntryHeader writes a map entry header into the buffer, which consists of the specified tag with a wire type of WireTypeLengthDelimited followed by the varint encoded entry size.
func (*Encoder) EncodeNested ¶
EncodeNested writes a nested message to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedBool ¶
EncodePackedBool writes a list of booleans to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedFixed32 ¶
EncodePackedFixed32 writes a list of 32-bit fixed-width unsigned integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedFixed64 ¶
EncodePackedFixed64 writes a list of 64-bit fixed-width unsigned integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedFloat32 ¶
EncodePackedFloat32 writes a list of 32-bit floating point numbers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedFloat64 ¶
EncodePackedFloat64 writes a list of 64-bit floating point numbers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedInt32 ¶
EncodePackedInt32 writes a list of 32-bit integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodePackedInt64 ¶
EncodePackedInt64 writes a list of 64-bit integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodePackedSFixed32 ¶
EncodePackedSFixed32 writes a list of 32-bit fixed-width signed integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedSFixed64 ¶
EncodePackedSFixed64 writes a list of 64-bit fixed-width signed integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
func (*Encoder) EncodePackedSInt32 ¶
EncodePackedSInt32 writes a list of 32-bit signed integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodePackedSInt64 ¶
EncodePackedSInt64 writes a list of 64-bit signed integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodePackedUInt32 ¶
EncodePackedUInt32 writes a list of 32-bit unsigned integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodePackedUInt64 ¶
EncodePackedUInt64 writes a list of 64-bit unsigned integers to the buffer using packed encoding, preceded by the varint-encoded tag key.
This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
func (*Encoder) EncodeRaw ¶
EncodeRaw writes the raw bytes of d into the buffer at the current offset
func (*Encoder) EncodeSInt32 ¶
EncodeSInt32 writes a zigzag-encoded 32-bit signed integer value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeSInt64 ¶
EncodeSInt64 writes a zigzag-encoded 64-bit signed integer value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeString ¶
EncodeString writes a length-delimited string value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeUInt32 ¶
EncodeUInt32 writes a varint-encoded 32-bit unsigned integer value to the buffer preceded by the varint-encoded tag key.
func (*Encoder) EncodeUInt64 ¶
EncodeUInt64 writes a varint-encoded 64-bit unsigned integer value to the buffer preceded by the varint-encoded tag key.
type GrpcCodec ¶
type GrpcCodec struct{}
GrpcCodec implements gRPC encoding.Codec. See: https://pkg.go.dev/google.golang.org/grpc/encoding#Codec
type JSONOption ¶ added in v0.2.0
type JSONOption func(*jsonOptions)
JSONOption defines a function that sets a specific JSON formatting option
func JSONIncludeZeroValues ¶ added in v0.2.0
func JSONIncludeZeroValues(emitZeroValues bool) JSONOption
JSONIncludeZeroValues returns a JSON option that enables or disables including zero-valued fields in the JSON output.
func JSONIndent ¶ added in v0.2.0
func JSONIndent(indent string) JSONOption
JSONIndent returns a JSONOption that configures the JSON indentation.
Passing an empty string disables indentation. If not empty, indent must consist of only spaces or tab characters.
func JSONUseEnumNumbers ¶ added in v0.2.0
func JSONUseEnumNumbers(useNumbers bool) JSONOption
JSONUseEnumNumbers returns a JSON option that enables or disables outputting integer values rather than the enum names for enum fields.
type Marshaler ¶
type Marshaler interface { // Marshal allocates a buffer large enough to hold this message, writes the contents of the // message into it, then returns the buffer. Marshal() ([]byte, error) }
Marshaler defines a message that can marshal itself into binary Protobuf format.
type MarshalerTo ¶
type MarshalerTo interface { // MarshalTo writes the contents of this message into dest using the binary Protobuf encoding. // // It is up to the caller to ensure that the buffer is large enough to hold the serialized message // data. MarshalTo(dest []byte) error }
MarshalerTo defines a message that can marshal itself into a provided buffer in binary Protobuf format.
type MessageType ¶
type MessageType int
MessageType defines the types of Protobuf message implementations this API supports.
const ( // MessageTypeUnknown indicates that we don't know which type of Protobuf message a type is. MessageTypeUnknown MessageType = iota // MessageTypeGogo indicates that a type was generated using Gogo Protobuf. MessageTypeGogo // MessageTypeGoogleV1 indicates that a type was generated using v1 of Google's Protobuf tools. MessageTypeGoogleV1 // MessageTypeGoogle indicates that a type was generated using v2 of Google's Protobuf tools. MessageTypeGoogle )
func MsgType ¶
func MsgType(msg interface{}) MessageType
MsgType accepts a protobuf message and returns the corresponding MessageType value.
type NativeTypes ¶
NativeTypes defines a generic constraint for the native Go types that need to be converted to pointers when storing values in generated Protobuf message structs.
Unsized integers (type int) also need to be converted to a pointer, but Protobuf doesn't support unsized integers. Use csproto.Int(v int) *int32 instead.
type ProtoV1Marshaler ¶
type ProtoV1Marshaler interface { ProtoV1Sizer XXX_Marshal(b []byte, deterministic bool) ([]byte, error) }
ProtoV1Marshaler defines the interface for a type that provides custom Protobuf V1 marshaling logic.
type ProtoV1Sizer ¶
type ProtoV1Sizer interface {
XXX_Size() int
}
ProtoV1Sizer defines the interface for a type that provides custom Protobuf V1 sizing logic.
type ProtoV1Unmarshaler ¶
ProtoV1Unmarshaler defines the interface a type that provides custom Protobuf V1 unmarshaling.
type Sizer ¶
type Sizer interface { // Size returns the size, in bytes, required to serialize a message into binary Protobuf format. Size() int }
Sizer defines a message that can pre-calculate the required size for storing the binary Protobuf encoding of its contents.
type Unmarshaler ¶
type Unmarshaler interface { // Unmarshal decodes the binary Protobuf data into this message. Unmarshal([]byte) error }
Unmarshaler defines a message that can unmarshal binary Protobuf data into itself.
type WireType ¶
type WireType int
WireType defines the supported values for Protobuf wire encodings.
const ( // WireTypeVarint denotes a value that is encoded using base128 varint encoding. WireTypeVarint WireType = 0 // WireTypeFixed64 denotes a value that is encoded using 8 bytes. WireTypeFixed64 WireType = 1 // WireTypeLengthDelimited denotes a value that is encoded as a sequence of bytes preceded by a // varint-encoded length. WireTypeLengthDelimited WireType = 2 // WireTypeFixed32 denotes a value that is encoded using 4 bytes. WireTypeFixed32 WireType = 5 )