Message structure.
Members
(static, constant) MAGIC :number
Bitmessage magic value.
Type:
- number
- Source:
Methods
(static) decode(buf) → {DecodeResult}
Decode message.
NOTE: payload
is copied, rest
references input buffer.
Parameters:
Name | Type | Description |
---|---|---|
buf |
Buffer | Buffer that starts with encoded message |
- Source:
Returns:
- Type
- DecodeResult
(static) encode(command, payload) → {Buffer}
Encode message.
Parameters:
Name | Type | Description |
---|---|---|
command |
string | Message command |
payload |
Bufer | Message payload |
- Source:
Returns:
Encoded message structure.
- Type
- Buffer
(static) tryDecode(buf) → (nullable) {TryDecodeResult}
Decode message in "stream" mode.
NOTE: message payload and rest
are copied (so the runtime can GC
processed buffer data).
Parameters:
Name | Type | Description |
---|---|---|
buf |
Buffer | Data buffer |
- Source:
Returns:
- Type
- TryDecodeResult
Type Definitions
DecodeResult
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
command |
string | Message command |
payload |
Buffer | Message payload |
length |
number | Full message length |
rest |
Buffer | The rest of the input buffer |
- Source:
TryDecodeResult
Type:
- Object
Properties:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
message |
Object | Decoded message Properties
|
||||||||||||
error |
Error | ...or decoding error |
||||||||||||
rest |
Buffer | The rest of the input buffer after processing message |
- Source: