You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

bison-types

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bison-types - npm Package Compare versions

Comparing version

to
2.0.2

src/enum.coffee

2

package.json
{
"name": "bison-types",
"version": "2.0.0",
"version": "2.0.2",
"description": "Convert between json and binary",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -69,4 +69,6 @@ # bison-types

## Provided simple types
## Provided types
The following types can be declared as a string, for example: `{timestamp: 'uint16'}`.
* `uint8` - unsigned 8 bit integer

@@ -84,8 +86,28 @@ * `uint16` - unsigned 16 bit integer

The is also an `enumeration` type, which can be used to represent enums from arrays of objects:
```coffee
# will store the index in the array
levelIndex = bison.enumeration 'uint8', ['admin', 'reader', 'writer']
# will store the value in the object
levelCode = bison.enumeration 'uint16',
'admin': 0xb8a3
'reader': 0xb90a
'writer': 0xf23c
bison.preCompile
'levelIndex': levelIndex
'levelCode': levelCode
'user': [
{id: 'uint8'}
{levelX: levelIndex}
{levelY: levelCode}
]
```
## Creating your own custom types
*NOTE:* All examples are written in coffeescript
There are 2 different ways that you can define a custom type
There are 2 different ways that you can define a custom type
### By mapping it to another type

@@ -111,5 +133,6 @@

### By explicitly creating a _read function
We expose the underlying [clever-buffer](https://github.com/TabDigital/clever-buffer) as @buffer.
You can call any of it's methods
You can call any of its methods

@@ -116,0 +139,0 @@ ```coffee

require("coffee-script");
exports.Reader = require("./reader");
exports.Writer = require("./writer");
exports.preCompile = require("./preCompile");
exports.Reader = require("./reader");
exports.Writer = require("./writer");
exports.preCompile = require("./preCompile");
exports.enumeration = require("./enum");