Serialization library for the Octet Encoding Rules (OER)
TypeScript JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
src
test
.eslintignore
.gitignore
CONTRIBUTING.md
LICENSE
README.md
npmrc-env
package-lock.json
package.json
predictor.js
reader.js
tsconfig.json
tslint.json
wallaby.js
writer.js

README.md

OER Utils

npm circle codecov

Collection of tools for OER parsing and serialization

Usage

npm install oer-utils

Numbers in oer-utils

This module uses the bignumber.js library to avoid issues with JavaScript numbers.

Writer methods for writing integers, like writeUInt8 or writeVarInt, accept numbers, strings, or BigNumbers.

The Reader exposes methods for reading integers that return strings, such as readInt16 and readVarUInt, as well as methods that return BigNumbers, such as readInt16BigNum and readVarUIntBigNum.

Note that if the bignumber.js API changes, there will be breaking changes to the read...BigNum 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.readUInt8BigNum()

Write a binary file

const Writer = require('oer-utils/writer')
const BigNumber = require('bignumber.js')

const writer = new Writer()

writer.writeUInt8(1)
writer.writeUInt8(new BigNumber(2))

const buffer = writer.getBuffer()