https://github.com/platdesign/bipro
Binary protocol composer/parser
https://github.com/platdesign/bipro
binary js nodejs protocol
Last synced: 2 months ago
JSON representation
Binary protocol composer/parser
- Host: GitHub
- URL: https://github.com/platdesign/bipro
- Owner: platdesign
- License: mit
- Created: 2017-07-31T17:42:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-20T20:43:06.000Z (over 6 years ago)
- Last Synced: 2024-04-27T23:01:11.757Z (about 1 year ago)
- Topics: binary, js, nodejs, protocol
- Language: HTML
- Size: 86.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# bipro
Binary Protocol composer/parser
# Install
`npm i --save bipro`# Api
### Protocol
#### defineType(name, configOrParent, [configExtender])- **name** *(String)* Unique name/identifier for type *(e.g. uint8, char, byte)*
- **configOrParent** *(Object | String)* String defines previous defined type for inheritance.
- **compose(value, data, schema, protocol)**
Should return an instance of `Buffer`.
- **value** Value of attributes key in `data`.
- **data** Whole composing data.
- **schema** Attribute schema config line
- **protocol** Current protocol instance
- **parse(buffer, context, schema, protocol)** Should return parsed value or `null` if invalid.- **buffer** Raw buffer
- **context**
- **offset** Current cursor position during parse-process.
- **schema** Attribute schema config line
- **protocol** Current protocol instance#### defineMessage(name, config)
Defines a messageType by given config.- **name** (`String`) Unique message name.
- **config** (`Object`)
- **schema** (`Array`) of Schema Objects
- **key** (`String`) Name of payload attribute.
- **type** (`String`) Name of type.
- **default** (`Number`|`String`|`Array`) based on `type`
- **static** (`Boolean`) Default: false
- **required** (`Boolean`) Default: false#### compose(messageName, payload)
Returns buffer for given payload.#### match(buffer)
Takes a buffer and returns parsed data or `false` if no messageType matches.#### use(plugin, [options])
### Message Schema
- schema
### Value Schema
- key
- type
- static
- default### Type Schema
- compose(char, data, schema, protocol)
- parse(buf, ctx, schema, protocol)## Default types
- **int8**
- **uint8**
- **byte**
- **char**
- **int16le**
- **int16be**
- **uint16le**
- **uint16be**
- **shortle**
- **shortbe**
- **ushortle**
- **ushortbe**
- **int32le**
- **int32be**
- **uint32le**
- **uint32be**
- **longle**
- **longbe**
- **ulongle**
- **ulongbe**
- **array**
- **items** (`String`|`Object`)
Set custom item type. (e.g. string, char, ulongbe) Default is `uint8`
- `String` Name of type
- `Object` Schema options ({type: 'string', size:3})
- **sizeType** (`String`)
Set custom size type. Default is `uint8`
- **size** (`Number`|`String`)
Set custom/fixed size. Otherwise array-items will be prefixed with size-byte(s).
- `Number` Used as fixed length. (No size byte(s) will be prefixed)
- `String` Used as size-value getter. (No size byte(s) will be prefixed)- **string**
- **size** (`Number`|`String`)
- `Number` Used as fixed length. (No size byte(s) will be prefixed)
- `String` Used as size-value getter. (No size byte(s) will be prefixed)#Author
Christian Blaschke