1.0.1 • Published 4 years ago

js01 v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

js01

Fast and simple protocol buffers in Javascript.

Usage

const myUserSchema = js01({
  name: "8", // for utf8 encoding
  someOtherName: "16", // for utf16 encoding
  age: 8, // for uint8,
  number: 0.64, // for float64
  isAdult: true, // boolean value for boolean type
  object: {
    os: "8"
    // more stuff here
  },
  array: [8], // array of uint8, max length 255
  range: -8, // int8, negative sign for signed integers
  // use js01.T for more types and customizibilty
});

let someUser = {
    name: "Bob",
    someOtherName: "你好",
    age: 40,
    number: 123.456,
    isAdult: true,
    object: {
        os: "linux"
    },
    array: [1,2,3,4,5,6],
    range: -100
}

let arrayBuffer = myUserSchema.encode(someUser)
let decoded = myUserSchema.decode(arrayBuffer)

Types

All the types are under js01.T

nametypeshorthand
T.boolbooltrue or false
T.u8uint88
T.u16uint1616
T.u32uint3232
T.i8int8-8
T.i16int16-16
T.i32int32-32
T.f32float320.32
T.f64float640.64
T.fstrfixed string"len:LENGTH ?ENCODING"
T.strstring"?ENCODING ?HEADER"
T.tuptuple[TYPES...]
T.objobject{SCHEMA...}
T.arrarray[TYPE]