-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add newDatatypes.md and reorganize README, progress on #46
- Loading branch information
Showing
4 changed files
with
254 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# API | ||
|
||
## ProtoDef() | ||
|
||
### ProtoDef.addType(name,functions) | ||
|
||
Add the type `name` with the data `functions` which can be either: | ||
* "native" : that type is already implemented by ProtoDef | ||
* a js object defining a type based on other already defined types | ||
* `[read,write,sizeOf]` functions | ||
|
||
### ProtoDef.read(buffer, cursor, _fieldInfo, rootNodes) | ||
|
||
Read the packet defined by `_fieldInfo` in `buffer` starting from `cursor` using the context `rootNodes`. | ||
|
||
### ProtoDef.write(value, buffer, offset, _fieldInfo, rootNode) | ||
|
||
Write the packet defined by `_fieldInfo` in `buffer` starting from `offset` with the value `value` and context `rootNode` | ||
|
||
### ProtoDef.sizeOf(value, _fieldInfo, rootNode) | ||
|
||
Size of the packet `value` defined by `_fieldInfo` with context `rootNode` | ||
|
||
### ProtoDef.createPacketBuffer(type,packet) | ||
|
||
Returns a buffer of the `packet` for `type`. | ||
|
||
### ProtoDef.parsePacketBuffer(type,buffer) | ||
|
||
Returns a parsed packet of `buffer` for `type`. | ||
|
||
## Serializer(proto,mainType) | ||
|
||
Create a serializer of `mainType` defined in `proto`. This is a Transform stream. | ||
|
||
### Serializer.createPacketBuffer(packet) | ||
|
||
Returns a buffer of the `packet`. | ||
|
||
## Parser(proto,mainType) | ||
|
||
Create a parser of `mainType` defined in `proto`. This is a Transform stream. | ||
|
||
### Parser.parsePacketBuffer(buffer) | ||
|
||
Returns a parsed packet of `buffer`. | ||
|
||
## types | ||
|
||
An object mapping the default type names to the corresponding `[read,write,sizeOf]` functions. | ||
|
||
## utils | ||
|
||
Some functions that can be useful to build new datatypes reader and writer. | ||
|
||
### utils.getField(countField, context) | ||
|
||
Get `countField` given `context`. Example: "../field" will get "field" one level above. | ||
|
||
### utils.getFieldInfo(fieldInfo) | ||
|
||
Takes `fieldInfo` as : | ||
* `"type"` | ||
* `["type",typeArgs]` | ||
* `{ type: "type", typeArgs: typeArgs }` | ||
|
||
Returns `{ type: "type", typeArgs: typeArgs }` | ||
|
||
### utils.addErrorField(e, field) | ||
|
||
Add `field` to error `e` and throw e. | ||
|
||
### utils.tryCatch(tryfn, catchfn) | ||
|
||
A simple tryCatch function, useful for optimization. | ||
returns what tryfn returns | ||
|
||
### utils.tryDoc(tryfn, field) | ||
|
||
Try `tryfn`, it it fails, use addErrorField with `field` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# History | ||
|
||
## 0.3.0 | ||
* add partial packet support | ||
|
||
## 0.2.6 | ||
* add compareToValue (optional) option to switch | ||
|
||
## 0.2.5 | ||
|
||
* fix small error in switch | ||
|
||
## 0.2.4 | ||
|
||
* get back the example file as one file for simplicity and for tonic | ||
|
||
## 0.2.3 | ||
|
||
* fix a small mistake in mapping error | ||
* improve internal code | ||
* improve example | ||
* integrate with tonicdev | ||
|
||
## 0.2.2 | ||
|
||
* Fix writeOption : the offset wasn't properly updated | ||
|
||
## 0.2.1 | ||
|
||
* Anon fields may now be null/undefined. | ||
|
||
## 0.2.0 | ||
|
||
* add createPacketBuffer and parsePacketBuffer to ProtoDef class | ||
* expose utils functions | ||
* add mapper and pstring datatypes | ||
|
||
## 0.1.0 | ||
|
||
* add the serializer and parser | ||
* expose the default datatypes | ||
* add an example | ||
|
||
## 0.0.1 | ||
|
||
* basic version, mostly contain the ProtoDef class and the datatype |
Oops, something went wrong.