binpack

package module
v0.0.0-...-baff025 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

Build Status GoDoc Go Report Card codecov.io GolangCI CodeFactor AppVeyor

Binpack Encoding for Golang

binpack is a library implementing encoding/binpack. Which is a binary serialize format, it is json like, but smaller and faster.

Install

go get github.com/theodesp/binpack

Documentation and Examples

Visit godoc for general examples and public api reference. See .travis.yml for supported go versions.

See implementation examples:

Supported Types

  • string
  • []byte
  • []uint8
  • float32
  • float64
  • bool
  • nil
  • basic slices ([]string, []int, ...)
  • basic arrays ([n]string, [n]int, ...)
  • basic maps
  • ints
  • uints

Run tests

go test -race

Contributions

See our Contributing guide. This project uses allcontributors.

License

The Apache

Documentation

Overview

Package binpack is a library implementing encoding/binpack. Which is a binary serialize format, it is json like, but smaller and faster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code byte
const (
	Closure Code = 0x01 // 0000 0001
	List    Code = 0x02 // 0000 0010
	Dict    Code = 0x03 // 0000 0011

	True  Code = 0x04 // 0000 0100
	False Code = 0x05 // 0000 0101

	Double Code = 0x06 // 0000 0110
	Float  Code = 0x07 // 0000 0111

	Nil    Code = 0x0f // 0000 1111
	Blob   Code = 0x10 // 0001 0000
	String Code = 0x20 // 0010 0000

	Integer         Code = 0x40 // 0100 0000
	IntegerNegative Code = 0x20 // 0010 0000

	IntegerTypeByte  Code = 0x01 << 3 // xxx0 1xxx
	IntegerTypeShort Code = 0x02 << 3 // xxx1 0xxx
	IntegerTypeInt   Code = 0x03 << 3 // xxx1 1xxx
	IntegerTypeLong  Code = 0x00 << 3 // xxx0 0xxx

	MaskIntegerSign      Code = 0x20 /* check if integer is negative */
	MaskTypeInteger      Code = 0x60 /* 0110 0000: integer or negative integer */
	MaskTypeStringOrBlob Code = 0x30 /* 00xx 0000: string or blob */
	MaskLastInteger      Code = 0x1f /* 000x xxxx the last 5 bits */
	MaskLastUintLen      Code = 0x0f /* 0000 xxxx the last 4 bits will be used to pack unit len */

	TagPackNumber  Code = 0x0f // 0001 xxxx
	TagPackInteger Code = 0x20 // 000x xxxx
	TagPackUintLen Code = 0x10 // 0000 xxxx

	NumSignBit Code = 0x80 // 1000 0000
	NumMask    Code = 0x7f // 0111 1111
)

type Decoder

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

A Decoder parses a decoded message and unpacks its values into the assigned variables. It is NOT safe for concurrent use by multiple goroutines.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from the io.Reader. If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.

func (*Decoder) Decode

func (dec *Decoder) Decode(e interface{}) error

Decode reads the next value from the input stream and stores it in the data represented by the empty interface value. If e is nil, the value will be discarded. Otherwise, the value underlying e must be a pointer to the correct type for the next data item received. If the input is at EOF, Decode returns io.EOF and does not modify e.

func (*Decoder) DecodeValue

func (dec *Decoder) DecodeValue(v reflect.Value) error

DecodeValue reads the next value from the input stream. If v is the zero reflect.Value (v.Kind() == Invalid), DecodeValue discards the value. Otherwise, it stores the value into v. In that case, v must represent a non-nil pointer to data or be an assignable reflect.Value (v.CanSet()) If the input is at EOF, DecodeValue returns io.EOF and does not modify v.

type Encoder

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

An Encoder manages the transmission of type and data information to the other side of a connection. It is NOT safe for concurrent use by multiple goroutines.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that will transmit on the io.Writer.

func (*Encoder) Encode

func (enc *Encoder) Encode(e interface{}) error

Encode transmits the data item represented by the empty interface value

func (*Encoder) EncodeValue

func (enc *Encoder) EncodeValue(value reflect.Value) error

EncodeValue transmits the data item represented by the reflection value,

Jump to

Keyboard shortcuts

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