codecs

package
v0.0.0-...-0969ca0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSupported is returned when an implement does not support
	// an operation.
	ErrNotSupported = errors.New("not supported")

	// ErrDecodeFailed is returned when decoding a byte slice into native type failed.
	ErrDecodeFailed = errors.New("failed to decode value")
)

errors ...

View Source
var (
	// ErrValueUnsettable is returned when the reflect.Value is not settable.
	ErrValueUnsettable = errors.New("value can not be set on reflect type")

	// ErrInvalidNoSize is returned when provided data slice fails to match length standard.
	ErrInvalidNoSize = errors.New("invalid data, byte slice must have length length")

	// ErrInvalidDataSlice is returned when provided data slice fails to match length standard.
	ErrInvalidDataSlice = errors.New("invalid data, byte slice not matching expected data frame length")

	// ErrNotList is returned when data slice provided is not a voxa.List type.
	ErrNotList = errors.New("data item is not a list")

	// ErrInvalidFieldID is returned when the field id does not match expected.
	ErrInvalidFieldID = errors.New("data id does not match expected field id")

	// ErrSkipErr is returned when codec is not available for a giving type.
	ErrSkipErr = errors.New("no codec available for type")
)

errors ...

View Source
var (
	// ErrNotRecord is returned when data slice provided is not a voxa.Record type.
	ErrNotRecord = errors.New("data item is not a Record")

	// ErrMustBePointer is returned when type to be unmarshalled to is a value.
	ErrMustBePointer = errors.New("destination must be a pointer of desired type")

	// ErrTagMustBeUniqueToField is returned when a tag id number is found in another field.
	ErrTagMustBeUniqueToField = errors.New("id tag number already used")

	// ErrUnknownType is returned when type cant be processed.
	ErrUnknownType = errors.New("type unknown")

	// ErrUnknownTypeForMap is returned when type cant be made for when creating a map.
	ErrUnknownTypeForMap = errors.New("type unsupported for maps")

	// ErrTagMustBeNumber is returned when a tag contains more than digit values.
	ErrTagMustBeNumber = errors.New("id tag must contain only digits")

	// ErrTagCantBeMoreThanUint8 is returned when a tag contains more the max values for a uint8.
	ErrTagCantBeMoreThanUint8 = errors.New("id tag numbers must be less or equal to a uint8 or 255")
)

Functions

func DecodeFloat32

func DecodeFloat32(f uint32) float32

DecodeFloat32 will decode provided uint64 value which should be in standard IEEE 754 binary representation, where it bit has been reversed, where having it's exponent appears first. It returns the float32 value.

func DecodeFloat64

func DecodeFloat64(f uint64) float64

DecodeFloat64 will decode provided uint64 value which should be in standard IEEE 754 binary representation, where it bit has been reversed, where having it's exponent appears first. It returns the float64 value.

func DecodeInt16FromBytes

func DecodeInt16FromBytes(b []byte) (int16, error)

DecodeInt16FromBytes attempts to decode provided byte slice into a int16 ensuring that it has minimum length of 2. It uses binary.BigEndian.

func DecodeInt32FromByte

func DecodeInt32FromByte(b []byte) (int32, error)

DecodeInt32FromBytes attempts to decode provided byte slice into a int32 ensuring that it has minimum length of 4. It uses binary.BigEndian.

func DecodeInt64FromBytes

func DecodeInt64FromBytes(b []byte) (int64, error)

DecodeInt64FromBytes attempts to decode provided byte slice into a int64 ensuring that it has minimum length of 8. It uses binary.BigEndian.

func DecodeUInt16

func DecodeUInt16(d []byte) uint16

DecodeUInt16 returns the decoded uint16 of provided byte slice which must be of length 2.

func DecodeUint16FromBytes

func DecodeUint16FromBytes(b []byte) (uint16, error)

DecodeUint16FromBytes attempts to decode provided byte slice into a uint16 ensuring that it has minimum length of 2. It uses binary.BigEndian.

