bintly

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

Bintly (super fast binary serialization for go)

GoReportCard GoDoc

This library is compatible with Go 1.11+

Please refer to CHANGELOG.md if you encounter breaking changes.

Motivation

The goal of library to provide super fast binary oriented decoding and encoding capability for any go data type, critical for low latency applications.

Introduction

Typical streamlined binary serialization format store primitive types with their native size, and all collection type got pre seeded with the repeated data size. Imagine the follow struct:

type Employee struct {
	ID int
	Name string
	RolesIDs []int
	Titles []string
    DeptIDs []int
}

var emp := Employee{
    ID: 100,
    Name: "test",
    RolesIDs: []int{1000,1002,1003},
    Titles: []string{"Lead", "Principal"},
    DeptIDs: []int{10,13},
}

This maps to the following binary stream representation:

100,4,test,3,1000,1002,1003,2,4,Lead,9,Principal,2,10,13

In examples presented coma got preserved only for visualisation, also numeric/alphanumerics usage is for simplification.

When decoding this binary format each repeated type requires new memory allocation, in this case 6 allocations: 3 for slices, and 3 for string type.

Since it's possible to copy any primitive slice to memory back and forth, we can go about binary serialization way faster than the originally presented approach. Instead of allocation memory for each repeated type (string,slice), we could simply reduce number allocation to number of primitive data type used + 1 to track allocations. In that case binary data stream for emp variable will look like the following.

alloc: [4,3,2,4,9,2] 
ints: [100,1000,1002,1003,10,13]
uint8s: [test,Lead,Principal]

The performance of this library comes by reducing memory allocation. In addition, all native data got copied to bytes back and forth without any conversion, improving additionally speed. Since there is no specific data conversion used, all serialized data uses native golang numeric data type representation.

Usage

func Example_Marshal() {
	emp := Employee{
		ID:       100,
		Name:     "test",
		RolesIDs: []int{1000, 1002, 1003},
		Titles:   []string{"Lead", "Principal"},
		DeptIDs:  []int{10, 13},
	}
	data, err := bintly.Marshal(emp)
	if err != nil {
		log.Fatal(err)
	}
	clone := Employee{}
	err = bintly.Unmarshal(data, &clone)
	if err != nil {
		log.Fatal(err)
	}
}
Custom encoding/decoding

To avoid reflection overhead you can define a custom encoder and decoder

Struct coder
//EncodeBinary encodes data from binary stream
func (e *Employee) EncodeBinary(stream *bintly.Writer) error {
	stream.Int(e.ID)
	stream.String(e.Name)
	stream.Ints(e.RolesIDs)
	stream.Strings(e.Titles)
	stream.Ints(e.DeptIDs)
	return nil
}

//DecodeBinary decodes data to binary stream
func (e *Employee) DecodeBinary(stream *bintly.Reader) error {
	stream.Int(&e.ID)
	stream.String(&e.Name)
	stream.Ints(&e.RolesIDs)
	stream.Strings(&e.Titles)
	stream.Ints(&e.DeptIDs)
	return nil
}
Slice coder
type Employees []*Employee

func (e *Employees) DecodeBinary(stream *bintly.Reader) error {
	size := int(stream.Alloc())
	if size == bintly.NilSize {
		return nil
	}
	for i := 0;i< size;i++ {
		if err := stream.Any((*e)[i]);err != nil {
			return err
		}
	}
	return nil
}

func (e *Employees) EncodeBinary(stream *bintly.Writer) error {
	if *e == nil {
		stream.Alloc(bintly.NilSize)
		return nil
	}
	stream.Alloc(int32(len(*e)))
	for i := range *e {
		if err := stream.Any((*e)[i]);err != nil {
			return nil
		}
	}	
	return nil
}

