# Class: Field

## ProtoBuf.Reflect.Message. Field

#### new Field(buildernon-null, messagenon-null, rule, keytypenullable, type, name, id, optionsopt, oneofopt, non-null, syntaxnullable)

  Constructs a new Message Field.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `builder` | ProtoBuf.Builder |  | Builder reference
  `message` | ProtoBuf.Reflect.Message |  | Message reference
  `rule` | string |  | Rule, one of requried, optional, repeated
  `keytype` | string | <nullable> | Key data type, if any.
  `type` | string |  | Data type, e.g. int32
  `name` | string |  | Field name
  `id` | number |  | Unique field id
  `options` | Object.<string, *> | <optional> | Options
  `oneof` | ProtoBuf.Reflect.Message.OneOf | <optional> | Enclosing OneOf
  `syntax` | string | <nullable> | The syntax level of this definition (e.g., proto3)

  Source:
    - ProtoBuf.js, line 3250

### Extends

- ProtoBuf.Reflect.T

### Members

#### (non-null) builder :ProtoBuf.Builder

  Builder reference.

  ##### Type:

  - ProtoBuf.Builder
  Inherited From:
    - ProtoBuf.Reflect.T#builder
  Source:
    - ProtoBuf.js, line 1382

#### className

  Source:
    - ProtoBuf.js, line 3256

#### defaultValue :*

  Default value.

  ##### Type:

  - *
  Source:
    - ProtoBuf.js, line 3322

#### element :ProtoBuf.Element

  Element implementation. Created in build() after types are resolved.

  ##### Type:

  - ProtoBuf.Element
  Source:
    - ProtoBuf.js, line 3350

#### id :number

  Unique message field id.

  ##### Type:

  - number
  Source:
    - ProtoBuf.js, line 3307

#### keyElement :ProtoBuf.Element

  Key element implementation, for map fields. Created in build() after types are resolved.

  ##### Type:

  - ProtoBuf.Element
  Source:
    - ProtoBuf.js, line 3358

#### keyType :string|Object|null

  Message field key type. Type reference string if unresolved, protobuf type if resolved. Valid only if this.map === true, null otherwise.

  ##### Type:

  - string | Object | null
  Source:
    - ProtoBuf.js, line 3285

#### map :boolean

  Message field map flag.

  ##### Type:

  - boolean
  Source:
    - ProtoBuf.js, line 3277

#### name :string

  Object name in namespace.

  ##### Type:

  - string
  Inherited From:
    - ProtoBuf.Reflect.T#name
  Source:
    - ProtoBuf.js, line 1396

#### (nullable) oneof :ProtoBuf.Reflect.Message.OneOf

  Enclosing OneOf.

  ##### Type:

  - ProtoBuf.Reflect.Message.OneOf
  Source:
    - ProtoBuf.js, line 3329

#### (non-null) options :Object.<string, *>

  Message field options.

  ##### Type:

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

#### originalName :string

  Original field name.

  ##### Type:

  - string
  Source:
    - ProtoBuf.js, line 3343

#### (nullable) parent :ProtoBuf.Reflect.T

  Parent object.

  ##### Type:

  - ProtoBuf.Reflect.T
  Inherited From:
    - ProtoBuf.Reflect.T#parent
  Source:
    - ProtoBuf.js, line 1389

#### repeated :boolean

  Message field repeated flag.

  ##### Type:

  - boolean
  Source:
    - ProtoBuf.js, line 3270

#### required :boolean

  Message field required flag.

  ##### Type:

  - boolean
  Source:
    - ProtoBuf.js, line 3263

#### resolvedType :ProtoBuf.Reflect.T|null

  Resolved type reference inside the global namespace.

  ##### Type:

  - ProtoBuf.Reflect.T | null
  Source:
    - ProtoBuf.js, line 3300

#### syntax :string

  Syntax level of this definition (e.g., proto3).

  ##### Type:

  - string
  Source:
    - ProtoBuf.js, line 3336

#### type :string|Object

  Message field type. Type reference string if unresolved, protobuf type if resolved. In a map field, this is the value type.

  ##### Type:

  - string | Object
  Source:
    - ProtoBuf.js, line 3293

### Methods

#### build()

  Builds the field.

  Source:
    - ProtoBuf.js, line 3376

#### calculate(value, messagenon-null) → {number}

  Calculates the length of this field's value on the network level.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `value` | * | Field value
  `message` | ProtoBuf.Builder.Message | Runtime message

  Source:
    - ProtoBuf.js, line 3572

  ##### Returns:

  Byte length

  Type
    number

#### decode(wireType, buffer, skipRepeatedopt) → {*}

  Decode the field value from the specified buffer.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `wireType` | number |  | Leading wire type
  `buffer` | ByteBuffer |  | ByteBuffer to decode from
  `skipRepeated` | boolean | <optional> | Whether to skip the repeated check or not. Defaults to false.

  Source:
    - ProtoBuf.js, line 3630

  ##### Throws:

  If the field cannot be decoded
  Type
    Error

  ##### Returns:

  Decoded value: array for packed repeated fields, [key, value] for map fields, or an individual value otherwise.

  Type
    *

#### encode(value, buffer, messagenon-null) → {ByteBuffer}

  Encodes the specified field value to the specified buffer.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `value` | * | Verified field value
  `buffer` | ByteBuffer | ByteBuffer to encode to
  `message` | ProtoBuf.Builder.Message | Runtime message

  Source:
    - ProtoBuf.js, line 3498

  ##### Throws:

  If the field cannot be encoded
  Type
    Error

  ##### Returns:

  The ByteBuffer for chaining

  Type
    ByteBuffer

#### fqn() → {string}

  Returns the fully qualified name of this object.

  Inherited From:
    - ProtoBuf.Reflect.T#fqn
  Source:
    - ProtoBuf.js, line 1417

  ##### Returns:

  Fully qualified name as of ".PATH.TO.THIS"

  Type
    string

#### hasWirePresence(value, messagenon-null) → {boolean}

  Determines whether the field will have a presence on the wire given its value.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `value` | * | Verified field value
  `message` | ProtoBuf.Builder.Message | Runtime message

  Source:
    - ProtoBuf.js, line 3446

  ##### Returns:

  Whether the field will be present on the wire

  Type
    boolean

#### toString(includeClassopt)

  Returns a string representation of this Reflect object (its fully qualified name).

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `includeClass` | boolean | <optional> | Set to true to include the class name. Defaults to false.

  Inherited From:
    - ProtoBuf.Reflect.T#toString
  Source:
    - ProtoBuf.js, line 1435

  ##### Returns:

  String representation

#### verifyValue(value, skipRepeatedopt) → {*}

  Checks if the given value can be set for this field.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `value` | * |  | Value to check
  `skipRepeated` | boolean | <optional> | Whether to skip the repeated value check or not. Defaults to false.

  Source:
    - ProtoBuf.js, line 3399

  ##### Throws:

  If the value cannot be set for this field
  Type
    Error

  ##### Returns:

  Verified, maybe adjusted, value

  Type
    *