Documentation ¶
Index ¶
- Variables
- func DecodeTag(tag uint64) (FieldNumber, WireType)
- func DecodeZigZag(v uint64) int64
- func EncodeTag(f FieldNumber, t WireType) uint64
- func EncodeZigZag(v int64) uint64
- func Marshal(v interface{}) ([]byte, error)
- func MarshalTo(b []byte, v interface{}) (int, error)
- func Parse(m []byte) (FieldNumber, WireType, RawValue, RawMessage, error)
- func Scan(b []byte, fn func(FieldNumber, WireType, RawValue) (bool, error)) error
- func Size(v interface{}) int
- func Unmarshal(b []byte, v interface{}) error
- type Field
- type FieldNumber
- func (f FieldNumber) Bool(v bool) RawMessage
- func (f FieldNumber) Bytes(v []byte) RawMessage
- func (f FieldNumber) Fixed32(v uint32) RawMessage
- func (f FieldNumber) Fixed64(v uint64) RawMessage
- func (f FieldNumber) Float32(v float32) RawMessage
- func (f FieldNumber) Float64(v float64) RawMessage
- func (f FieldNumber) Int(v int) RawMessage
- func (f FieldNumber) Int32(v int32) RawMessage
- func (f FieldNumber) Int64(v int64) RawMessage
- func (f FieldNumber) String(v string) RawMessage
- func (f FieldNumber) Uint(v uint) RawMessage
- func (f FieldNumber) Uint32(v uint32) RawMessage
- func (f FieldNumber) Uint64(v uint64) RawMessage
- func (f FieldNumber) Value(v interface{}) RawMessage
- type Kind
- type Message
- type MessageRewriter
- type RawMessage
- func Append(m RawMessage, f FieldNumber, t WireType, v []byte) RawMessage
- func AppendFixed32(m RawMessage, f FieldNumber, v uint32) RawMessage
- func AppendFixed64(m RawMessage, f FieldNumber, v uint64) RawMessage
- func AppendVarint(m RawMessage, f FieldNumber, v uint64) RawMessage
- func AppendVarlen(m RawMessage, f FieldNumber, v []byte) RawMessage
- type RawValue
- type RewriteFunc
- type Rewriter
- type Type
- type UnmarshalFieldError
- type WireType
Constants ¶
This section is empty.
Variables ¶
var (
ErrWireTypeUnknown = errors.New("unknown wire type")
)
Functions ¶
func DecodeTag ¶
func DecodeTag(tag uint64) (FieldNumber, WireType)
DecodeTag reverses the encoding applied by EncodeTag.
func DecodeZigZag ¶
DecodeZigZag reverses the encoding applied by EncodeZigZag.
func EncodeTag ¶
func EncodeTag(f FieldNumber, t WireType) uint64
EncodeTag encodes a pair of field number and wire type into a protobuf tag.
func EncodeZigZag ¶
EncodeZigZag returns v as a zig-zag encoded value.
func Parse ¶
func Parse(m []byte) (FieldNumber, WireType, RawValue, RawMessage, error)
Types ¶
type FieldNumber ¶
type FieldNumber uint
FieldNumber represents a protobuf field number.
func (FieldNumber) Bool ¶
func (f FieldNumber) Bool(v bool) RawMessage
func (FieldNumber) Bytes ¶
func (f FieldNumber) Bytes(v []byte) RawMessage
func (FieldNumber) Fixed32 ¶
func (f FieldNumber) Fixed32(v uint32) RawMessage
func (FieldNumber) Fixed64 ¶
func (f FieldNumber) Fixed64(v uint64) RawMessage
func (FieldNumber) Float32 ¶
func (f FieldNumber) Float32(v float32) RawMessage
func (FieldNumber) Float64 ¶
func (f FieldNumber) Float64(v float64) RawMessage
func (FieldNumber) Int ¶
func (f FieldNumber) Int(v int) RawMessage
func (FieldNumber) Int32 ¶
func (f FieldNumber) Int32(v int32) RawMessage
func (FieldNumber) Int64 ¶
func (f FieldNumber) Int64(v int64) RawMessage
func (FieldNumber) String ¶
func (f FieldNumber) String(v string) RawMessage
func (FieldNumber) Uint ¶
func (f FieldNumber) Uint(v uint) RawMessage
func (FieldNumber) Uint32 ¶
func (f FieldNumber) Uint32(v uint32) RawMessage
func (FieldNumber) Uint64 ¶
func (f FieldNumber) Uint64(v uint64) RawMessage
func (FieldNumber) Value ¶
func (f FieldNumber) Value(v interface{}) RawMessage
Value constructs a RawMessage for field number f from v.
type Kind ¶
type Kind int
Kind is an enumeration representing the various data types supported by the protobuf language.
type Message ¶
type Message interface { // Size is the size of the protobuf representation (in bytes). Size() int // Marshal writes the message to the byte slice passed as argument. Marshal([]byte) error // Unmarshal reads the message from the byte slice passed as argument. Unmarshal([]byte) error }
Message is an interface implemented by types that supported being encoded to and decoded from protobuf.
type MessageRewriter ¶
type MessageRewriter []Rewriter
MessageRewriter maps field numbers to rewrite rules, satisfying the Rewriter interace to support composing rewrite rules.
type RawMessage ¶
type RawMessage []byte
RawMessage represents a raw protobuf-encoded message.
func Append ¶
func Append(m RawMessage, f FieldNumber, t WireType, v []byte) RawMessage
func AppendFixed32 ¶
func AppendFixed32(m RawMessage, f FieldNumber, v uint32) RawMessage
func AppendFixed64 ¶
func AppendFixed64(m RawMessage, f FieldNumber, v uint64) RawMessage
func AppendVarint ¶
func AppendVarint(m RawMessage, f FieldNumber, v uint64) RawMessage
func AppendVarlen ¶
func AppendVarlen(m RawMessage, f FieldNumber, v []byte) RawMessage
func (RawMessage) Marshal ¶
func (m RawMessage) Marshal(b []byte) error
Marshal satisfies the Message interface.
func (RawMessage) Rewrite ¶
func (m RawMessage) Rewrite(out, _ []byte) ([]byte, error)
Rewrite satisfies the Rewriter interface.
func (*RawMessage) Unmarshal ¶
func (m *RawMessage) Unmarshal(b []byte) error
Unmarshal satisfies the Message interface.
type RawValue ¶
type RawValue []byte
RawValue represents a single protobuf value.
RawValue instances are returned by Parse and share the backing array of the RawMessage that they were decoded from.
func (RawValue) Fixed32 ¶
Fixed32 decodes v as a fixed32.
The content of v will always be a valid fixed32 if v was returned by a call to Parse and the associated wire type was Fixed32. In other cases, the behavior of Fixed32 is undefined.
type RewriteFunc ¶
RewriteFunc is a function type implementing the Rewriter interface.
type Rewriter ¶
type Rewriter interface { // The function is expected to append the new content to the byte slice // passed as argument. If it wasn't able to perform the rewrite, it must // return a non-nil error. Rewrite(out, in []byte) ([]byte, error) }
Rewriter is an interface implemented by types that support rewriting protobuf messages.
func MultiRewriter ¶
MultiRewriter constructs a Rewriter which applies all rewriters passed as arguments.
type Type ¶
type Type interface { // Returns a human-readable representation of the type. String() string // Returns the name of the type. Name() string // Kind returns the kind of protobuf values that are represented. Kind() Kind // When the Type represents a protobuf map, calling this method returns the // type of the map keys. // // If the Type is not a map type, the method panics. Key() Type // When the Type represents a protobuf map, calling this method returns the // type of the map values. // // If the Type is not a map type, the method panics. Elem() Type // Returns the protobuf wire type for the Type it is called on. WireType() WireType // Returns the number of fields in the protobuf message. // // If the Type does not represent a struct type, the method returns zero. NumField() int // Returns the Field at the given in Type. // // If the Type does not represent a struct type, the method panics. Field(int) Field // Returns the Field with the given name in Type. // // If the Type does not represent a struct type, or if the field does not // exist, the method panics. FieldByName(string) Field // Returns the Field with the given number in Type. // // If the Type does not represent a struct type, or if the field does not // exist, the method panics. FieldByNumber(FieldNumber) Field // For unsigned types, convert to their zig-zag form. // // The method uses the following table to perform the conversion: // // base | zig-zag // --------+--------- // int32 | sint32 // int64 | sint64 // uint32 | sint32 // uint64 | sint64 // fixed32 | sfixed32 // fixed64 | sfixed64 // // If the type cannot be converted to a zig-zag type, the method panics. ZigZag() Type }
Type is an interface similar to reflect.Type. Values implementing this interface represent high level protobuf types.
Type values are safe to use concurrently from multiple goroutines.
Types are comparable value.
func TypeOf ¶
TypeOf returns the protobuf type used to represent a go type.
The function uses the following table to map Go types to Protobuf:
Go | Protobuf --------+--------- bool | bool int | int64 int32 | int32 int64 | int64 uint | uint64 uint32 | uint32 uint64 | uint64 float32 | float float64 | double string | string []byte | bytes map | map struct | message
Pointer types are also supported and automatically dereferenced.
type UnmarshalFieldError ¶
func (*UnmarshalFieldError) Error ¶
func (e *UnmarshalFieldError) Error() string
func (*UnmarshalFieldError) Unwrap ¶
func (e *UnmarshalFieldError) Unwrap() error