func Example_Slice_Unmarshal() {
    emps := Employees{
		{
			ID:       1,
			Name:     "test 1",
			RolesIDs: []int{1000, 1002, 1003},
			Titles:   []string{"Lead", "Principal"},
			DeptIDs:  []int{10, 13},
		},
		{
			ID:       2,
			Name:     "test 2",
			RolesIDs: []int{1000, 1002, 1003},
			Titles:   []string{"Lead", "Principal"},
			DeptIDs:  []int{10, 13},
		},
	}
	
	data, err := bintly.Marshal(&emps) //pass pointer to the slice
	if err != nil {
		log.Fatal(err)
	}
	var clone Employees
	err = bintly.Unmarshal(data, &clone)
	if err != nil {
		log.Fatal(err)
	}
Map coder
type EmployeesMap map[int]Employee

func (e *EmployeesMap) DecodeBinary(stream *bintly.Reader) error {
	size := int(stream.Alloc())
	if size == bintly.NilSize {
		return nil
	}
	*e = make(map[int]Employee, size)
	for i := 0; i < size; i++ {
		var k string
		var v Employee
		if err := stream.Any(&k); err != nil {
			return err
		}
		if err := stream.Any(&v); err != nil {
			return err
		}
	}
	return nil
}

func (e *EmployeesMap) EncodeBinary(stream *bintly.Writer) error {
	if *e == nil {
		stream.Alloc(bintly.NilSize)
		return nil
	}
	stream.Alloc(int32(len(*e)))
	for k, v := range *e {
		if err := stream.Any(k); err != nil {
			return nil
		}
		if err := stream.Any(v); err != nil {
			return nil
		}
	}
	return nil
}

func Example_Map_Unmarshal() {
	emps := EmployeesMap{
		1:{
			ID:       1,
			Name:     "test 1",
			RolesIDs: []int{1000, 1002, 1003},
			Titles:   []string{"Lead", "Principal"},
			DeptIDs:  []int{10, 13},
		},
		2:{
			ID:       2,
			Name:     "test 2",
			RolesIDs: []int{1000, 1002, 1003},
			Titles:   []string{"Lead", "Principal"},
			DeptIDs:  []int{10, 13},
		},
	}
	data, err := bintly.Marshal(&emps) //pass pointer to the map
	if err != nil {
		log.Fatal(err)
	}
	var clone EmployeesMap
	err = bintly.Unmarshal(data, &clone)
	if err != nil {
		log.Fatal(err)
	}
}

###Auto Code Generation The package provides CLI options to generate bintly encoding/decoding to make conversion effortless. For instance , the following command generates encode/decode for a type "Message" defined in the file "message.go" to produce "message_enc.go" in the same directory

./gen -s "/Users/xxx/github.com/viant/bintly/codegen/test_data/slices/message.go" -t "Message"

Options :

    -s : Source file location (required)
    -t : Type (required)
    -d : Destination file directory (optional - if not provided output is produced in same directory as source)

####Examples

Basic Types

Input : message.go

package basic_struct

type Message struct {
	A1 int
	B1 *string
	C1 []string
}

Cmd:

gen -s "message.go" -t "Message" 

Output : message_enc.go

package basic_struct

import (
	"github.com/viant/bintly"
)
func (m *Message) EncodeBinary(coder *bintly.Writer) error {
	coder.Int(m.A1)
	coder.StringPtr(m.B1)
	coder.Strings(m.C1)
	return nil
}
func (m *Message) DecodeBinary(coder *bintly.Reader) error {
	coder.Int(&m.A1)
	coder.StringPtr(&m.B1)
	coder.Strings(&m.C1)	
	return nil
}

Slice Types

Input:

package slices

type SubMessage struct {
	Id   int
	Name string
}

type Message struct {
	M1 []SubMessage
}

Output :

package slices

import (
	"github.com/viant/bintly"
)

func (s *SubMessage) EncodeBinary(coder *bintly.Writer) error {
	coder.Int(s.Id)
	coder.String(s.Name)
	return nil
}

func (s *SubMessage) DecodeBinary(coder *bintly.Reader) error {
	coder.Int(&s.Id)
	coder.String(&s.Name)	
	return nil
}

func (m *Message) EncodeBinary(coder *bintly.Writer) error {
	var m1 = len(m.M1)
	coder.Alloc(int32(m1))
	for i:=0; i < m1 ; i++ {
		if err := coder.Coder(&m.M1[i]);err !=nil {
			return nil
		}
	}
	return nil
}

func (m *Message) DecodeBinary(coder *bintly.Reader) error {
	var m1 = coder.Alloc()
	m.M1 = make([]SubMessage,m1)
	for i:=0; i < int(m1) ; i++ {
		if err := coder.Coder(&m.M1[i]);err != nil {
			return nil
		}
	}	
	return nil
}
Map Types

Input:

package maps

type SubMessage struct {
	Id   int
	Name string
}


type M1 map[string][]*SubMessage

type Message struct {
	 M1
}

Output :

package maps

import (
	"github.com/viant/bintly"
)

func (s *SubMessage) EncodeBinary(coder *bintly.Writer) error {
	coder.Int(s.Id)
	coder.String(s.Name)
	return nil
}
func (s *SubMessage) DecodeBinary(coder *bintly.Reader) error {
	coder.Int(&s.Id)
	coder.String(&s.Name)
	return nil
}

func (m *Message) EncodeBinary(coder *bintly.Writer) error {
	coder.Alloc(int32(len(m.M1)))
	for k, v := range m.M1 {
		coder.String(k)
		var m1 = len(v)
		coder.Alloc(int32(m1))
		for i := 0; i < m1; i++ {
			if err := coder.Coder(v[i]); err != nil {
				return nil
			}
		}
	}
	return nil
}
func (m *Message) DecodeBinary(coder *bintly.Reader) error {
	size := int(coder.Alloc())
	if size == bintly.NilSize {
		return nil
	}
	m.M1 = make(map[string][]*SubMessage, size)
	for i := 0; i < size; i++ {
		var k string
		var v []*SubMessage
		coder.String(&k)
		var m1Size = coder.Alloc()
		v = make([]*SubMessage, m1Size)
		for j := 0; j < int(m1Size); j++ {
			v[j] = &SubMessage{}
			if err := coder.Coder(v[j]); err != nil {
				return nil
			}
		}
		m.M1[k] = v
	}
	return nil
}

Bugs

This package uses architecture dependent encoding (native go representation). User of the package should ensure that it is compatible with the needed platforms and architectures.

Benchmark

Benchmark uses BenchStruct where slices got populated with 80 random items.

BenchmarkUnmarshalBintly
BenchmarkUnmarshalBintly-16           	  940587	      1263 ns/op	    3762 B/op	       6 allocs/op
BenchmarkMarshalBintly
BenchmarkMarshalBintly-16             	  856911	      1202 ns/op	    2484 B/op	       3 allocs/op
BenchmarkUnmarshalBintlyReflect
BenchmarkUnmarshalBintlyReflect-16    	  675956	      1675 ns/op	    3796 B/op	       7 allocs/op
BenchmarkMarshalBintlyReflect
BenchmarkMarshalBintlyReflect-16      	  580586	      1784 ns/op	    2507 B/op	      10 allocs/op
BenchmarkUnmarshalBinary
BenchmarkUnmarshalBinary-16           	  365941	      3306 ns/op	    3152 B/op	      73 allocs/op
BenchmarkMarshalBinary
BenchmarkMarshalBinary-16             	  239450	      4868 ns/op	    4536 B/op	       7 allocs/op
BenchmarkUnMarshalGob
BenchmarkUnMarshalGob-16              	   46789	     25958 ns/op	   13928 B/op	     317 allocs/op
BenchmarkMarshalGob
BenchmarkMarshalGob-16                	   96601	     10510 ns/op	    9956 B/op	      36 allocs/op
BenchmarkUnmarshalCbor
BenchmarkUnmarshalCbor-16             	  109017	     11655 ns/op	    3488 B/op	      79 allocs/op
BenchmarkMarshalCbor
BenchmarkMarshalCbor-16               	  216528	      5453 ns/op	    2194 B/op	       2 allocs/op
BenchmarkUnmarshalMsgPack
BenchmarkUnmarshalMsgPack-16          	   69460	     17462 ns/op	    4899 B/op	      84 allocs/op
BenchmarkMarshalMsgPack
BenchmarkMarshalMsgPack-16            	   99207	     12255 ns/op	    4722 B/op	       8 allocs/op
BenchmarkJSONUnmarshal
BenchmarkJSONUnmarshal-16             	   18126	     72414 ns/op	   15488 B/op	     308 allocs/op
BenchmarkJSONMarshal
BenchmarkJSONMarshal-16               	   52039	     21745 ns/op	    4359 B/op	       3 allocs/op

License

The source code is made available under the terms of the Apache License, Version 2, as stated in the file LICENSE.

Individual files may be made available under their own specific license, all compatible with Apache License, Version 2. Please see individual files for details.

Contributing to Bintly

Bintly is an open source project and contributors are welcome!

See TODO list

Credits and Acknowledgements

Library Author: Adrian Witas

Documentation

Overview

Package bintly defines binary coding and encoding using native golang numeric data type representation.

Index

Constants

View Source
const (

	//represents nil size
	NilSize = -1
)

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, coder Decoder) error

