
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
A fast binary data packing & unpacking library for node.js designed for multiplayer games.
npm install c-struct --save
Execute
$ node examples/to see the examples.
var _ = require('c-struct');
var playerSchema = new _.Schema({
id: _.type.uint16,
name: _.type.string(16),
hp: _.type.uint24,
exp: _.type.uint32,
status: _.type.uint8,
motd: _.type.string(), // null-terminated if no length
motw: _.type.string(), // cstring if no length
skills: [{
id: _.type.uint8,
name: _.type.string(32),
secret: _.type.uint40
}],
position: {
x: _.type.uint16,
y: _.type.uint16
},
hash: _.type.uint48
});
// register to cache
_.register('Player', playerSchema);
// object to buffer | this can be on another file
var buf = _.packSync('Player', {
id: 1,
name: 'Foobar',
hp: 1000,
exp: 88888888,
status: 100,
skills: [{
id: 1,
name: 'traps of thunder',
secret: 5151515151
}, {
id: 2,
}, {
name: 'fatal blow'
}, {
id: 3,
name: 'galvano strike'
}],
position: {
x: 102,
y: 351
},
motd: 'welcome',
motw: 'weekly',
hash: 99999999,
});
var _ = require('c-struct');
var playerSchema = new _.Schema({
id: _.type.uint16,
name: _.type.string(16),
hp: _.type.uint24,
exp: _.type.uint32,
status: _.type.uint8,
motd: _.type.string(), // null-terminated if no length
motw: _.type.string(), // cstring if no length
skills: [{
id: _.type.uint8,
name: _.type.string(32),
secret: _.type.uint40
}],
position: {
x: _.type.uint16,
y: _.type.uint16
},
hash: _.type.uint48
});
// register to cache
_.register('Player', playerSchema);
// buffer to object | this can be on another file
var obj = _.unpackSync('Player', BUFFER_HERE);
Currently only unsigned values in little endian are supported
_.type.uint8 // unsigned char
_.type.uint16 // unsigned short
_.type.uint24
_.type.uint32 // unsigned long
_.type.uint40
_.type.uint48
You can also specify default values
_.type.u8(9999) // default value 9999
_.type.u16(999) // default value 999
_.type.u24(888) // default value 888
_.type.u32(777) // default value 777
_.type.u40(666) // default value 666
_.type.u48(555) // default value 555
There is currently no configs.
FAQs
A C-struct library to manage binary structures with Node.JS
The npm package c-struct receives a total of 36 weekly downloads. As such, c-struct popularity was classified as not popular.
We found that c-struct demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.