# Class: Message

## ProtoBuf.Builder. Message

Barebone of all runtime messages.

#### new Message(values)

  Constructs a new runtime Message.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `values` | Object.<string,*> | ...[string] | Preset values

  ##### Throws:

  If the message cannot be created
  Type
    Error

### Members

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

  Options.

### Methods

#### <static> decode(buffer, enc) → {ProtoBuf.Builder.Message}

  Decodes the 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

  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) → {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

  Type
    ProtoBuf.Builder.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

  Type
    ProtoBuf.Builder.Message

#### add(key, value)

  Adds a value to a repeated field.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | Field name
  `value` | * | Value to add

  ##### 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 if omitted.

  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

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

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

  Sets a field value.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key
  `value` | * | Value to set

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