Decode converts []byte to decoder or error

func Encode

func Encode(coder Encoder) ([]byte, error)

Encode converts encoder into []byte, or error

func Float32

func Float32(b []byte) float32

Float32 copy []byte to float32

func Float64

func Float64(b []byte) float64

Float64 copy []byte to float64

func GetFloat32s

func GetFloat32s(bs []byte, vs []float32)

GetFloat32s copy []byte into []float32

func GetFloat64s

func GetFloat64s(bs []byte, vs []float64)

GetFloat64s copy []byte into []float64

func GetInt

func GetInt(b []byte, v *int)

GetInt copy []byte to int

func GetInt16

func GetInt16(b []byte, v *int16)

GetInt16 copy []byte to *int16

func GetInt16s

func GetInt16s(bs []byte, vs []int16)

GetInt16s copy []byte into []int16

func GetInt32

func GetInt32(b []byte, v *int32)

GetInt32 copy []byte to *int32

func GetInt32s

func GetInt32s(bs []byte, vs []int32)

GetInt32s copy []byte into []int32

func GetInt64

func GetInt64(b []byte, v *int64)

GetInt64 copy []byte to int64

func GetInt64s

func GetInt64s(bs []byte, vs []int64)

GetInt64s copy []byte into []int64

func GetInt8s

func GetInt8s(bs []byte, vs []int8)

GetInt8s copy []byte into []int8

func GetInts

func GetInts(bs []byte, vs []int)

GetInts copy []byte into []int

func GetUint

func GetUint(b []byte, v *uint)

GetUint copy []byte to uint

func GetUint16

func GetUint16(b []byte, v *uint16)

GetUint16 copy []byte to *uint16

func GetUint16s

func GetUint16s(bs []byte, vs []uint16)

GetUint16s copy []byte into []uint16

func GetUint32

func GetUint32(b []byte, v *uint32)

GetUint32 copy []byte to *uint32

func GetUint32s

func GetUint32s(bs []byte, vs []uint32)

GetUint32s copy []byte into []uint32

func GetUint64

func GetUint64(b []byte, v *uint64)

GetUint64 copy []byte to *uint64

func GetUint64s

func GetUint64s(bs []byte, vs []uint64)

GetUint64s copy []byte into []uint64

func GetUint8s

func GetUint8s(bs []byte, vs []uint8)

GetUint8s copy []byte into []uint8

func GetUints

func GetUints(bs []byte, vs []uint)

GetUints copy []byte into []uint

func Int

func Int(b []byte) int

Int copy []byte to int

func Int16

func Int16(b []byte) int16

Int16 copy []byte to int16

func Int16s

func Int16s(bs []byte) []int16

Int16s copy []byte into []int16

func Int32

func Int32(b []byte) int32

Int32 copy []byte to int32

func Int32s

func Int32s(bs []byte) []int32

Int32s copy []byte into []int32

func Int64

func Int64(b []byte) int64

Int64 copy []byte to int64

func Int64s

func Int64s(bs []byte) []int64

Int64s copy []byte into []int64

func Int8s

func Int8s(bs []byte) []int8

Int8s copy []byte into []int8

func Ints

func Ints(bs []byte) []int

Ints copy []byte into []int

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal converts e into []byte, or error

func MarshalStream

func MarshalStream(stream *Writer, v interface{}) ([]byte, error)

MarshalStream converts e into []byte, or error

func PutFloat32

func PutFloat32(dest []byte, v float32)

PutFloat32 copy float32 into []byte

func PutFloat32s

func PutFloat32s(bs []byte, vs []float32)

PutFloat32s copy []float32 into []byte

func PutFloat64

func PutFloat64(dest []byte, v float64)

PutFloat64 copy float64 into []byte

func PutFloat64s

func PutFloat64s(bs []byte, vs []float64)

PutFloat64s copy []float64 into []byte

func PutInt

func PutInt(dest []byte, v int)

PutInt copy int into []byte

func PutInt16

func PutInt16(dest []byte, v int16)

PutInt16 copy int16 into []byte

func PutInt16s

func PutInt16s(bs []byte, vs []int16)

