pbcmpl

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package pbcmpl provides a header for proto.Message

One of the known protobuf issue is that user must control the size when unmarshaling. This package gives a solution to add a header for every proto.Message, in which there are: a semantic-version for checking compatibility, a header size and size of marshaled proto.Message.

Since 0.1.6

Index

Constants

View Source
const (

	// DefaultVer is the default version if the message to marshal does not
	// provide version.
	//
	// Since v0.1.6
	DefaultVer = "1.0.0"
)

Variables

View Source
var (
	// ErrInvalidHeaderSize indicates the size in the header is incorrect
	ErrInvalidHeaderSize = errors.New("headersize is incorrect")
)

Functions

func HeaderSize

func HeaderSize(msg proto.Message) int

HeaderSize returns the marshaled size of the header for a proto.Message .

Since 0.1.6

func Marshal

func Marshal(w io.Writer, msg proto.Message) (int64, error)

Marshal a proto.Message following a small header into an io.Writer. The header contains version(if msg is a VersionedMessage), header size and payload size.

It returns the number of written bytes and an error.

Since v0.1.6

func Size

func Size(msg proto.Message) int

Size returns the size of the header and the marshaled message.

Since 0.1.6

func Unmarshal

func Unmarshal(r io.Reader, msg proto.Message) (int64, string, error)

Unmarshal a header and following message form an io.Reader . It returns the number of read bytes, a version in string and an error.

Since 0.1.6

Types

type Header interface {
	GetVersion() string
	GetHeaderSize() int64
	GetBodySize() int64
}

Header defines header info retrieving APIs.

Since 0.1.7

func ReadHeader added in v0.1.7

func ReadHeader(r io.Reader) (int64, Header, error)

ReadHeader reads header info from a stream marshaled by this module. It returns number of bytes it has read, a Header interface for retreiving header info and an error. The number of bytes may be greater than 0 even if there is an error.

Since 0.1.7

type VersionedMessage

type VersionedMessage interface {
	GetVersion() string
	proto.Message
}

VersionedMessage must provide a "GetVersion" returning the version of a proto.Message . The version is a string in 16 bytes.

Since 0.1.6

Jump to

Keyboard shortcuts

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