0.3.1 • Published 3 years ago

@krknet/bpson v0.3.1

Weekly downloads
7
License
ISC
Repository
-
Last release
3 years ago

BPSON

Binary Protocol JSON

Schema

Optional Fields append a ? to the Key.

Field Types

String: String Number: Number Boolean: Boolean Array: [] Object: {}

Example

const Schema = require('@krknet/bpson')

const input = {
  t1: [ 2012, 2012.5423, -2018.984512315646, 0 ],
  t2: true,
  t3: {
    t31: 153,
    t32: 'Test',
    t33: {
      t331: 'Testst'
    }
  },
  t4: 'Aloha'
}

const schema = new Schema({
  t1: [Number],
  't2?': Boolean,
  t3: {
    t31: Number,
    t32: String,
    't33?': { t331: String }
  },
  t4: String
})

const code = schema.encode(input)
const text = code.toString('base64')
const result = schema.decode(Buffer.from(text, 'base64'))