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[,schema]]
functions- a validate boolean : to check the validity of the type against its schema or not
See newDataTypes.md for more details.
Add types
which is an object with keys the name of the types and values the type definitions.
Add types in protocol
recursively. The protocol object is an object with keys types
and namespace keys.
- The value of the
types
key is an object of type name to type definition. - The value of the namespace key is a protocol object.
The path
is an array of namespace keys which select a path of namespaces to be added to the protodef object.
See full_protocol.js for an example of usage.
Read the packet defined by _fieldInfo
in buffer
starting from cursor
using the context rootNodes
.
Write the packet defined by _fieldInfo
in buffer
starting from offset
with the value value
and context rootNode
Size of the packet value
defined by _fieldInfo
with context rootNode
Returns a buffer of the packet
for type
.
Returns a parsed packet of buffer
for type
.
Create a serializer of mainType
defined in proto
. This is a Transform stream.
Returns a buffer of the packet
.
Create a parser of mainType
defined in proto
. This is a Transform stream.
Returns a parsed packet of buffer
.
An object mapping the default type names to the corresponding [read,write,sizeOf]
functions.
Add types
which is an object with keys the name of the types and values the type definitions.
Add types in protocol
recursively. The protocol object is an object with keys types
and namespace keys.
- The value of the
types
key is an object of type name to type definition. - The value of the namespace key is a protocol object.
The path
is an array of namespace keys which select a path of namespaces to be added to the protodef object.
Compile and return a ProtoDef
object, optionaly print the generated javascript code.
Some functions that can be useful to build new datatypes reader and writer.
Get countField
given context
. Example: "../field" will get "field" one level above.
Takes fieldInfo
as :
"type"
["type",typeArgs]
{ type: "type", typeArgs: typeArgs }
Returns { type: "type", typeArgs: typeArgs }
Add field
to error e
and throw e.
A simple tryCatch function, useful for optimization. returns what tryfn returns
Try tryfn
, it it fails, use addErrorField with field