PutInt16s copy []int16 into []byte

func PutInt32

func PutInt32(dest []byte, v int32)

PutInt32 copy int32 into []byte

func PutInt32s

func PutInt32s(bs []byte, vs []int32)

PutInt32s copy []int32 into []byte

func PutInt64

func PutInt64(dest []byte, v int64)

PutInt64 copy int64 into []byte

func PutInt64s

func PutInt64s(bs []byte, vs []int64)

PutInt64s copy []int64 into []byte

func PutInt8s

func PutInt8s(bs []byte, vs []int8)

PutInt8s copy []int8 into []byte

func PutInts

func PutInts(bs []byte, vs []int)

PutInts copy []int into []byte

func PutUint

func PutUint(dest []byte, v uint)

PutUint copy uint into []byte

func PutUint16

func PutUint16(dest []byte, v uint16)

PutUint16 copy uint16 into []byte

func PutUint16s

func PutUint16s(bs []byte, vs []uint16)

PutUint16s copy []uint16 into []byte

func PutUint32

func PutUint32(dest []byte, v uint32)

PutUint32 copy uint32 into []byte

func PutUint32s

func PutUint32s(bs []byte, vs []uint32)

PutUint32s copy []uint32 into []byte

func PutUint64

func PutUint64(dest []byte, v uint64)

PutUint64 copy uint64 into []byte

func PutUint64s

func PutUint64s(bs []byte, vs []uint64)

PutUint64s copy []uint64 into []byte

func PutUint8s

func PutUint8s(bs []byte, vs []uint8)

PutUint8s copy []uint8 into []byte

func PutUints

func PutUints(bs []byte, vs []uint)

PutUints copy []uint into []byte

func Uint

func Uint(b []byte) uint

Uint copy []byte to uint

func Uint16

func Uint16(b []byte) uint16

Uint16 copy []byte to uint16

func Uint16s

func Uint16s(bs []byte) []uint16

Uint16s copy []byte into []uint16

func Uint32

func Uint32(b []byte) uint32

Uint32 copy []byte to uint32

func Uint32s

func Uint32s(bs []byte) []uint32

Uint32s copy []byte into []uint32

func Uint64

func Uint64(b []byte) uint64

Uint64 copy []byte to uint64

func Uint64s

func Uint64s(bs []byte) []uint64

Uint64s copy []byte into []uint64

func Uint8s

func Uint8s(bs []byte) []uint8

Uint8s copy []byte into []uint8

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal converts []byte to e pointer or error

func UnmarshalStream

func UnmarshalStream(stream *Reader, data []byte, v interface{}) error

UnmarshalStream converts []byte to e pointer or error

Types

type Alloc

type Alloc interface {
	//Alloc returns size of repeated type
	Alloc() int32
}

Alloc represents repeated type allocator

type Allocator

type Allocator interface {
	SetAlloc(allocation int32)
}

Allocator represents repeated type allocator

type Decoder

type Decoder interface {
	DecodeBinary(stream *Reader) error
}

Decoder represents a decoder interface

type Encoder

type Encoder interface {
	//EncodeBinary writes data to the stream
	EncodeBinary(stream *Writer) error
}

Encoder defines an encoder interface

type Reader

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

Reader represents binary readers

func (*Reader) Alloc

func (r *Reader) Alloc() int32

Alloc shifts allocation size (for repeated or pointers(nil:0,1))

func (*Reader) Any

func (r *Reader) Any(v interface{}) error

Any returns value into source pointer, source has to be a pointer

func (*Reader) Bool

func (r *Reader) Bool(v *bool)

Bool reads into *bool

func (*Reader) BoolPtr

func (r *Reader) BoolPtr(v **bool)

BoolPtr reads into **bool

func (*Reader) Bools

func (r *Reader) Bools(vs *[]bool)

Bools reads into *[]bool

func (*Reader) Coder

func (r *Reader) Coder(coder Decoder) error

Coder decodes coder

func (*Reader) Float32

func (r *Reader) Float32(v *float32)

Float32 reads into *float32

func (*Reader) Float32Ptr

func (r *Reader) Float32Ptr(v **float32)

Float32Ptr reads into **float32

func (*Reader) Float32s

func (r *Reader) Float32s(vs *[]float32)

Float32s reads into *[]float32

func (*Reader) Float64

