Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert between JS object and Node.js buffer

License

NotificationsYou must be signed in to change notification settings

rzcoder/data-struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert between JS object and Node.js buffer with rigidly predetermined scheme.

Installing

    npm install data-struct

Usage

require("data-struct") exports just 3 namespaces:

  • DataTypes – dictonary of supported types:
    • boolean – 1 byte
    • int8 – 1 byte
    • uint8 – 1 byte
    • int16 – 2 bytes
    • uint16 – 2 bytes
    • int32 – 4 bytes
    • uint32 – 4 bytes
    • float – 4 bytes
    • double – 8 bytes
    • string – 2 bytes header + string bytes length (max length: 65535 bytes,not string length!)
    • shortBuffer – 2 bytes header + buffer length (max length: 65535 bytes)
    • buffer – 4 bytes header + buffer length (max length 4294967295 bytes)
  • DataReader(buffer, scheme) – buffer -> object function.
  • DataWriter(object, scheme) – object -> buffer function.

Example

varDataTypes=require("data-struct").DataTypes;varDataReader=require("data-struct").DataReader;varDataWriter=require("data-struct").DataWriter;varhero={id:9,name:'CirnoBaka',hp:146,skills:[{id:34,description:'freezing frogs'},{id:16,description:'perfect math'}],playable:false,experience:99999999,position:{x:2,y:3}};varheroScheme={id:DataTypes.uint32,name:DataTypes.string,hp:DataTypes.int16,skills:[{id:DataTypes.uint16,description:DataTypes.string}],playable:DataTypes.boolean,experience:DataTypes.uint32,position:{x:DataTypes.uint16,y:DataTypes.uint16}};varheroBuf=DataWriter(hero,heroScheme);varheroClone=DataReader(heroBuf,heroScheme);//nested arraysvarmap=[[0,1,0,0,1,1,1,1],[1,1,0,0,0,1,1,1],[1,1,0,0,0,0,1,1],[1,1,1,1,0,0,1,1],[0,1,1,0,0,0,1,1],[0,0,0,0,0,1,1,1],[0,0,0,0,1,1,1,1]];varmapScheme=[[DataTypes.uint8]];varmapBuf=DataWriter(map,mapScheme);varmapClone=DataReader(mapBuf,mapScheme);

License

MIT

About

Convert between JS object and Node.js buffer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp