codec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MultipleTagsTests = []func(c GeneralCodec, t testing.TB){
	TestMultipleTags,
}

Functions

func TestArray

func TestArray(codec GeneralCodec, t testing.TB)

Test marshalling an array

func TestArrayOfInterface

func TestArrayOfInterface(codec GeneralCodec, t testing.TB)

Test marshalling an array of interfaces

func TestBigArray

func TestBigArray(codec GeneralCodec, t testing.TB)

Test marshalling a really big array

func TestBool

func TestBool(codec GeneralCodec, t testing.TB)

Test marshalling a bool

func TestEmptySliceSerialization

func TestEmptySliceSerialization(codec GeneralCodec, t testing.TB)

Test marshaling a slice that has 0 elements (but isn't nil)

func TestExtraSpace

func TestExtraSpace(codec GeneralCodec, t testing.TB)

Test unmarshaling something with extra data

func TestInterface

func TestInterface(codec GeneralCodec, t testing.TB)

Test marshalling an interface

func TestMaxSizeSlice

func TestMaxSizeSlice(codec GeneralCodec, t testing.TB)

Test marshalling/unmarshalling largest possible slice

func TestMultipleTags

func TestMultipleTags(codec GeneralCodec, t testing.TB)

func TestNegativeNumbers

func TestNegativeNumbers(codec GeneralCodec, t testing.TB)

Ensure serializing structs with negative number members works

func TestNilSlice

func TestNilSlice(codec GeneralCodec, t testing.TB)

Ensure a nil slice is unmarshaled to slice with length 0

func TestNilSliceSerialization

func TestNilSliceSerialization(codec GeneralCodec, t testing.TB)

Test marshalling of nil slice

func TestPointerToInterface

func TestPointerToInterface(codec GeneralCodec, t testing.TB)

Test marshalling a pointer to an interface

func TestPointerToStruct

func TestPointerToStruct(codec GeneralCodec, t testing.TB)

Test marshalling a pointer to a struct

func TestRegisterStructTwice

func TestRegisterStructTwice(codec GeneralCodec, t testing.TB)

func TestRestrictedSlice

func TestRestrictedSlice(codec GeneralCodec, t testing.TB)

Ensure deserializing slices that have been length restricted errors correctly

func TestSerializeOfNoSerializeField

func TestSerializeOfNoSerializeField(codec GeneralCodec, t testing.TB)

func TestSerializeUnexportedField

func TestSerializeUnexportedField(codec GeneralCodec, t testing.TB)

Ensure that trying to serialize a struct with an unexported member that has `serialize:"true"` returns error

func TestSlice

func TestSlice(codec GeneralCodec, t testing.TB)

func TestSliceLengthOverflow

func TestSliceLengthOverflow(codec GeneralCodec, t testing.TB)

Ensure deserializing slices that have been length restricted errors correctly

func TestSliceOfInterface

func TestSliceOfInterface(codec GeneralCodec, t testing.TB)

Test marshalling a slice of interfaces

func TestSliceOfStruct

func TestSliceOfStruct(codec GeneralCodec, t testing.TB)

Test marshalling a slice of structs

func TestSliceTooLarge

func TestSliceTooLarge(codec GeneralCodec, t testing.TB)

func TestSliceWithEmptySerialization

func TestSliceWithEmptySerialization(codec GeneralCodec, t testing.TB)

Test marshaling slice that is not nil and not empty

func TestSliceWithEmptySerializationOutOfMemory

func TestSliceWithEmptySerializationOutOfMemory(codec GeneralCodec, t testing.TB)

func TestString

func TestString(codec GeneralCodec, t testing.TB)

Test marshalling a string

func TestStruct

func TestStruct(codec GeneralCodec, t testing.TB)

Test marshaling/unmarshaling a complicated struct

func TestTooLargeUnmarshal

func TestTooLargeUnmarshal(codec GeneralCodec, t testing.TB)

Ensure deserializing structs with too many bytes errors correctly

func TestUInt32

func TestUInt32(codec GeneralCodec, t testing.TB)

func TestUnmarshalInvalidInterface

func TestUnmarshalInvalidInterface(codec GeneralCodec, t testing.TB)

Ensure deserializing structs into the wrong interface errors gracefully

Types

type Codec

type Codec interface {
	MarshalInto(interface{}, *wrappers.Packer) error
	Unmarshal([]byte, interface{}) error
}

Codec marshals and unmarshals

type Foo

type Foo interface {
	Foo() int
}

type GeneralCodec

type GeneralCodec interface {
	Codec
	Registry
}

GeneralCodec marshals and unmarshals structs including interfaces

type Manager

type Manager interface {
	// Associate the given codec with the given version ID
	RegisterCodec(version uint16, codec Codec) error

	// Define the maximum size, in bytes, of something serialized/deserialized
	// by this codec manager
	SetMaxSize(int)

	// Marshal the given value using the codec with the given version.
	// RegisterCodec must have been called with that version.
	Marshal(version uint16, source interface{}) (destination []byte, err error)

	// Unmarshal the given bytes into the given destination. [destination] must
	// be a pointer or an interface. Returns the version of the codec that
	// produces the given bytes.
	Unmarshal(source []byte, destination interface{}) (version uint16, err error)
}

Manager describes the functionality for managing codec versions.

func NewDefaultManager

func NewDefaultManager() Manager

NewDefaultManager returns a new codec manager.

func NewManager

func NewManager(maxSize int) Manager

NewManager returns a new codec manager.

type MultipleVersionsStruct

type MultipleVersionsStruct struct {
	BothTags    string `tag1:"true" tag2:"true"`
	SingleTag1  string `tag1:"true"`
	SingleTag2  string `tag2:"true"`
	EitherTags1 string `tag1:"false" tag2:"true"`
	EitherTags2 string `tag1:"true" tag2:"false"`
	NoTags      string `tag1:"false" tag2:"false"`
}

type MyInnerStruct

type MyInnerStruct struct {
	Str string `serialize:"true"`
}

func (*MyInnerStruct) Foo

func (*MyInnerStruct) Foo() int

type MyInnerStruct2

type MyInnerStruct2 struct {
	Bool bool `serialize:"true"`
}

func (*MyInnerStruct2) Foo

func (*MyInnerStruct2) Foo() int

type MyInnerStruct3

type MyInnerStruct3 struct {
	Str string        `serialize:"true"`
	M1  MyInnerStruct `serialize:"true"`
	F   Foo           `serialize:"true"`
}

MyInnerStruct3 embeds Foo, an interface, so it has to implement TypeID and ConcreteInstance

type Registry

type Registry interface {
	RegisterType(interface{}) error
}

Registry registers new types that can be marshaled into

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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