postcard

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postcard encodes and decodes the Rust postcard wire format.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTrailingBytes is returned when Unmarshal does not consume all input.
	ErrTrailingBytes = errors.New("postcard: trailing bytes")
)

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal encodes v in postcard format.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal decodes postcard data into v.

Types

type Decoder

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

Decoder incrementally decodes postcard values.

func NewDecoder

func NewDecoder(b []byte) *Decoder

NewDecoder returns a decoder reading b.

func (*Decoder) Bool

func (d *Decoder) Bool() (bool, error)

Bool decodes a postcard bool.

func (*Decoder) BytesValue

func (d *Decoder) BytesValue() ([]byte, error)

BytesValue decodes a postcard byte sequence.

func (*Decoder) Decode

func (d *Decoder) Decode(v any) error

Decode decodes the next postcard value into v.

func (*Decoder) Done

func (d *Decoder) Done() bool

Done reports whether d consumed all input.

func (*Decoder) Int

func (d *Decoder) Int() (int64, error)

Int decodes a postcard signed integer.

func (*Decoder) RawBytes

func (d *Decoder) RawBytes(n int) ([]byte, error)

RawBytes decodes n bytes without a length prefix.

func (*Decoder) String

func (d *Decoder) String() (string, error)

String decodes a postcard string.

func (*Decoder) Uint

func (d *Decoder) Uint() (uint64, error)

Uint decodes a postcard unsigned integer.

type DecoderFrom

type DecoderFrom interface {
	DecodePostcard(*Decoder) error
}

DecoderFrom is implemented by values that decode themselves from d.

type Encoder

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

Encoder incrementally encodes postcard values.

func (*Encoder) Bool

func (e *Encoder) Bool(v bool)

Bool appends v as a postcard bool.

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns a copy of the encoded bytes.

func (*Encoder) BytesValue

func (e *Encoder) BytesValue(b []byte)

BytesValue appends b as a postcard byte sequence.

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

Encode appends v to e.

func (*Encoder) Int

func (e *Encoder) Int(v int64)

Int appends v as a postcard signed integer.

func (*Encoder) RawBytes

func (e *Encoder) RawBytes(b []byte)

RawBytes appends b without a length prefix.

func (*Encoder) String

func (e *Encoder) String(s string)

String appends s as a postcard string.

func (*Encoder) Uint

func (e *Encoder) Uint(v uint64)

Uint appends v as a postcard unsigned integer.

type EncoderTo

type EncoderTo interface {
	EncodePostcard(*Encoder) error
}

EncoderTo is implemented by values that encode themselves to e.

type Marshaler

type Marshaler interface {
	MarshalPostcard() ([]byte, error)
}

Marshaler is implemented by values with a custom postcard representation.

Jump to

Keyboard shortcuts

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