Class: Message

ProtoBuf.Builder. Message

Barebone of all runtime messages.

new Message(values, …var_args)

Constructs a new runtime Message.

Parameters:
Name Type Attributes Description
values !Object.<string, *> | string

Preset values

var_args string <repeatable>
Source:
Throws:
If the message cannot be created
Type
Error

Members

(static) $options :Object.<string, *>

Message options.

Type:
  • Object.<string, *>
Source:

(static, non-null) $type :ProtoBuf.Reflect.Message

Reflection type.

Type:
Source:

$options :Object.<string, *>

Message options.

Type:
  • Object.<string, *>
Source:

(non-null) $type :ProtoBuf.Reflect.Message

Reflection type.

Type:
Source:

Methods

(static) decode(buffer, encopt) → (non-null) {ProtoBuf.Builder.Message}

Decodes a message from the specified buffer or string.

Parameters:
Name Type Attributes 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

Source:
See:
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

Type
ProtoBuf.Builder.Message

(static) decode64(str) → (non-null) {ProtoBuf.Builder.Message}

Decodes the message from the specified base64 encoded string.

Parameters:
Name Type Description
str string

String to decode from

Source:
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

Type
ProtoBuf.Builder.Message

(static) decodeDelimited(buffer, encopt) → {ProtoBuf.Builder.Message}

Decodes a varint32 length-delimited message from the specified buffer or string.

Parameters:
Name Type Attributes 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

Source:
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 or null if not enough bytes are available yet

Type
ProtoBuf.Builder.Message

(static) decodeHex(str) → (non-null) {ProtoBuf.Builder.Message}

Decodes the message from the specified hex encoded string.

Parameters:
Name Type Description
str string

String to decode from

Source:
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

Type
ProtoBuf.Builder.Message

(static) decodeJSON(str) → (non-null) {ProtoBuf.Builder.Message}

Decodes the message from a JSON string.

Parameters:
Name Type Description
str string

String to decode from

Source:
Throws:
If the message cannot be decoded or if required fields are missing.
Type
Error
Returns:

Decoded message

Type
ProtoBuf.Builder.Message

$add(key, value, noAssertopt) → (non-null) {ProtoBuf.Builder.Message}

Adds a value to a repeated field. This is an alias for ProtoBuf.Builder.Message#add.

Parameters:
Name Type Attributes Description
key string

Field name

value *

Value to add

noAssert boolean <optional>

Whether to assert the value or not (asserts by default)

Source:
Throws:
If the value cannot be added
Type
Error
Returns:

this

Type
ProtoBuf.Builder.Message

$encode(bufferopt, noVerifyopt) → (non-null) {ByteBuffer}

Encodes the message.

Parameters:
Name Type Attributes Description
buffer ByteBuffer | boolean <optional>

ByteBuffer to encode to. Will create a new one and flip it if omitted.

noVerify boolean <optional>

Whether to not verify field values, defaults to false

Source:
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

$get(key) → {*}

Gets a field's value. This is an alias for ProtoBuf.Builder.Message#$get.

Parameters:
Name Type Description
key string

Key

Source:
Throws:
If there is no such field
Type
Error
Returns:

Value

Type
*

$set(keyOrObj, valueopt, noAssertopt)

Sets a field's value. This is an alias for [@link ProtoBuf.Builder.Message#set}.

Parameters:
Name Type Attributes Description
keyOrObj string | !Object.<string, *>

String key or plain object holding multiple values

value * | boolean <optional>

Value to set if key is a string, otherwise omitted

noAssert boolean <optional>

Whether to not assert the value, defaults to false

Source:
Throws:
If the value cannot be set
Type
Error

add(key, value, noAssertopt) → (non-null) {ProtoBuf.Builder.Message}

Adds a value to a repeated field.

Parameters:
Name Type Attributes Description
key string

Field name

value *

Value to add

noAssert boolean <optional>

Whether to assert the value or not (asserts by default)

Source:
Throws:
If the value cannot be added
Type
Error
Returns:

this

