llsn

package module
v0.0.0-...-41dc3a6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2018 License: MIT Imports: 11 Imported by: 0

README

LLSN

Go support for LLSN. Allyst's data interchange binary format

Format specification is available at http://allyst.org/opensource/llsn/

int64              // number
*int64             // number, nullable
*uint64            // unumber, nullable
[3]bool            // boolean
float64            // float
string             // string
time.Time          // date
*time.Time         // date, nullable
ExampleStruct      // struct
[5]ExampleStruct   // array of struct.
[]ExampleStruct    // array of struct. nullable
[4]*ExampleStruct  // array of struct. have null values
[][]*ExampleStruct // array of struct. nullable, have null values
llsn.Blob          // blob. nullable. its a regular slice of bytes ([]byte), 
                   // but you have to use this type for correct encode/decode 
llsn.File          // file
*llsn.File         // file. nullable

Encode(value *struct) []byte Encode(value *struct, threshold uint16) []byte

example...

You can get encoded data via channel. Returns nil Encode(value *struct, channel chan []byte) []byte Encode(value *struct, channel chan []byte, threshold uint16) []byte example...

Decode(source []byte, destination *struct) error Notice: source data will modify by decoder. you have to copy the original to reuse it elsewhere example Decode(source chan []byte, destination *struct) error example

EncodeNumber(number int64) []byte // returns 1..9 bytes EncodeUNumber(number uint64) []byte // returns 1..9 bytes EncodeFloat(f float64) []byte // returns 4 or 8 bytes EncodeDate(t *time.Time) []byte // return 8 bytes

DecodeFloat(buffer []byte) float64 DecodeNumber(buffer []byte) int64 DecodeUNumber(buffer []byte) uint64 DecodeDate(buffer []byte) *time.Time

llsn.SetOption(name string, v interface{}) tail encoding threshold "threshold" int (0 - disabled, max - 4096). default: 0 cache directory. uses for decoding files. "dir" string. default: "/tmp/"

Documentation

Index

Constants

View Source
const (

	// huge data threshold (STRING, BLOB, FILE)
	// if set to 0 - tail encoding is disable
	// if set > 0 - data exeeds this value are placed to the end of binary packet
	DEFAULT_THRESHOLD = 0

	// max length for the types STRING/BLOB
	STRING_MAXBYTES = 10485760
	BLOB_MAXBYTES   = 4294967296

	// temporary folder for decoding files
	DECODE_FOLDER = "/tmp/"

	// version of encoder
	VERSION = 1
)

Variables

This section is empty.

Functions

func Decode

func Decode(source interface{}, destination interface{}) (err error)

func DecodeDate

func DecodeDate(buffer []byte) *time.Time

2B: year. (-32767..32768)

:4b month (1..12)
:5b day of month (1..31)
:5b hour (0..23)
:6b min (0..59)
:6b sec (0..59)
:10 msec (0..999)
:6b hours offset (signed)
:6b min offset (unsigned)
-- :48bit

-- 8B total

func DecodeFloat

func DecodeFloat(buffer []byte) float64

func DecodeNumber

func DecodeNumber(buffer []byte) int64

func DecodeUNumber

func DecodeUNumber(buffer []byte) uint64

func Encode

func Encode(v interface{}, a ...interface{}) *bytes.Buffer

Encode method allows calling

Encode(value) Encode(value, threshold)

return nil in this case. all encoded data writes to the channel Encode(value, channel) Encode(value, channel, threshold)

func EncodeDate

func EncodeDate(t *time.Time) []byte

func EncodeFloat

func EncodeFloat(f float64) []byte

func EncodeNumber

func EncodeNumber(number int64) []byte

func EncodeUNumber

func EncodeUNumber(number uint64) []byte

func SetOption

func SetOption(name string, v interface{})

Types

type Blob

type Blob []byte

we have declared custom type Blob because of 'reflect' reflects '[]byte' as a '[]uint8' but we need the strict naming

type ErrorLLSN

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

func (*ErrorLLSN) Code

func (e *ErrorLLSN) Code() int

func (*ErrorLLSN) Error

func (e *ErrorLLSN) Error() string

type File

type File struct {
	Name string
	// contains filtered or unexported fields
}

func (*File) SaveTo

func (f *File) SaveTo(path string) error

Jump to

Keyboard shortcuts

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