This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including schemapack
with all npm
packages installed. Try it out:
const sp = require('schemapack');
// Define the schema
const playerSchema = sp.build({
health: 'varuint',
jumping: 'boolean',
position: [ 'int16' ],
attributes: { str: 'uint8', agi: 'uint8', int: 'uint8' },
});
// An object to serialize
const player = {
health: 4000,
jumping: false,
position: [ -540, 343, 1201 ],
attributes: { str: 87, agi: 42, int: 22 },
};
// Encode
const buffer = playerSchema.encode(player);
console.log(buffer);
// Decode
const decoded = playerSchema.decode(buffer);
console.log(decoded);
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.