Parser
Example:
import Parser from 'remote-instance';
const parser = new Parser();
Static Method Summary
Static Public Methods | ||
public static |
Construct a new instance of the given constructor with the given arguments list. |
|
public static |
isConstructor(constructor: function): boolean Check if the given value is a remote-instance constructor. |
|
public static |
trimArgumentsList(argumentsList: Array, defaults: Array): Array Trim a given argument list to a shorter list by removing undefined or default values. |
Constructor Summary
Public Constructor | ||
public |
constructor(opts: object) Create an instance of remote-instance Parser. |
Method Summary
Public Methods | ||
public |
decode(buffer: Buffer | BufferList): * Decode an value or an instance from an encoded buffer. |
|
public |
decodeArgumentsList(buffer: Buffer | BufferList): Array Decode a given arguments list buffer. |
|
public |
decoder(): Stream Get an transform stream that convert buffer to objects. |
|
public |
encode(value: *): BufferList Encode an value or an instance to a buffer. |
|
public |
encodeArgumentsList(argumentsList: Array): BufferList Encode a given arguments list to a buffer. |
|
public |
encoder(): Stream Get an transform stream that convert objects to buffer. |
|
public |
Register an instance on the parser with given type-code and constructor. |
|
public |
Create a duplex stream that transform duplex buffer stream to object stream. |
Static Public Methods
public static construct(constructor: function, argumentsList: Array): * source
Construct a new instance of the given constructor with the given arguments list.
If the constructor has a static method fromArgumentsList(argumentsList)
this
function will use that function to construct the instance.
Return:
* | A new instance of the given constructor |
public static isConstructor(constructor: function): boolean source
Check if the given value is a remote-instance constructor.
An remote-instance constructor is a constructor with a method toArgumentsList()
that enable to get the construct arguments of this class to create it remotely.
Params:
Name | Type | Attribute | Description |
constructor | function | the given value to check |
public static trimArgumentsList(argumentsList: Array, defaults: Array): Array source
Trim a given argument list to a shorter list by removing undefined or default values.
Default arguments comparing via strict deep-equal comparison.
For example, for the given argument list: [1, 'foo', undefined, {}]
and the given
default: [undefined, 'foo', 'bar', {}]
. The trimmed arguments list will be: [1]
.
Public Constructors
Public Methods
public decode(buffer: Buffer | BufferList): * source
Decode an value or an instance from an encoded buffer.
Params:
Name | Type | Attribute | Description |
buffer | Buffer | BufferList | The encoded buffer |
Return:
* | Any value or registered instance |
public decodeArgumentsList(buffer: Buffer | BufferList): Array source
Decode a given arguments list buffer.
Params:
Name | Type | Attribute | Description |
buffer | Buffer | BufferList | an encoded arguments list buffer |
public decoder(): Stream source
Get an transform stream that convert buffer to objects.
Return:
Stream |
public encode(value: *): BufferList source
Encode an value or an instance to a buffer.
Params:
Name | Type | Attribute | Description |
value | * | Any value or registered instance |
Return:
BufferList | The encoded buffer |
public encodeArgumentsList(argumentsList: Array): BufferList source
Encode a given arguments list to a buffer.
Params:
Name | Type | Attribute | Description |
argumentsList | Array | The given arguments list |
Return:
BufferList | The encoded arguments list |
public encoder(): Stream source
Get an transform stream that convert objects to buffer.
Return:
Stream |
public register(typeCode: number | object, constructor: function): Parser source
Register an instance on the parser with given type-code and constructor. The type-code value must be consistent in all the remote devices for the given constructor. The first argument could be also an object-map of type-codes and constructors instead.
public transform(stream: Stream, opts: object): Stream source
Create a duplex stream that transform duplex buffer stream to object stream.
Params:
Name | Type | Attribute | Description |
stream | Stream | A duplex buffer stream |
|
opts | object |
|
An options object to construct the duplex stream with.
The option |
Return:
Stream | A duplex object stream |