Documentation ¶
Index ¶
- Variables
- func ConsumeHeader(r io.Reader, header []byte) (err error)
- func ConsumePath(r io.Reader, path []byte) (err error)
- func Header(path []byte) []byte
- func HeaderPath(hdr []byte) []byte
- func HeaderSafe(path []byte) ([]byte, error)
- func Marshal(c Codec, o interface{}) ([]byte, error)
- func MarshalTo(c Codec, w io.Writer, o interface{}) error
- func ReadHeader(r io.Reader) (path []byte, err error)
- func ReadPath(r io.Reader) (path []byte, err error)
- func Unmarshal(c Codec, buf []byte, o interface{}) error
- func UnmarshalFrom(c Codec, r io.Reader, o interface{}) error
- func WrapHeaderReader(hdr []byte, r io.Reader) io.Reader
- func WrapTransformPathToHeader(r io.Reader) (io.Reader, error)
- func WriteHeader(w io.Writer, path []byte) error
- type Codec
- type Decoder
- type Encoder
- type Multicodec
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ConsumeHeader ¶
ConsumeHeader reads a multicodec header from a reader, verifying it matches given header. If it does not, it returns ErrProtocolMismatch
func ConsumePath ¶
ConsumePath reads a multicodec header from a reader, verifying it matches given path. If it does not, it returns ErrProtocolMismatch
func HeaderPath ¶
HeaderPath returns the multicodec path from header
func HeaderSafe ¶
HeaderSafe works like Header but it returns error instead of calling panic
func ReadHeader ¶
ReadHeader reads a multicodec header from a reader. Returns the header found, or an error if the header mismatched.
func ReadPath ¶
ReadPath reads a multicodec header from a reader. Returns the path found, or an error if the header mismatched.
func UnmarshalFrom ¶
UnmarshalFrom deserializes an objects from a reader.
func WrapHeaderReader ¶
WrapHeaderReader returns a reader that first reads the given header, and then the given reader, using io.MultiReader. It is useful if the header has been read through, but still needed to pass to a decoder.
Types ¶
type Codec ¶
type Codec interface { // Decoder wraps given io.Reader and returns an object which // will decode bytes into objects. Decoder(r io.Reader) Decoder // Encoder wraps given io.Writer and returns an Encoder Encoder(w io.Writer) Encoder }
Codec is an algorithm for coding data from one representation to another. For convenience, we define a codec in the usual sense: a function and its inverse, to encode and decode.
type Decoder ¶
type Decoder interface {
Decode(n interface{}) error
}
Decoder decodes objects from bytes from an underlying io.Reader, into given object. Works like encoding.Unmarshal
type Encoder ¶
type Encoder interface {
Encode(n interface{}) error
}
Encoder encodes objects into bytes and writes them to an underlying io.Writer. Works like encoding.Marshal
type Multicodec ¶
Multicodec is the interface for a multicodec
func NewMulticodecFromCodec ¶
func NewMulticodecFromCodec(c Codec, header []byte) Multicodec