new Message(values)
Constructs a new runtime Message.
Parameters:
Name | Type | Description |
---|---|---|
values |
Object.<string,*> | ...[string] | Preset values |
Throws:
- Type
- Error
Members
-
<static> $options :Object.<string,*>
-
Options.
Methods
-
<static> decode(buffer, enc) → {ProtoBuf.Builder.Message}
-
Decodes a message from the specified buffer or string.
Parameters:
Name Type Argument Description buffer
ByteBuffer | !ArrayBuffer | !Buffer | string Buffer to decode from
enc
string <optional>
Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
Throws:
If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error.- Type
- Error
Returns:
Decoded message
-
<static> decode64(str) → {ProtoBuf.Builder.Message}
-
Decodes the message from the specified base64 encoded string.
Parameters:
Name Type Description str
string String to decode from
Throws:
If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error.- Type
- Error
Returns:
Decoded message
-
<static> decodeDelimited(buffer, enc) → {ProtoBuf.Builder.Message}
-
Decodes a varint32 length-delimited message from the specified buffer or string.
Parameters:
Name Type Argument Description buffer
ByteBuffer | !ArrayBuffer | !Buffer | string Buffer to decode from
enc
string <optional>
Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
Throws:
If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error.- Type
- Error
Returns:
Decoded message
-
<static> decodeHex(str) → {ProtoBuf.Builder.Message}
-
Decodes the message from the specified hex encoded string.
Parameters:
Name Type Description str
string String to decode from
Throws:
If the message cannot be decoded or if required fields are missing. The later still returns the decoded message with missing fields in the `decoded` property on the error.- Type
- Error
Returns:
Decoded message
-
$add(key, value, noAssert)
-
Adds a value to a repeated field. This is an alias for ProtoBuf.Builder.Message#add.
Parameters:
Name Type Argument Description key
string Field name
value
* Value to add
noAssert
boolean <optional>
Whether to assert the value or not (asserts by default)
Throws:
If the value cannot be added- Type
- Error
-
$encode(buffer) → {ByteBuffer}
-
Encodes the message.
Parameters:
Name Type Argument Description buffer
!ByteBuffer | boolean <optional>
ByteBuffer to encode to. Will create a new one and flip it if omitted.
- See:
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded ByteBuffer in the `encoded` property on the error.- Type
- Error
Returns:
Encoded message as a ByteBuffer
- Type
- ByteBuffer
-
$set(key, value, noAssert)
-
Sets a field's value. This is an alias for [@link ProtoBuf.Builder.Message#set}.
Parameters:
Name Type Argument Description key
string Key
value
* Value to set
noAssert
boolean <optional>
Whether to assert the value or not (asserts by default)
Throws:
If the value cannot be set- Type
- Error
-
add(key, value, noAssert)
-
Adds a value to a repeated field.
Parameters:
Name Type Argument Description key
string Field name
value
* Value to add
noAssert
boolean <optional>
Whether to assert the value or not (asserts by default)
Throws:
If the value cannot be added- Type
- Error
-
encode(buffer) → {ByteBuffer}
-
Encodes the varint32 length-delimited message.
Parameters:
Name Type Argument Description buffer
!ByteBuffer | boolean <optional>
ByteBuffer to encode to. Will create a new one and flip it if omitted.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded ByteBuffer in the `encoded` property on the error.- Type
- Error
Returns:
Encoded message as a ByteBuffer
- Type
- ByteBuffer
-
encode64() → {string}
-
Directly encodes the message to a base64 encoded string.
Throws:
If the underlying buffer cannot be encoded or if required fields are missing. The later still returns the encoded base64 string in the `encoded` property on the error.- Type
- Error
Returns:
Base64 encoded string
- Type
- string
-
encodeAB() → {ArrayBuffer}
-
Directly encodes the message to an ArrayBuffer.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded ArrayBuffer in the `encoded` property on the error.- Type
- Error
Returns:
Encoded message as ArrayBuffer
- Type
- ArrayBuffer
-
encodeHex() → {string}
-
Directly encodes the message to a hex encoded string.
Throws:
If the underlying buffer cannot be encoded or if required fields are missing. The later still returns the encoded hex string in the `encoded` property on the error.- Type
- Error
Returns:
Hex encoded string
- Type
- string
-
encodeNB() → {Buffer}
-
Directly encodes the message to a node Buffer.
Throws:
If the message cannot be encoded, not running under node.js or if required fields are missing. The later still returns the encoded node Buffer in the `encoded` property on the error.- Type
- Error
Returns:
- Type
- Buffer
-
encodeNB() → {Buffer}
-
Returns the message as a node Buffer. This is an alias for ProtoBuf.Builder.Message#encodeNB.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded node Buffer in the `encoded` property on the error.- Type
- Error
Returns:
- Type
- Buffer
-
get(key) → {*}
-
Gets a field's value.
Parameters:
Name Type Description key
string Key
Throws:
If there is no such field- Type
- Error
Returns:
Value
- Type
- *
-
get(key) → {*}
-
Gets a field's value. This is an alias for ProtoBuf.Builder.Message#$get.
Parameters:
Name Type Description key
string Key
Throws:
If there is no such field- Type
- Error
Returns:
Value
- Type
- *
-
<virtual> get[SomeField]() → {*}
-
Gets a value. This method is present for each field, but only if there is no name conflict with another field.
Returns:
The value
- Type
- *
-
<virtual> get_[some_field]() → {*}
-
Gets a value. This method is present for each field, but only if there is no name conflict with another field.
Returns:
The value
- Type
- *
-
set(key, value, noAssert)
-
Sets a field's value.
Parameters:
Name Type Argument Description key
string Key
value
* Value to set
noAssert
boolean <optional>
Whether to assert the value or not (asserts by default)
Throws:
If the value cannot be set- Type
- Error
-
<virtual> set[SomeField](value)
-
Sets a value. This method is present for each field, but only if there is no name conflict with another field.
Parameters:
Name Type Description value
* Value to set
Throws:
If the value cannot be set- Type
- Error
-
<virtual> set_[some_field](value)
-
Sets a value. This method is present for each field, but only if there is no name conflict with another field.
Parameters:
Name Type Description value
* Value to set
Throws:
If the value cannot be set- Type
- Error
-
toArrayBuffer() → {ArrayBuffer}
-
Returns the message as an ArrayBuffer. This is an alias for ProtoBuf.Builder.Message#encodeAB.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded ArrayBuffer in the `encoded` property on the error.- Type
- Error
Returns:
Encoded message as ArrayBuffer
- Type
- ArrayBuffer
-
toBase64() → {string}
-
Returns the message as a base64 encoded string. This is an alias for ProtoBuf.Builder.Message#encode64.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded base64 string in the `encoded` property on the error.- Type
- Error
Returns:
Base64 encoded string
- Type
- string
-
toHex() → {string}
-
Returns the message as a hex encoded string. This is an alias for ProtoBuf.Builder.Message#encodeHex.
Throws:
If the message cannot be encoded or if required fields are missing. The later still returns the encoded hex string in the `encoded` property on the error.- Type
- Error
Returns:
Hex encoded string
- Type
- string
-
toString() → {string}
-
Returns a string representation of this Message.
Returns:
String representation as of ".Fully.Qualified.MessageName"
- Type
- string