Giter VIP home page Giter VIP logo

node-caps's Introduction

Node-Caps

What is Caps

Caps is a light, simple serialization library, support data types:

  • int32
  • uint32
  • int64
  • uint64
  • string
  • float
  • double

What is Node-Caps

Node-Caps is a wrapper of Caps using N-API

Node-Caps API Reference

Write Data

writeInt32(num) write int32 value into this Caps object

  • num int32, 4 bytes

writeUInt32(num) write uint32 value into this Caps object

  • num uint32, 4 bytes

writeInt64(num) write int64 value into this Caps object

  • num int64, 8 bytes

writeUInt64(num) write uint64 value into this Caps object

  • num uint64, 8 bytes

writeFloat(num) write float value into this Caps object

  • num float, 4 bytes

writeDouble(num) write int32 value into this Caps object

  • num double number, 8 bytes

writeCaps(capsObj) write another Caps object into this Caps

  • capsObj Caps object

Read Data

readInt32() read out a int32 value

  • return int32 value

readUInt32() read out a uint32 value

  • return uint32 value

readInt64() read out a int64 value

  • return int64 value

readUInt64() read out a uint64 value

  • return uint64 value

readFloat() read out a float value

  • return float value

readDouble() read out a double value

  • return double value

readCaps(capsObj) read out a Caps object

  • return Caps object

serialize and deserialize

serialize(byteOrder) serialize this Caps object into UInt8Array byteOrder Caps.NetworkByteOrder/Caps.NBO, Caps.HostByteOrder/Caps.HBO

serializeForCapsObj(byteOrder) serialize this Caps object into another one byteOrder Caps.NetworkByteOrder/Caps.NBO, Caps.HostByteOrder/Caps.HBO

deserialize(uint8Array) deserialize from UInt8Array uint8Array the buff deserialize to Caps object

deserializeForCapsObj(capsObj) deserialize from another Caps object capsObj the Caps object contain another Caps

demo

'use strict'

const Caps = require("./PATH/TO/Caps").Caps

let f = ()=>
{

    var arr = new Uint8Array(5)
    arr[0] = 0x00
    arr[1] = 0x01
    arr[2] = 0x02
    arr[3] = 0x03
    arr[4] = 0x04
    var write = new Caps()
    console.log(write.NetWorkByteOrder)
    try {
        write.writeInt32(-123)
        write.writeUInt32(123)
        write.writeInt64(123456789)
        write.writeString("testring")
        write.writeBinary(arr)
        var capsToWrite = new Caps()
        capsToWrite.writeInt32(999)
        capsToWrite.writeString("stringincaps")
        write.writeCaps(capsToWrite)
    }
    catch (errWrite) {
        //something wrong here
    }
    var buff = write.serialize()

    var reader = new Caps()
    try {
        reader.deserialize(buff)
        console.log(reader.readInt32())// console output -123
        console.log(reader.readUInt32())// console output 123
        console.log(reader.readInt64())// console output 123456789
        console.log(reader.readString())// console output teststring
        var arr_read = reader.readBinary()
        //console output arr[0] 1 arr[1] 2 arr[2] 3 arr[3] 4 arr[4] 5
        for (var i = 0; i < arr_read.length; ++i)
            console.log(`arr[${i}] ${arr_read[i]}`)
        var capsFromCaps = reader.readCaps()
        console.log(capsFromCaps.readInt32())// console output 999
        console.log(capsFromCaps.readString())// console output stringincaps
    }
    catch (errRead) {
        //something wrong here
    }
};
f();

node-caps's People

Contributors

feelychau avatar legendecas avatar mingzc0508 avatar yorkie avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.