func DecodeUint32FromBytes

func DecodeUint32FromBytes(b []byte) (uint32, error)

DecodeUint32FromBytes attempts to decode provided byte slice into a uint32 ensuring that it has minimum length of 4. It uses binary.BigEndian.

func DecodeUint64FromBytes

func DecodeUint64FromBytes(b []byte) (uint64, error)

DecodeUint64FromBytes attempts to decode provided byte slice into a uint64 ensuring that it has minimum length of 8. It uses binary.BigEndian.

func DecodeVarInt32

func DecodeVarInt32(b []byte) (uint32, int)

DecodeVarInt32 encodes uint32 into a byte slice using EncodeVarInt64 after turing uint32 into uin64.

func DecodeVarInt64

func DecodeVarInt64(buf []byte) (x uint64, n int)

DecodeVarInt64 reads a varint-encoded integer from the slice. It returns the integer and the number of bytes consumed, or zero if there is not enough. This is the format for the int32, int64, uint32, uint64, bool.

func EncodeFloat32

func EncodeFloat32(f float32) uint32

EncodeFloat64 will encode provided float value into the standard IEEE 754 binary representation and has it's bit reversed, having the exponent appearing first.

func EncodeFloat64

func EncodeFloat64(f float64) uint64

EncodeFloat64 will encode provided float value into the standard IEEE 754 binary representation and has it's bit reversed, having the exponent appearing first.

func EncodeInt32ToBytes

func EncodeInt32ToBytes(f int32, b []byte) error

EncodeInt32ToBytes encodes provided uint32 into provided byte ensuring byte slice has minimum of length 4. It uses binary.BigEndian.

func EncodeInt64ToBytes

func EncodeInt64ToBytes(f int64, b []byte) error

EncodeInt64ToBytes encodes provided uint64 into provided byte ensuring byte slice has minimum of length 8. It uses binary.BigEndian.

func EncodeUInt16

func EncodeUInt16(x uint16) []byte

EncodeUInt16 returns the encoded byte slice of a uint16 value.

func EncodeUint16ToBytes

func EncodeUint16ToBytes(f uint16, b []byte) error

EncodeUint16ToBytes encodes provided uint16 into provided byte ensuring byte slice has minimum of length 2. It uses binary.BigEndian.

func EncodeUint32ToBytes

func EncodeUint32ToBytes(f uint32, b []byte) error

EncodeUint32ToBytes encodes provided uint32 into provided byte ensuring byte slice has minimum of length 4. It uses binary.BigEndian.

func EncodeUint64ToBytes

func EncodeUint64ToBytes(f uint64, b []byte) error

EncodeUint64ToBytes encodes provided uint64 into provided byte ensuring byte slice has minimum of length 8. It uses binary.BigEndian.

func EncodeVarInt32

func EncodeVarInt32(x uint32) []byte

EncodeVarInt32 encodes uint32 into a byte slice using EncodeVarInt64 after turing uint32 into uin64.

func EncodeVarInt64

func EncodeVarInt64(x uint64) []byte

EncodeVarInt64 returns the varint encoding of x. This is the format for the int32, int64, uint32, uint64, bool, and enum.

Types

type AppendWriter

type AppendWriter struct {
	C []byte
}

AppendWriter implements io.Writer and writes all received data into a underline byte slice.

func (*AppendWriter) Write

func (aw *AppendWriter) Write(b []byte) (int, error)

type BooleanCodec

type BooleanCodec struct{}

func (BooleanCodec) BinaryToNative

