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.
BESON was designed to have the following three characteristics:
-
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.
-
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.
-
More Types: BESON supports many types of integer, 8-bit to 512-bit and even you can customize the size of the integer.
- Big integer number operations.
- 128-bit integer:
UInt128
/Int128
- 256-bit integer:
UInt256
/Int256
- 512-bit integer:
UInt512
/Int512
- Variable length integer:
UIntVar
/IntVar
- 128-bit integer:
- Serialize data to binary sequence.
- Desrialize binary sequence to original data.
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"
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]}
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]
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.
- See the wiki page for details:wiki
beson-go source code is licensed under the Apache Licence, Version 2.0.