# README
qcodec
qcodec encodes and decodes a primitive type or struct type with a predefined codec engine. It is simple thus very fast.
Install
go get github.com/openacid/qcodec
Synopsis
Build a SlimArray
package qcodec
import "fmt"
func Example() {
type Foo struct {
A int32
B int64
}
fmt.Println("uint32:", U32{}.Encode(uint32(0x0102)))
fmt.Println("uint16:", U16{}.Encode(uint16(0x0102)))
fmt.Println("dummy:", Dummy{}.Encode("dummy encodes anything to empty slice"))
// TypeCodec encodes any size fixed type.
fcodec, err := NewTypeCodec(Foo{})
_ = err
buf := fcodec.Encode(Foo{1, 2})
fmt.Println("Foo:", buf)
consumed, foo := fcodec.Decode(buf)
fmt.Println("decode Foo:", consumed, foo)
intCodec, err := NewTypeCodec(int(1))
_ = intCodec
fmt.Println("int:", err)
// Output:
// uint32: [2 1 0 0]
// uint16: [2 1]
// dummy: []
// Foo: [1 0 0 0 2 0 0 0 0 0 0 0]
// decode Foo: 12 {1 2}
// int: type: int: element type is not fixed size
}
# Packages
No description provided by the author
# Functions
No description provided by the author
CodecOf returns a `Codec` implementation for type `e`.
GetSliceEltCodec creates a `Codec` for type of element in slice `s`.
NewTypeCodec creates a *TypeCodec by a value.
NewTypeCodecByType creates a *TypeCodec for specified type and with a specified byte order.
# Variables
ErrNotFixedSize indicates the size of value of a type can not be determined by its type.
ErrNotSlice indicates it expects a slice type but not.
ErrUnknownEltType indicates a type this package does not support.
# Structs
Bytes converts a byte slice into fixed length slice.
Dummy converts anything to nothing.
I16 converts int16 to slice of 2 bytes and back.
I32 converts int32 to slice of 4 bytes and back.
I64 converts int64 to slice of 8 bytes and back.
I8 converts int8 to slice of 1 byte and back.
Int converts int to slice of bytes and back.
String16 converts uint16 to slice of 2 bytes and back.
TypeCodec provides encoding for fixed size types.
U16 converts uint16 to slice of 2 bytes and back.
U32 converts uint32 to slice of 4 bytes and back.
U64 converts uint64 to slice of 8 bytes and back.
U8 converts int8 to slice of 1 byte and back.
# Interfaces
A Codec converts one element between serialized byte stream and in-memory data structure.