# Class: Builder

## ProtoBuf. Builder

Provides the functionality to build protocol messages.

## Constructor

#### new Builder(optionsopt)

Constructs a new Builder.

##### Parameters:

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

Source:
  - protobuf.js, line 4295

### Classes

Message
Service

### Members

#### files :Array.<string>

Imported files.

##### Type:

- Array.<string>

Source:
  - protobuf.js, line 4330

#### (nullable) importRoot :string

Import root override.

##### Type:

- string

Source:
  - protobuf.js, line 4337

#### ns :ProtoBuf.Reflect.Namespace

Namespace.

##### Type:

- ProtoBuf.Reflect.Namespace

Source:
  - protobuf.js, line 4302

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

Options.

##### Type:

- Object.<string, *>

Source:
  - protobuf.js, line 4344

#### ptr :ProtoBuf.Reflect.T

Namespace pointer.

##### Type:

- ProtoBuf.Reflect.T

Source:
  - protobuf.js, line 4309

#### resolved :boolean

Resolved flag.

##### Type:

- boolean

Source:
  - protobuf.js, line 4316

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

The current building result.

##### Type:

- Object.<string, (ProtoBuf.Builder.Message|Object)> | null

Source:
  - protobuf.js, line 4323

### Methods

#### (static) isEnum(defnon-null) → {boolean}

Tests if a definition most likely describes an enum.

##### Parameters:

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

Source:
  - protobuf.js, line 4390

##### Returns:

Type
  boolean

#### (static) isExtend(defnon-null) → {boolean}

Tests if a definition most likely describes an extended message

##### Parameters:

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

Source:
  - protobuf.js, line 4419

##### Returns:

Type
  boolean

#### (static) isMessage(defnon-null) → {boolean}

Tests if a definition most likely describes a message.

##### Parameters:

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

Source:
  - protobuf.js, line 4361

##### Returns:

Type
  boolean

#### (static) isMessageField(defnon-null) → {boolean}

Tests if a definition most likely describes a message field.

##### Parameters:

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

Source:
  - protobuf.js, line 4377

##### Returns:

Type
  boolean

#### (static) isService(defnon-null) → {boolean}

Tests if a definition most likely describes a service.

##### Parameters:

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

Source:
  - protobuf.js, line 4406

##### Returns:

Type
  boolean

#### "import"](json, filenameopt) → (non-null) {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 4640

##### 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 | Array.<string> | <optional> | Specifies what to return. If omitted, the entire namespace will be returned.

Source:
  - protobuf.js, line 4853

##### Throws:

If a type could not be resolved

Type
  Error

##### Returns:

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

#### create(defsnon-null) → (non-null) {ProtoBuf.Builder}

Creates the specified definitions at the current pointer position.

##### Parameters:

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

Source:
  - protobuf.js, line 4463

##### Throws:

If a message definition is invalid

Type
  Error

##### Returns:

this

Type
  ProtoBuf.Builder

#### define(namespace) → (non-null) {ProtoBuf.Builder}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`namespace` | string |

Source:
  - protobuf.js, line 4444

##### Returns:

this

Type
  ProtoBuf.Builder

#### lookup(pathopt, excludeNonNamespaceopt) → (nullable) {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.
`excludeNonNamespace` | boolean | <optional> | Excludes non-namespace types like fields, defaults to `false`

Source:
  - protobuf.js, line 4881

##### Returns:

Reflection descriptor or `null` if not found

Type
  ProtoBuf.Reflect.T

#### reset() → (non-null) {ProtoBuf.Builder}

Resets the pointer to the root namespace.

Source:
  - protobuf.js, line 4433

##### Returns:

this

Type
  ProtoBuf.Builder

#### resolveAll() → (non-null) {ProtoBuf.Builder}

Resolves all namespace objects.

Source:
  - protobuf.js, line 4769

##### Throws:

If a type cannot be resolved

Type
  Error

##### Returns:

this

Type
  ProtoBuf.Builder

#### toString() → {string}

Returns a string representation of this object.

Source:
  - protobuf.js, line 4890

##### Returns:

String representation as of "Builder"

Type
  string