# 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:
    - ProtoBuf.js, line 1692

  ##### Throws:

  If the message cannot be created
  Type
    Error

### Members

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

  Options.

  ##### Type:

  - Object.<string, *>
  Source:
    - ProtoBuf.js, line 2275

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

  Reflection type.

  ##### Type:

  - ProtoBuf.Reflect.Message
  Source:
    - ProtoBuf.js, line 2283

### 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:
    - ProtoBuf.js, line 2171
  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 2232

  ##### 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 2199

  ##### 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 2246

  ##### 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

#### $add(key, value, noAssertopt)

  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 1763

  ##### Throws:

  If the value cannot be added
  Type
    Error

#### $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 1957
  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 1847

  ##### Throws:

  If there is no such field
  Type
    Error

  ##### Returns:

  Value

  Type
    *

#### $set(key, value, noAssertopt)

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

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `key` | string |  | Key
  `value` | * |  | Value to set
  `noAssert` | boolean | <optional> | Whether to not assert the value, defaults to `false`

  Source:
    - ProtoBuf.js, line 1814

  ##### Throws:

  If the value cannot be set
  Type
    Error

#### add(key, value, noAssertopt)

  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 1738

  ##### Throws:

  If the value cannot be added
  Type
    Error

#### calculate() → {number}

  Calculates the byte length of the message.

  Source:
    - ProtoBuf.js, line 1989

  ##### 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 2081

  ##### 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 2023

  ##### 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:
    - ProtoBuf.js, line 2001

  ##### 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 2110

  ##### 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() → (non-null) {Buffer}

  Directly encodes the message to a node Buffer.

  Source:
    - ProtoBuf.js, line 2052

  ##### 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 1826

  ##### 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 1930

  ##### 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 1941

  ##### Returns:

  The value

  Type
    *

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

  Sets a field's value.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `key` | string |  | Key
  `value` | * |  | Value to set
  `noAssert` | boolean | <optional> | Whether to not assert for an actual field / proper value type, defaults to `false`

  Source:
    - ProtoBuf.js, line 1775

  ##### 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 1902

  ##### 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 1916

  ##### 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 2041

  ##### 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 2099

  ##### 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 2070

  ##### 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 2128

  ##### 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(includeBinaryAsBase64opt) → {Object.<string, *>}

  Returns the message's raw payload.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `includeBinaryAsBase64` | boolean | <optional> | Whether to include binary data as base64 strings or not, defaults to `false`

  Source:
    - ProtoBuf.js, line 2167

  ##### Returns:

  Raw payload

  Type
    Object.<string, *>

#### toString() → {string}

  Returns a string representation of this Message.

  Source:
    - ProtoBuf.js, line 2262

  ##### Returns:

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

  Type
    string