func (r *Reader) Float64(v *float64)

Float64 reads into *float64

func (*Reader) Float64Ptr

func (r *Reader) Float64Ptr(v **float64)

Float64Ptr reads into **float64

func (*Reader) Float64s

func (r *Reader) Float64s(vs *[]float64)

Float64s reads into *[]float64

func (*Reader) FromBytes

func (r *Reader) FromBytes(data []byte) error

FromBytes loads stream from bytes

func (*Reader) Int

func (r *Reader) Int(v *int)

Int reads into *int

func (*Reader) Int16

func (r *Reader) Int16(v *int16)

Int16 reads into *int16

func (*Reader) Int16Ptr

func (r *Reader) Int16Ptr(v **int16)

Int16Ptr reads into **int16

func (*Reader) Int16s

func (r *Reader) Int16s(vs *[]int16)

Int16s reads into *[]int16

func (*Reader) Int32

func (r *Reader) Int32(v *int32)

Int32 reads into *int32

func (*Reader) Int32Ptr

func (r *Reader) Int32Ptr(v **int32)

Int32Ptr reads into **int32

func (*Reader) Int32s

func (r *Reader) Int32s(vs *[]int32)

Int32s reads into *[]int32

func (*Reader) Int64

func (r *Reader) Int64(v *int64)

Int64 reads into *int64

func (*Reader) Int64Ptr

func (r *Reader) Int64Ptr(v **int64)

Int64Ptr reads into **int64

func (*Reader) Int64s

func (r *Reader) Int64s(vs *[]int64)

Int64s reads into *[]int64

func (*Reader) Int8

func (r *Reader) Int8(v *int8)

Int8 reads into *int8

func (*Reader) Int8Ptr

func (r *Reader) Int8Ptr(v **int8)

Int8Ptr reads into **int8

func (*Reader) Int8s

func (r *Reader) Int8s(vs *[]int8)

Int8s reads into *[]int8

func (*Reader) IntPtr

func (r *Reader) IntPtr(v **int)

IntPtr reads into **int

func (*Reader) Ints

func (r *Reader) Ints(vs *[]int)

Ints reads into *[]int

func (*Reader) MAlloc

func (r *Reader) MAlloc() uint16

MAlloc shifts allocation size (for repeated or pointers(nil:0,1))

func (*Reader) MInt32s

func (r *Reader) MInt32s(vs *[]int32)

MInt32s reads into *[]int32

func (*Reader) MInt64s

func (r *Reader) MInt64s(vs *[]int64)

MInt64s reads into *[]int64

func (*Reader) MInts

func (r *Reader) MInts(vs *[]int)

MInts reads medium size slice into *[]int

func (*Reader) MString

func (r *Reader) MString(v *string)

MString reads into *string

func (*Reader) MStringPtr

func (r *Reader) MStringPtr(v **string)

MStringPtr reads into **string

func (*Reader) MStrings

func (r *Reader) MStrings(v *[]string)

MStrings reads into *[]string

func (*Reader) MUint32s

func (r *Reader) MUint32s(vs *[]uint32)

Uint32s reads into *[]uint32

func (*Reader) MUint64s

func (r *Reader) MUint64s(vs *[]uint64)

MUint64s reads into *[]uint64

func (*Reader) MUint8s

func (r *Reader) MUint8s(vs *[]uint8)

MUint8s reads medium size slice (64k) into *[]uint8

func (*Reader) MUints

func (r *Reader) MUints(vs *[]uint)

MUints reads into *[]uint

func (*Reader) String

func (r *Reader) String(v *string)

String reads into *string

func (*Reader) StringPtr

func (r *Reader) StringPtr(v **string)

StringPtr reads into **string

func (*Reader) Strings

func (r *Reader) Strings(v *[]string)

Strings reads into *[]string

func (*Reader) Time

func (r *Reader) Time(v *time.Time)

Time reads into *time.Time

func (*Reader) TimePtr

func (r *Reader) TimePtr(v **time.Time)

TimePtr reads into **time.Time

func (*Reader) Uint

func (r *Reader) Uint(v *uint)

Uint reads into *uint

func (*Reader) Uint16

func (r *Reader) Uint16(v *uint16)

Uint16 reads into *uint16

func (*Reader) Uint16Ptr

func (r *Reader) Uint16Ptr(v **uint16)