func (BooleanCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (BooleanCodec) MarshalTextualToNative

func (BooleanCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (BooleanCodec) NativeToBinary

func (BooleanCodec) NativeToBinary(b interface{}, f voxa.FieldID, c []byte) ([]byte, error)

func (BooleanCodec) NativeToTextual

func (BooleanCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (BooleanCodec) TextualToNative

func (BooleanCodec) TextualToNative(b []byte) (interface{}, error)

type ByteCodec

type ByteCodec struct{}

func (ByteCodec) BinaryToNative

func (ByteCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (ByteCodec) NativeToBinary

func (ByteCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

type BytesCodec

type BytesCodec struct{}

func (BytesCodec) BinaryToNative

func (BytesCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (BytesCodec) MarshalTextualToNative

func (BytesCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (BytesCodec) NativeToBinary

func (BytesCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

func (BytesCodec) NativeToTextual

func (BytesCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (BytesCodec) TextualToNative

func (BytesCodec) TextualToNative(b []byte) (interface{}, error)

type FloatCodec

type FloatCodec struct{}

func (FloatCodec) BinaryToNative

func (FloatCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (FloatCodec) MarshalTextualToNative

func (FloatCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (FloatCodec) NativeToBinary

func (FloatCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

func (FloatCodec) NativeToTextual

func (FloatCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (FloatCodec) TextualToNative

func (FloatCodec) TextualToNative(b []byte) (interface{}, error)

type HeaderCodec

type HeaderCodec struct{}

HeaderCodec implements the voxa.HeaderCodec providing methods to turn giving field names and associated data into a byte slice with format: `[FieldID][Atom][Name Bytes...]` and vice-versa.

func (HeaderCodec) BinaryToField

func (HeaderCodec) BinaryToField(b []byte) (string, voxa.FieldID, voxa.Atom, error)

func (HeaderCodec) FieldToBinary

func (HeaderCodec) FieldToBinary(name string, id voxa.FieldID, ty voxa.Atom, b []byte) ([]byte, error)

type IntCodec

type IntCodec struct{}

func (IntCodec) BinaryToNative

func (IntCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (IntCodec) MarshalTextualToNative

func (IntCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (IntCodec) NativeToBinary

func (IntCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

func (IntCodec) NativeToTextual

func (IntCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (IntCodec) TextualToNative

func (IntCodec) TextualToNative(b []byte) (interface{}, error)

type ListCodec

type ListCodec struct{}

func (ListCodec) BinaryToNative

func (lc ListCodec) BinaryToNative(b []byte, target interface{}) (interface{}, error)

func (ListCodec) NativeToBinary

func (lc ListCodec) NativeToBinary(b interface{}, c []byte) ([]byte, error)

func (ListCodec) NativeToBinaryFrom

func (lc ListCodec) NativeToBinaryFrom(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

type RecordCodec

type RecordCodec struct{}

func (RecordCodec) BinaryToNative

func (lc RecordCodec) BinaryToNative(b []byte, target interface{}) error

func (RecordCodec) NativeToBinary

func (lc RecordCodec) NativeToBinary(b interface{}, c []byte) ([]byte, error)

func (RecordCodec) NativeToBinaryFrom

func (lc RecordCodec) NativeToBinaryFrom(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

type TextCodec

type TextCodec struct{}

func (TextCodec) BinaryToNative

func (TextCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (TextCodec) MarshalTextualToNative

func (TextCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (TextCodec) NativeToBinary

func (TextCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

func (TextCodec) NativeToTextual

func (TextCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (TextCodec) TextualToNative

func (TextCodec) TextualToNative(b []byte) (interface{}, error)

type TimeCodec

type TimeCodec struct{}

func (TimeCodec) BinaryToNative

func (TimeCodec) BinaryToNative(b []byte) (interface{}, voxa.FieldID, error)

func (TimeCodec) MarshalTextualToNative

func (TimeCodec) MarshalTextualToNative(_ []byte, _ interface{}) error

func (TimeCodec) NativeToBinary

func (TimeCodec) NativeToBinary(b interface{}, id voxa.FieldID, c []byte) ([]byte, error)

func (TimeCodec) NativeToTextual

func (TimeCodec) NativeToTextual(b interface{}, c []byte) ([]byte, error)

func (TimeCodec) TextualToNative

func (TimeCodec) TextualToNative(b []byte) (interface{}, error)

Jump to

Keyboard shortcuts

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