Skip to content
Binary Extended JSON. Beson library is similar to BSON format and allows primitive data to be encoded directly.
Branch: master
Clone or download
Latest commit 7e72b14 Apr 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
helper
types
README.md
beson_test.go
constants.go
deserializer.go
serializer.go

README.md

GoDoc

BESON, short for Binary Extended JSON. Beson library is similar to BSON format used in mongodb. The major difference between beson and bson is that beson allows primitive data to be encoded directly. Beson is designed to transfer or store data in a binary format, not specialized for database storage.

Table of Contents

Characteristics

BESON was designed to have the following three characteristics:

  1. Lightweight: To be compared to BSON and JSON, BESON is more advantage in space efficiency. BESON allows primitive data to be encoded directly, which can save space overhead for object key.

  2. Efficient: Encoding data to BESON and decoding from BESON can be performed very quickly in most languages due to the use of primitive data types.

  3. More Types: BESON supports many types of integer, 8-bit to 512-bit and even you can customize the size of the integer.

Features

  • Big integer number operations.
    • 128-bit integer:UInt128 / Int128
    • 256-bit integer:UInt256 / Int256
    • 512-bit integer:UInt512 / Int512
    • Variable length integer:UIntVar / IntVar
  • Serialize data to binary sequence.
  • Desrialize binary sequence to original data.

Installation

Download and install it:

$ go get -u github.com/GoblinBear/beson-go

Import it in your code (serialize / deserialize):

import beson "github.com/GoblinBear/beson-go"

Import it in your code (big integer number):

import "github.com/GoblinBear/beson-go/types"

Quick start

Initialize a big integer number

package main

import (
    "fmt"
    "github.com/GoblinBear/beson-go/types"
)

func main() {
    v1 := types.NewUInt256("1844674407370955161825", 10)
    fmt.Println(v1)
}
&{[206 8 0 0 0 0 0 0 232 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}

Serialize

package main

import (
    "fmt"
    beson "github.com/GoblinBear/beson-go"
)

func main() {
    var v uint32 = 2568
    ser := beson.Serialize(v)
    fmt.Println(ser)
}
[3 0 8 10 0 0]

Deserialize

package main

import (
    "fmt"
    beson "github.com/GoblinBear/beson-go"
    "github.com/GoblinBear/beson-go/types"
)

func main() {
    var v uint32 = 2568
    ser := beson.Serialize(v)

    anchor, data := beson.Deserialize(ser, 0)
    fmt.Println(data)
    fmt.Println(anchor)
}
data = 2568
anchor = 6
  • data:Source data.
  • anchor:The location of next encoded data.

Usage

  • See the wiki page for details:wiki

License

beson-go source code is licensed under the Apache Licence, Version 2.0.

You can’t perform that action at this time.