Giter VIP home page Giter VIP logo

beson-go's Introduction

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.

beson-go's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.