Type
ProtoBuf.Builder.Message

calculate() → {number}

Calculates the byte length of the message.

Source:
Throws:
If the message cannot be calculated or if required fields are missing.
Type
Error
Returns:

Byte length

Type
number

encode64() → {string}

Directly encodes the message to a base64 encoded string.

Source:
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.

Source:
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

encodeDelimited(bufferopt) → (non-null) {ByteBuffer}

Encodes the varint32 length-delimited message.

Parameters:
Name Type Attributes Description
buffer ByteBuffer | boolean <optional>

ByteBuffer to encode to. Will create a new one and flip it if omitted.

Source:
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

encodeHex() → {string}

Directly encodes the message to a hex encoded string.

Source:
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

encodeJSON() → {string}

Encodes a message to JSON.

Source:
Returns:

JSON string

Type
string

encodeNB() → (non-null) {Buffer}

Directly encodes the message to a node Buffer.

Source:
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

get(key, noAssertopt) → {*}

Gets a field's value.

Parameters:
Name Type Attributes Description
key string

Key

noAssert boolean <optional>

Whether to not assert for an actual field, defaults to false

Source:
Throws:
If there is no such field
Type
Error
Returns:

Value

Type
*

(abstract) get[SomeField]() → {*}

Gets a value. This method is present for each field, but only if there is no name conflict with another field.

Source:
Returns:

The value

Type
*

(abstract) get_[some_field]() → {*}

Gets a value. This method is present for each field, but only if there is no name conflict with another field.

Source:
Returns:

The value

Type
*

set(keyOrObj, valueopt, noAssertopt) → (non-null) {ProtoBuf.Builder.Message}

Sets a field's value.

Parameters:
Name Type Attributes Description
keyOrObj string | !Object.<string, *>

String key or plain object holding multiple values

value * | boolean <optional>

Value to set if key is a string, otherwise omitted

noAssert boolean <optional>

Whether to not assert for an actual field / proper value type, defaults to false

Source:
Throws:
If the value cannot be set
Type
Error
Returns:

this

Type
ProtoBuf.Builder.Message

(abstract) set[SomeField](value, noAssertopt) → (non-null) {ProtoBuf.Builder.Message}

Sets a value. This method is present for each field, but only if there is no name conflict with another field.

Parameters:
Name Type Attributes Description
value *

Value to set

noAssert boolean <optional>

Whether to not assert the value, defaults to false

Source:
Throws:
If the value cannot be set
Type
Error
Returns:

this

Type
ProtoBuf.Builder.Message

(abstract) set_[some_field](value, noAssertopt) → (non-null) {ProtoBuf.Builder.Message}

Sets a value. This method is present for each field, but only if there is no name conflict with another field.

Parameters:
Name Type Attributes Description
value *

Value to set

noAssert boolean <optional>

Whether to not assert the value, defaults to false

Source:
Throws:
If the value cannot be set
Type
Error
Returns:

this

Type
ProtoBuf.Builder.Message

toArrayBuffer() → {ArrayBuffer}

Returns the message as an ArrayBuffer. This is an alias for ProtoBuf.Builder.Message#encodeAB.

Source:
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.

Source:
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

toBuffer() → (non-null) {Buffer}

Returns the message as a node Buffer. This is an alias for ProtoBuf.Builder.Message#encodeNB.

Source:
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

toHex() → {string}

Returns the message as a hex encoded string. This is an alias for ProtoBuf.Builder.Message#encodeHex.

Source:
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

toRaw(binaryAsBase64opt, longsAsStrings) → {Object.<string, *>}

Returns the message's raw payload.

Parameters:
Name Type Attributes Description
binaryAsBase64 boolean <optional>

Whether to include binary data as base64 strings instead of Buffers, defaults to false

longsAsStrings boolean

Whether to encode longs as strings

Source:
Returns:

Raw payload

Type
Object.<string, *>

toString() → {string}

Returns a string representation of this Message.

Source:
Returns:

String representation as of ".Fully.Qualified.MessageName"

Type
string