Uint16Ptr reads into **uint16

func (*Reader) Uint16s

func (r *Reader) Uint16s(vs *[]uint16)

Uint16s read into *[]uint16

func (*Reader) Uint32

func (r *Reader) Uint32(v *uint32)

Uint32 reads into *uint32

func (*Reader) Uint32Ptr

func (r *Reader) Uint32Ptr(v **uint32)

Uint32Ptr reads into **uint32

func (*Reader) Uint32s

func (r *Reader) Uint32s(vs *[]uint32)

Uint32s reads into *[]uint32

func (*Reader) Uint64

func (r *Reader) Uint64(v *uint64)

Uint64 reads into *uint64

func (*Reader) Uint64Ptr

func (r *Reader) Uint64Ptr(v **uint64)

Uint64Ptr reads into **uint64

func (*Reader) Uint64s

func (r *Reader) Uint64s(vs *[]uint64)

Uint64s reads into *[]uint64

func (*Reader) Uint8

func (r *Reader) Uint8(v *uint8)

Uint8 reads into *uint8

func (*Reader) Uint8Ptr

func (r *Reader) Uint8Ptr(v **uint8)

Uint8Ptr reads into **uint8

func (*Reader) Uint8s

func (r *Reader) Uint8s(vs *[]uint8)

Uint8s reads into *[]uint8

func (*Reader) UintPtr

func (r *Reader) UintPtr(v **uint)

UintPtr reads into **uint

func (*Reader) Uints

func (r *Reader) Uints(vs *[]uint)

Uints reads into *[]uint

type Readers

type Readers struct {
	sync.Pool
}

Readers represents readers pool

func NewReaders

func NewReaders() *Readers

NewReaders creates a readers pool

func (*Readers) Get

func (p *Readers) Get() *Reader

Get returns a readers

type Writer

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

Writer represents binary writer

func (*Writer) Alloc

func (w *Writer) Alloc(size int32)

Alloc append data allocation size for repeater or pointers(0,1) types

func (*Writer) Any

func (w *Writer) Any(v interface{}) error

Any writes any supported writer type

func (*Writer) Bool

func (w *Writer) Bool(v bool)

Bool writes bool

func (*Writer) BoolPtr

func (w *Writer) BoolPtr(v *bool)

BoolPtr writes *bool

func (*Writer) Bools

func (w *Writer) Bools(vs []bool)

Bools writes []bool

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns writer bytes and resets stream

func (*Writer) Coder

func (w *Writer) Coder(v Encoder) error

Coder encodes data with encoder

func (*Writer) Float32

func (s *Writer) Float32(v float32)

Float32 writes float32

func (*Writer) Float32Ptr

func (w *Writer) Float32Ptr(v *float32)

Float32Ptr writes *float32

func (*Writer) Float32s

func (w *Writer) Float32s(vs []float32)

Float32s writes []float32

func (*Writer) Float64

func (s *Writer) Float64(v float64)

Float64 float64

func (*Writer) Float64Ptr

func (w *Writer) Float64Ptr(v *float64)

Float64Ptr writes *float64

func (*Writer) Float64s

func (w *Writer) Float64s(vs []float64)

Float64s writes []float64

func (*Writer) Int

func (s *Writer) Int(v int)

Int writes int

func (*Writer) Int16

func (s *Writer) Int16(v int16)

Int16 writes int16

func (*Writer) Int16Ptr

func (w *Writer) Int16Ptr(v *int16)

Int16Ptr writes *int16

func (*Writer) Int16s

func (w *Writer) Int16s(vs []int16)

Int16s writes []int16

func (*Writer) Int32

func (s *Writer) Int32(v int32)

Int32 writes int32

func (*Writer) Int32Ptr

func (w *Writer) Int32Ptr(v *int32)

Int32Ptr writes *int32

func (*Writer) Int32s

func (w *Writer) Int32s(vs []int32)

Int32s writes []int32

func (*Writer) Int64

func (s *Writer) Int64(v int64)

Int64 writes int64

func (*Writer) Int64Ptr

func (w *Writer) Int64Ptr(v *int64)

Int64Ptr writes *int64

func (*Writer) Int64s

func (w *Writer) Int64s(vs []int64)

Int64s writes []int64

func (*Writer) Int8

func (s *Writer) Int8(v int8)

Int8 writes int8

