binary

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SByteDataSize  = 1
	ByteDataSize   = 1
	CharDataSize   = 2
	ShortDataSize  = 2
	UShortDataSize = 2
	IntDataSize    = 4
	UIntDataSize   = 4
	LongDataSize   = 8
	ULongDataSize  = 8
	FloatDataSize  = 4
	DoubleDataSize = 8
)

Variables

Functions

func MarshalBool

func MarshalBool(b bool) []byte

MarshalBool marshals boolean value

func MarshalBools

func MarshalBools(bs []bool) []byte

MarshalBools marshals bool array format:

  • TypeBools
  • 16bit count
  • repeat: bits...

func MarshalByte

func MarshalByte(val int) []byte

MarshalByte marshals unsigned 8bit integer

func MarshalBytes

func MarshalBytes(vals []int) []byte

MarshalBytes marshals bytes array format:

  • TypeBytes
  • 16bit count
  • repeat: byte...

func MarshalChar

func MarshalChar(val rune) []byte

MarshalChar marshals 16bit code-point.

if the val is larger than \uffff, it is replaced to \uffff.

func MarshalChars

func MarshalChars(vals []rune) []byte

MarshalChars marshals 16bit code-point array format:

  • TypeChars
  • 16bit count
  • repeat: 16bit BE integer...

func MarshalDict

func MarshalDict(dict Dict) []byte

MarshalDict marshals Dict format:

  • TypeDict
  • 8bit count
  • repeat:
  • 8bit key length
  • key string
  • 16bit body length
  • marshaled body

func MarshalDouble

func MarshalDouble(val float64) []byte

MarshalFloat marshals IEEE 754 double value as comparably.

func MarshalDoubles

func MarshalDoubles(vals []float64) []byte

MarshalDoubles marshals IEEE754 single array

func MarshalFloat

func MarshalFloat(val float32) []byte

MarshalFloat marshals IEEE 754 single value as comparably. The sign-bit (MSB) is inverted to make the positive value greater than the negative value. All exponent and fraction bits on the negative value are inverted to make it natural order.

func MarshalFloats

func MarshalFloats(vals []float32) []byte

MarshalFloats marshals IEEE754 single array

func MarshalInt

func MarshalInt(val int) []byte

MarshalInt marshals signed 32bit integer comparably

func MarshalInts

func MarshalInts(vals []int) []byte

MarshalInts marshals signed 32bit integer array format:

  • TypeInts
  • 16bit count
  • repeat: 32bit BE integer...

func MarshalList

func MarshalList(list List) []byte

MarshalList marshals List format:

  • TypeList
  • 8bit count
  • repeat:
  • 16bit body length
  • marshaled body

func MarshalLong

func MarshalLong(val int) []byte

MarshalLong marshals signed 64bit integer comparably

func MarshalLongs

func MarshalLongs(vals []int) []byte

MarshalLongs marshals signed 64bit integer array format:

  • TypeInts
  • 16bit count
  • repeat: 64bit BE integer...

func MarshalNull

func MarshalNull() []byte

MarshalNull marshals null

func MarshalObj

func MarshalObj(obj *Obj) []byte

MarshalObj marshals Obj format:

  • TypeObj
  • 8bit class id (specified by app)
  • 16bit body length
  • body

func MarshalSByte

func MarshalSByte(val int) []byte

MarshalSByte marshals signed 8bit integer comparably

This func maps the value -128..127 to unsigned value 0..255 to make the dst array comparable byte-by-byte directly.

func MarshalSBytes

func MarshalSBytes(vals []int) []byte

MarshalSBytes marshals sbytes array format:

  • TypeSBytes
  • 16bit count
  • repeat: sbyte...

func MarshalShort

func MarshalShort(val int) []byte

MarshalUShort marshals signed 16bit integer comparably

func MarshalShorts

func MarshalShorts(vals []int) []byte

MarshalShorts marshals signed 16bit integer array format:

  • TypeShorts
  • 16bit count
  • repeat: 16bit BE integer...

func MarshalStr16

func MarshalStr16(str string) []byte

MarshalStr16 marshals long string (len > 255..65545)

func MarshalStr8

func MarshalStr8(str string) []byte

MarshalStr8 marshals short string (len <= 255)

func MarshalStrings

func MarshalStrings(vals []string) []byte

func MarshalUInt

func MarshalUInt(val int) []byte

MarshalUInt marshals unsigned 32bit integer

func MarshalUInts

func MarshalUInts(vals []int) []byte

MarshalInts marshals unsigned 32bit integer array format:

  • TypeUInts
  • 16bit count
  • repeat: 32bit BE integer...

func MarshalULong

func MarshalULong(val uint64) []byte

MarshalULong marshals unsigned 64bit integer

func MarshalULongs

func MarshalULongs(vals []uint64) []byte

MarshalULongs marshals unsigned 64bit integer array format:

  • TypeInts
  • 16bit count
  • repeat: 64bit BE integer...

func MarshalUShort

func MarshalUShort(val int) []byte

MarshalUShort marshals unsigned 16bit integer

func MarshalUShorts

func MarshalUShorts(vals []int) []byte

MarshalUShort marshals unsigned 16bit integer array format:

  • TypeUShort
  • 16bit count
  • repeat: 16bit BE integer...

func Unmarshal

func Unmarshal(src []byte) (interface{}, int, error)

Unmarshal serialized bytes

func UnmarshalAs

func UnmarshalAs(src []byte, types ...Type) (interface{}, int, error)

Unmarshal bytes as specified type

Types

type Dict

type Dict map[string][]byte

type List

type List [][]byte

type Obj

type Obj struct {
	ClassId byte   // specified by app
	Body    []byte // marshaled bytes
}

type Type

type Type byte
const (
	TypeNull    Type = iota // C#:null
	TypeFalse               // C#:bool (false)
	TypeTrue                // C#:bool (true)
	TypeSByte               // C#:sbyte
	TypeByte                // C#:byte
	TypeChar                // C#:char
	TypeShort               // C#:short (16bit)
	TypeUShort              // C#:ushort
	TypeInt                 // C#:int (32bit)
	TypeUInt                // C#:uint
	TypeLong                // C#:long (64bit)
	TypeULong               // C#:ulong
	TypeFloat               // C#:float
	TypeDouble              // C#:double
	TypeDecimal             // C#:decimal
	TypeStr8                // C#:string; lenght < 256
	TypeStr16               // C#:string; lenght >= 256
	TypeObj                 // C#:object
	TypeList                // C#:List<object>; count < 256
	TypeDict                // C#:Dictionary<string, object>; count < 256; key length < 256

	TypeBools    // C#:bool[]
	TypeSBytes   // C#:sbyte[]
	TypeBytes    // C#:byte[]
	TypeChars    // C#:char[]
	TypeShorts   // C#:short[]
	TypeUShorts  // C#:ushort[]
	TypeInts     // C#:int[]
	TypeUInts    // C#:uint[]
	TypeLongs    // C#:long[]
	TypeULongs   // C#:ulong[]
	TypeFloats   // C#:float[]
	TypeDoubles  // C#:double[]
	TypeDecimals // C#:decimal[]
)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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