protobuf

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: OSL-3.0 Imports: 4 Imported by: 2

README

ProtoBuf

Protocol Buffers

This module parses and formats the raw wire encoding.

Embedded message wire type

Currently Protocol Buffers is an inherently flawed protocol, in that it is not self describing. This is evidenced by the fact that "type 2" wire type, can be any of these values:

  1. string
  2. byte slice
  3. embedded message

Its pretty straight forward to check for string or byte slice. Also, not all input is a valid message. That gives you this result:

valid string valid message result
no no byte slice
no yes message or byte slice
yes no string
yes yes message or string

Ideally the protocol would have an extra wire type, for example "type 6", to designate embedded messages. But without that, its not possible in every case to know the structure of the input, unless you have a schema. Other protocols such as JSON are self describing, nothing is stopping ProtoBuf from being self describing as well. Granted, you lose the field names, but even just having the field numbers and values, with a defined structure as read from the input, would be quite useful. Quoting from the spec:

in other words, the last three bits of the number store the wire type

So that gives you this currently:

000 Varint
001 64-bit
010 Length-delimited
011 Start group
100 End group
101 32-bit
110
111

So you have at least two extra types that could be added. Even a single extra type for embedded messages would essentially make ProtoBuf self describing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes []byte

func (Bytes) Append

func (b Bytes) Append(data []byte) []byte

func (Bytes) GoString

func (b Bytes) GoString() string

type Field

type Field struct {
	Number Number
	Type   protowire.Type
	Value  Value
}

type Fixed32

type Fixed32 uint32

func (Fixed32) Append

func (f Fixed32) Append(data []byte) []byte

func (Fixed32) GoString

func (f Fixed32) GoString() string

type Fixed64

type Fixed64 uint64

func (Fixed64) Append

func (f Fixed64) Append(data []byte) []byte

func (Fixed64) GoString

func (f Fixed64) GoString() string

type Message

type Message []Field

func (*Message) Add

func (m *Message) Add(n Number, f func(*Message))

func (*Message) AddBytes added in v1.0.5

func (m *Message) AddBytes(n Number, v Bytes)

func (*Message) AddFixed32 added in v1.0.5

func (m *Message) AddFixed32(n Number, v Fixed32)

func (*Message) AddFixed64 added in v1.0.5

func (m *Message) AddFixed64(n Number, v Fixed64)

func (*Message) AddVarint added in v1.0.5

func (m *Message) AddVarint(n Number, v Varint)

func (Message) Append

func (m Message) Append(data []byte) []byte

func (*Message) Consume added in v1.0.5

func (m *Message) Consume(data []byte) error

func (Message) Encode added in v1.0.5

func (m Message) Encode() []byte

func (Message) Get added in v1.0.5

func (m Message) Get(n Number) chan Message

func (Message) GetBytes added in v1.0.5

func (m Message) GetBytes(n Number) chan Bytes

func (Message) GetFixed32 added in v1.0.5

func (m Message) GetFixed32(n Number) chan Fixed32

func (Message) GetFixed64 added in v1.0.5

func (m Message) GetFixed64(n Number) chan Fixed64

func (Message) GetVarint added in v1.0.5

func (m Message) GetVarint(n Number) chan Varint

func (Message) GoString

func (m Message) GoString() string

type Number

type Number = protowire.Number

type Value

type Value interface {
	Append([]byte) []byte
	fmt.GoStringer
}

type Varint

type Varint uint64

func (Varint) Append

func (v Varint) Append(data []byte) []byte

func (Varint) GoString

func (v Varint) GoString() string

Jump to

Keyboard shortcuts

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