codecapi

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package codecapi is used by the codec package and by code generated by codec.GenerateFile. It should NOT be used directly.

Index

Constants

This section is empty.

Variables

View Source
var BuiltinTypes []reflect.Type

Functions

func Fail

func Fail(err error)

Fail aborts the current encoding or decoding with the given error. It never returns.

func Failf

func Failf(format string, args ...interface{})

Failf calls fmt.Errorf with the given arguments, then Fail. It never returns.

func Register

func Register(x interface{}, tc typeCodec)

Register records the type of x for use by Encoders and Decoders. All types subject to encoding must be registered, even builtin types.

Types

type DecodeOptions

type DecodeOptions struct {
	DisallowUnknownFields bool
}

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader, opts DecodeOptions) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(p interface{}) (err error)

Decode decodes a value encoded with Encoder.Encode and stores the result in the value pointed to by p. The decoded value must be assignable to the pointee's type; no conversions are performed. Decode returns io.EOF if there are no more values.

func (*Decoder) DecodeAny

func (d *Decoder) DecodeAny() interface{}

DecodeAny decodes a value encoded by EncodeAny.

func (*Decoder) DecodeBool

func (d *Decoder) DecodeBool() bool

DecodeBool decodes a bool.

func (*Decoder) DecodeByte

func (d *Decoder) DecodeByte() byte

func (*Decoder) DecodeBytes

func (d *Decoder) DecodeBytes() []byte

DecodeBytes decodes a byte slice. It makes a copy of a portion of the underlying buffer.

func (*Decoder) DecodeComplex

func (d *Decoder) DecodeComplex() complex128

DecodeComplex decodes a complex128.

func (*Decoder) DecodeFloat

func (d *Decoder) DecodeFloat() float64

DecodeFloat decodes a float64.

func (*Decoder) DecodeInt

func (d *Decoder) DecodeInt() int64

DecodeInt decodes a signed integer.

func (*Decoder) DecodeString

func (d *Decoder) DecodeString() string

DecodeString decodes a string.

func (*Decoder) DecodeUint

func (d *Decoder) DecodeUint() uint64

DecodeUint decodes a uint64.

func (*Decoder) NextStructField

func (d *Decoder) NextStructField() int

NextStructField should be called by a struct decoder in a loop. It returns the field number of the next encoded field, or -1 if there are no more fields.

func (*Decoder) StartList

func (d *Decoder) StartList() int

StartList should be called before decoding any sequence of variable-length values. It returns -1 if the encoded list was nil. Otherwise, it returns the length of the sequence.

func (*Decoder) StartPtr

func (d *Decoder) StartPtr() (bool, interface{})

StartPtr should be called before decoding a pointer. If the first return value is false, the destination should not be set. Otherwise, if the second return value is non-nil, assign it to the destination. Otherwise, proceed with decoding into the destination.

func (*Decoder) StartStruct

func (d *Decoder) StartStruct()

StartStruct should be called before decoding a struct.

func (*Decoder) StoreRef

func (d *Decoder) StoreRef(p interface{})

StoreRef should be called by a struct decoder immediately after it allocates a struct pointer.

func (*Decoder) UnknownField

func (d *Decoder) UnknownField(typeName string, num int)

UnknownField should be called by a struct decoder when it sees a field number that it doesn't know.

type EncodeOptions

type EncodeOptions struct {
	TrackPointers bool
	Buffer        []byte
}

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer, opts EncodeOptions) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(x interface{}) (err error)

Encode encodes x.

func (*Encoder) EncodeAny

func (e *Encoder) EncodeAny(x interface{})

EncodeAny encodes a Go type. The type must have been registered with Register.

func (*Encoder) EncodeBool

func (e *Encoder) EncodeBool(b bool)

EncodeBool encodes a bool.

func (*Encoder) EncodeByte

func (e *Encoder) EncodeByte(b byte)

func (*Encoder) EncodeBytes

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

EncodeBytes encodes a byte slice.

func (*Encoder) EncodeComplex

func (e *Encoder) EncodeComplex(c complex128)

EncodeComplex encodes a complex128.

func (*Encoder) EncodeFloat

func (e *Encoder) EncodeFloat(f float64)

EncodeFloat encodes a float64.

func (*Encoder) EncodeInt

func (e *Encoder) EncodeInt(i int64)

EncodeInt encodes a signed integer.

func (*Encoder) EncodeNil

func (e *Encoder) EncodeNil()

func (*Encoder) EncodeString

func (e *Encoder) EncodeString(s string)

EncodeString encodes a string.

func (*Encoder) EncodeUint

func (e *Encoder) EncodeUint(u uint64)

EncodeUint encodes a uint64.

func (*Encoder) EndStruct

func (e *Encoder) EndStruct()

EndStruct should be called after encoding a struct.

func (*Encoder) StartList

func (e *Encoder) StartList(len int)

StartList should be called before encoding any sequence of variable-length values.

func (*Encoder) StartPtr

func (e *Encoder) StartPtr(isNil bool, p interface{}) bool

StartPtr should be called before encoding a pointer. The isNil argument says whether the pointer is nil. The p argument is the pointer. If StartPtr returns false, encoding should not proceed.

func (*Encoder) StartStruct

func (e *Encoder) StartStruct()

Jump to

Keyboard shortcuts

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