oer-utils
v5.1.3-alpha.2
Published
Tools for OER parsing and serialization
Downloads
6,772
Readme
OER Utils
Collection of tools for OER parsing and serialization
Usage
npm install oer-utils
Numbers in oer-utils
This module uses the long
library to avoid issues with JavaScript numbers.
Writer
methods for writing integers, like writeUInt8
or writeVarInt
, accept numbers, strings, or Long
s.
The Reader
exposes methods for reading integers that return strings, such as readInt16
and readVarUInt
, as well as methods that return Long
s, such as readInt16Long
and readVarUIntLong
.
Note that if the long
API changes, there will be breaking changes to the read...Long
methods. These methods may be used to avoid unnecessary string conversions, but they may be less stable in the long term than the methods that export strings.
Examples
Parse a binary buffer
const Reader = require('oer-utils/reader')
const reader = Reader.from(new Buffer('1234', 'hex'))
const v1 = reader.readUInt8()
const v2 = reader.readUInt8Long()
Write a binary file
const Writer = require('oer-utils/writer')
const Long = require('long')
const writer = new Writer()
writer.writeUInt8(1)
writer.writeUInt8(Long.fromNumber(2, true))
const buffer = writer.getBuffer()