# Class: Builder

## ProtoBuf. Builder

Provides the functionality to build protocol messages.

#### new Builder(optionsopt)

  Constructs a new Builder.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `options` | Object.<string, *> | <optional> | Options

  Source:
    - ProtoBuf.js, line 3598

### Classes

Message
Service

### Members

#### files :Array.<string>

  Imported files.

  ##### Type:

  - Array.<string>
  Source:
    - ProtoBuf.js, line 3633

#### (nullable) importRoot :string

  Import root override.

  ##### Type:

  - string
  Source:
    - ProtoBuf.js, line 3640

#### ns :ProtoBuf.Reflect.Namespace

  Namespace.

  ##### Type:

  - ProtoBuf.Reflect.Namespace
  Source:
    - ProtoBuf.js, line 3605

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

  Options.

  ##### Type:

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

#### ptr :ProtoBuf.Reflect.T

  Namespace pointer.

  ##### Type:

  - ProtoBuf.Reflect.T
  Source:
    - ProtoBuf.js, line 3612

#### resolved :boolean

  Resolved flag.

  ##### Type:

  - boolean
  Source:
    - ProtoBuf.js, line 3619

#### result :Object.<string, (ProtoBuf.Builder.Message|Object)>|null

  The current building result.

  ##### Type:

  - Object.<string, (ProtoBuf.Builder.Message|Object)> | null
  Source:
    - ProtoBuf.js, line 3626

### Methods

#### (static) isValidEnum(def) → {boolean}

  Tests if a definition is a valid enum definition.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `def` | Object | Definition

  Source:
    - ProtoBuf.js, line 3767

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### (static) isValidExtend(def) → {boolean}

  Tests if a definition is a valid extension.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `def` | Object | Definition

  Source:
    - ProtoBuf.js, line 4042

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### (static) isValidMessage(def) → {boolean}

  Tests if a definition is a valid message definition.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `def` | Object.<string, *> | Definition

  Source:
    - ProtoBuf.js, line 3693

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### (static) isValidMessageField(def) → {boolean}

  Tests if a definition is a valid message field definition.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `def` | Object | Definition

  Source:
    - ProtoBuf.js, line 3742

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### (static) isValidService(def) → {boolean}

  Tests if a definition is a valid service definition.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `def` | Object | Definition

  Source:
    - ProtoBuf.js, line 4031

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### "import"](json, filenameopt) → {ProtoBuf.Builder}

  Imports another definition into this builder.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `json` | Object.<string, *> |  | Parsed import
  `filename` | string | Object | <optional> | Imported file name

  Source:
    - ProtoBuf.js, line 3934

  ##### Throws:

  If the definition or file cannot be imported
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

#### build(pathopt) → {ProtoBuf.Builder.Message|Object.<string, *>}

  Builds the protocol. This will first try to resolve all definitions and, if this has been successful, return the built package.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `path` | string | <optional> | Specifies what to return. If omitted, the entire namespace will be returned.

  Source:
    - ProtoBuf.js, line 4124

  ##### Throws:

  If a type could not be resolved
  Type
    Error

  ##### Returns:

  Type
    ProtoBuf.Builder.Message | Object.<string, *>

#### create(defs) → {ProtoBuf.Builder}

  Creates ths specified protocol types at the current pointer position.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `defs` | Array.<Object.<string, *>> | Messages, enums or services to create

  Source:
    - ProtoBuf.js, line 3795

  ##### Throws:

  If a message definition is invalid
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

#### define(pkg, optionsopt) → {ProtoBuf.Builder}

  Defines a package on top of the current pointer position and places the pointer on it.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `pkg` | string |  |
  `options` | Object.<string, *> | <optional> |

  Source:
    - ProtoBuf.js, line 3672

  ##### Throws:

  If the package name is invalid
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

#### lookup(pathopt) → {ProtoBuf.Reflect.T}

  Similar to ProtoBuf.Builder#build, but looks up the internal reflection descriptor.

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `path` | string | <optional> | Specifies what to return. If omitted, the entire namespace wiil be returned.

  Source:
    - ProtoBuf.js, line 4153

  ##### Returns:

  Reflection descriptor or `null` if not found

  Type
    ProtoBuf.Reflect.T

#### reset()

  Resets the pointer to the root namespace.

  Source:
    - ProtoBuf.js, line 3660

#### resolveAll()

  Resolves all namespace objects.

  Source:
    - ProtoBuf.js, line 4068

  ##### Throws:

  If a type cannot be resolved
  Type
    Error

#### toString() → {string}

  Returns a string representation of this object.

  Source:
    - ProtoBuf.js, line 4162

  ##### Returns:

  String representation as of "Builder"

  Type
    string