# Class: Message

## ProtoBuf .Builder. Message

Barebone of all runtime messages.

## Constructor

#### 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:
  - protobuf.js, line 2375

##### Throws:

If the message cannot be created

Type
  Error

### Members

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

Message options.

##### Type:

- Object.<string, *>

Source:
  - protobuf.js, line 3052

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

Reflection type.

##### Type:

- ProtoBuf.Reflect.Message

Source:
  - protobuf.js, line 3068

#### $options :Object.<string, *>

Message options.

##### Type:

- Object.<string, *>

Source:
  - protobuf.js, line 3060

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

Reflection type.

##### Type:

- ProtoBuf.Reflect.Message

Source:
  - protobuf.js, line 3076

### Methods

#### (static) decode(buffer, lengthopt, 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
`length` | number | string | <optional> | Message length. Defaults to decode all the remainig data.
`enc` | string | <optional> | Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64

Source:
  - protobuf.js, line 2928
See:
  - ProtoBuf.Builder.Message.decode64
  - ProtoBuf.Builder.Message.decodeHex

##### 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:
  - protobuf.js, line 2995

##### 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:
  - protobuf.js, line 2961

##### 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:
  - protobuf.js, line 3009

##### 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:
  - protobuf.js, line 3023

##### 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:
  - protobuf.js, line 2453

##### 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:
  - protobuf.js, line 2651
See:
  - ProtoBuf.Builder.Message#encode64
  - ProtoBuf.Builder.Message#encodeHex
  - ProtoBuf.Builder.Message#encodeAB

##### 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:
  - protobuf.js, line 2541

##### 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:
  - protobuf.js, line 2508

##### 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:
  - protobuf.js, line 2425

##### 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:
  - protobuf.js, line 2695

##### 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:
  - protobuf.js, line 2788

##### 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:
  - protobuf.js, line 2730

##### 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, noVerifyopt) → (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.
`noVerify` | boolean | <optional> | Whether to not verify field values, defaults to `false`

Source:
  - protobuf.js, line 2707

##### 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:
  - protobuf.js, line 2817

##### 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:
  - protobuf.js, line 2918

##### Returns:

JSON string

Type
  string

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

Directly encodes the message to a node Buffer.

Source:
  - protobuf.js, line 2759

##### 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:
  - protobuf.js, line 2520

##### 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:
  - protobuf.js, line 2625

##### 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:
  - protobuf.js, line 2636

##### 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:
  - protobuf.js, line 2466

##### 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:
  - protobuf.js, line 2597

##### 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:
  - protobuf.js, line 2611

##### 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:
  - protobuf.js, line 2748

##### 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:
  - protobuf.js, line 2806

##### 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:
  - protobuf.js, line 2777

##### 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:
  - protobuf.js, line 2835

##### 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:
  - protobuf.js, line 2909

##### Returns:

Raw payload

Type
  Object.<string, *>

#### toString() → {string}

Returns a string representation of this Message.

Source:
  - protobuf.js, line 3039

##### Returns:

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

Type
  string