...

Package protodelim

import "google.golang.org/protobuf/encoding/protodelim"
Overview
Index

Overview ▾

Package protodelim marshals and unmarshals varint size-delimited messages.

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.

type MarshalOptions

MarshalOptions is a configurable varint size-delimited marshaler.

type MarshalOptions struct{ proto.MarshalOptions }

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

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

type Reader interface {
    io.Reader
    io.ByteReader
}

type SizeTooLargeError

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

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
}

func (*SizeTooLargeError) Error

func (e *SizeTooLargeError) Error() string

type UnmarshalOptions

UnmarshalOptions is a configurable varint size-delimited unmarshaler.

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
}

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.