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

  ##### Throws:

  If the message cannot be created
  Type
    Error

### Members

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

  Message options.

  ##### Type:

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

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

  Reflection type.

  ##### Type:

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

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

  Message options.

  ##### Type:

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

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

  Reflection type.

  ##### Type:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  ##### Returns:

  JSON string

  Type
    string

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

  Directly encodes the message to a node Buffer.

  Source:
    - ProtoBuf.js, line 2708

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

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

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

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

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

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

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

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

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

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

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

  ##### Returns:

  Raw payload

  Type
    Object.<string, *>

#### toString() → {string}

  Returns a string representation of this Message.

  Source:
    - ProtoBuf.js, line 2982

  ##### Returns:

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

  Type
    string