protobuf

package module
v0.0.0-...-201b277 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2016 License: ISC Imports: 8 Imported by: 0

README

Protobuf V3 GoDoc

Package protobuf converts data structures to and from the wire format of protocol buffers. See https://developers.google.com/protocol-buffers/docs/encoding for protocol buffers documentation.

This package does not require users to write or compile .proto files, but does not support all of the Protocol Buffer types.

The following table summarizes the correspondence between .proto definition types and Go field types:

Go Protocol Buffer
bool optional bool
uint64 optional uint64
uint32 optional uint64
int64 optional int64
int32 optional int32
float optional float32
double optional float64
time.Time optional int64
[]byte optional bytes
string optional string
struct optional message
[]bool repeated bool
[]uint64 repeated uint64
[]uint32 repeated uint64
[]int64 repeated int64
[]int32 repeated int32
[]float repeated float32
[]double repeated float64
[][]byte repeated bytes
[]string repeated string
[]struct repeated message

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(data []byte, v interface{}) ([]byte, error)

Marshal traverses the value v recursively and returns the protocol buffer encoding of v. The struct underlying v must be a pointer.

Marshal currently encodes all visible field, which does not allow distinction between 'required' and 'optional' fields. Marshal ignores unsupported struct field types.

The returned slice may be a sub- slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the protocol buffer representation in data and places the decoded result in v. If the struct underlying v does not match the data, the results can be unpredictable.

Unmarshal uses the inverse of the encodings that Marshal uses, allocating slices and pointers as necessary.

func UnmarshalUnsafe

func UnmarshalUnsafe(data []byte, v interface{}) error

UnmarshalUnsafe parses the protocol buffer representation in data and places the decoded result in v. If the struct underlying v does not match the data, the results can be unpredictable.

UnmarshalUnsafe uses the inverse of the encodings that Marshal uses, allocating slices and pointers as necessary.

UnmarshalUnsafe does not copy raw byte slices. Most code should use Unmarshal instead.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder manages the receipt of type and data information read from the remote side of a connection.

func NewDecoder

func NewDecoder(r Reader, max int) *Decoder

NewDecoder returns a new decoder that reads from the io.Reader.

Max defines the maximum size that can be read, if max is 0, the maximum message size is not checked.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decode first reads the varint encoded message size and then reads the next value from the input stream and stores it in the data represented by the empty interface value. If v is nil, the value will be discarded. Otherwise, the value underlying v must be a pointer to the correct type for the next data item received.

func (*Decoder) Reset

func (d *Decoder) Reset(r Reader, max int)

Reset discards any buffered data, resets all state, and switches the decoder reader to read from r.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder manages the transmission of type and data information to the other side of a connection.

func NewEncoder

func NewEncoder(w Writer, max int) *Encoder

NewEncoder returns a new encoder that will transmit on the io.Writer.

Max defines the maximum size that can be transmitted, if max is 0, the maximum message size is not checked.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode transmits the data item represented by the empty interface value, guaranteeing that all necessary type information has been transmitted first.

Encode first writes the varint encoded message size, traverses the value v recursively and writes the Protocol Buffer encoding of v. The struct underlying v must be a pointer.

Encode currently encodes all visible field and ignores unsupported Protocol Buffer struct field types.

type Reader

type Reader interface {
	io.ByteReader
	io.Reader
}

Reader defines the decode reader. Typically this is a *bufio.Reader.

type Writer

type Writer interface {
	WriteString(string) (int, error)
	io.ByteWriter
	io.Writer
}

Writer defines the encode writer. Typically this is a *bufio.Writer.

Directories

Path Synopsis
internal
proto
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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