func (*Writer) Int8Ptr

func (w *Writer) Int8Ptr(v *int8)

Int8Ptr writes *int8

func (*Writer) Int8s

func (w *Writer) Int8s(vs []int8)

Int8s writes []int8

func (*Writer) IntPtr

func (w *Writer) IntPtr(v *int)

IntPtr writes *int

func (*Writer) Ints

func (w *Writer) Ints(vs []int)

Ints writes []int

func (*Writer) MAlloc

func (w *Writer) MAlloc(size uint16)

Alloc append data allocation size for repeater or pointers(0,1) types

func (*Writer) MInt32s

func (w *Writer) MInt32s(vs []int32)

MInt32s writes []int32

func (*Writer) MInt64s

func (w *Writer) MInt64s(vs []int64)

MInt64s writes []int64

func (*Writer) MInts

func (w *Writer) MInts(vs []int)

MInts writes medium size slice []int

func (*Writer) MString

func (w *Writer) MString(v string)

MString writes a medium (64k) string

func (*Writer) MStringPtr

func (w *Writer) MStringPtr(v *string)

MStringPtr writes medium *string

func (*Writer) MStrings

func (w *Writer) MStrings(v []string)

MStrings writes medium size (64k) []string

func (*Writer) MUint32s

func (w *Writer) MUint32s(vs []uint32)

MUint32s writes medium size slice (upto 64k) []uint32

func (*Writer) MUint64s

func (w *Writer) MUint64s(vs []uint64)

MUint64s writes []uint64

func (*Writer) MUint8s

func (w *Writer) MUint8s(vs []uint8)

MUint8s writes medium (upto 64k) []uint8

func (*Writer) MUints

func (w *Writer) MUints(vs []uint)

MUints writes []uint

func (*Writer) Size

func (w *Writer) Size() int

Size returns data size

func (*Writer) String

func (w *Writer) String(v string)

String writes string

func (*Writer) StringPtr

func (w *Writer) StringPtr(v *string)

StringPtr writes *string

func (*Writer) Strings

func (w *Writer) Strings(v []string)

Strings writes []string

func (*Writer) Time

func (w *Writer) Time(v time.Time)

Time writes time.Time

func (*Writer) TimePtr

func (w *Writer) TimePtr(v *time.Time)

TimePtr writes *time.Time

func (*Writer) Uint

func (s *Writer) Uint(v uint)

Uint writes uint

func (*Writer) Uint16

func (s *Writer) Uint16(v uint16)

Uint16 writes uint16

func (*Writer) Uint16Ptr

func (w *Writer) Uint16Ptr(v *uint16)

Uint16Ptr writes *uint16

func (*Writer) Uint16s

func (w *Writer) Uint16s(vs []uint16)

Uint16s writes []uint16

func (*Writer) Uint32

func (s *Writer) Uint32(v uint32)

Uint32 writes uint32

func (*Writer) Uint32Ptr

func (w *Writer) Uint32Ptr(v *uint32)

Uint32Ptr writes *uint32

func (*Writer) Uint32s

func (w *Writer) Uint32s(vs []uint32)

Uint32s writes []uint32

func (*Writer) Uint64

func (s *Writer) Uint64(v uint64)

Uint64 write uint64

func (*Writer) Uint64Ptr

func (w *Writer) Uint64Ptr(v *uint64)

Uint64Ptr writes *uint64

func (*Writer) Uint64s

func (w *Writer) Uint64s(vs []uint64)

Uint64s writes []uint64

func (*Writer) Uint8

func (s *Writer) Uint8(v uint8)

Uint8 uint8

func (*Writer) Uint8Ptr

func (w *Writer) Uint8Ptr(v *uint8)

Uint8Ptr writes *uint8

func (*Writer) Uint8s

func (w *Writer) Uint8s(vs []uint8)

Uint8s writes []uint8

func (*Writer) UintPtr

func (w *Writer) UintPtr(v *uint)

UintPtr writes *uint

func (*Writer) Uints

func (w *Writer) Uints(vs []uint)

Uints writes []uint

type Writers

type Writers struct {
	sync.Pool
}

Writers represents writer pool

func NewWriters

func NewWriters() *Writers

NewWriters creates writer pool

func (*Writers) Get

func (p *Writers) Get() *Writer

Get returns a writer

Jump to

Keyboard shortcuts

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