protodelim

package
v0.0.0-...-bb96f36 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package protodelim marshals and unmarshals varint size-delimited messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalTo

func MarshalTo(w io.Writer, m proto.Message) (int, error)

MarshalTo writes a varint size-delimited wire-format message to w with the default options.

See the documentation for MarshalOptions.MarshalTo.

func UnmarshalFrom

func UnmarshalFrom(r Reader, m proto.Message) error

UnmarshalFrom parses and consumes a varint size-delimited wire-format message from r with the default options. The provided message must be mutable (e.g., a non-nil pointer to a message).

See the documentation for UnmarshalOptions.UnmarshalFrom.

Types

type MarshalOptions

type MarshalOptions struct{ proto.MarshalOptions }

MarshalOptions is a configurable varint size-delimited marshaler.

func (MarshalOptions) MarshalTo

func (o MarshalOptions) MarshalTo(w io.Writer, m proto.Message) (int, error)

MarshalTo writes a varint size-delimited wire-format message to w. If w returns an error, MarshalTo returns it unchanged.

type Reader

type Reader interface {
	io.Reader
	io.ByteReader
}

Reader is the interface expected by UnmarshalFrom. It is implemented by *bufio.Reader.

type SizeTooLargeError

type SizeTooLargeError struct {
	// Size is the varint size of the message encountered
	// that was larger than the provided MaxSize.
	Size uint64

	// MaxSize is the MaxSize limit configured in UnmarshalOptions, which Size exceeded.
	MaxSize uint64
}

SizeTooLargeError is an error that is returned when the unmarshaler encounters a message size that is larger than its configured MaxSize.

func (*SizeTooLargeError) Error

func (e *SizeTooLargeError) Error() string

type UnmarshalOptions

type UnmarshalOptions struct {
	proto.UnmarshalOptions

	// MaxSize is the maximum size in wire-format bytes of a single message.
	// Unmarshaling a message larger than MaxSize will return an error.
	// A zero MaxSize will default to 4 MiB.
	// Setting MaxSize to -1 disables the limit.
	MaxSize int64
}

UnmarshalOptions is a configurable varint size-delimited unmarshaler.

func (UnmarshalOptions) UnmarshalFrom

func (o UnmarshalOptions) UnmarshalFrom(r Reader, m proto.Message) error

UnmarshalFrom parses and consumes a varint size-delimited wire-format message from r. The provided message must be mutable (e.g., a non-nil pointer to a message).

The error is io.EOF error only if no bytes are read. If an EOF happens after reading some but not all the bytes, UnmarshalFrom returns a non-io.EOF error. In particular if r returns a non-io.EOF error, UnmarshalFrom returns it unchanged, and if only a size is read with no subsequent message, io.ErrUnexpectedEOF is returned.

Jump to

Keyboard shortcuts

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