# Class: Builder

## ProtoBuf. Builder

Provides the functionality to build protocol messages.

#### new Builder()

  Constructs a new Builder.

### Classes

Message
Service

### Members

#### files :Array.<string>

  Imported files.

#### importRoot :string

  Import root override.

#### ns :ProtoBuf.Reflect.Namespace

  Namespace.

#### ptr :ProtoBuf.Reflect.T

  Namespace pointer.

#### resolved :boolean

  Resolved flag.

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

  The current building result.

### Methods

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

  Tests if a definition is a valid enum definition.

  ##### Parameters:

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

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

  ##### Returns:

  true if valid, else false

  Type
    boolean

#### <static> isValidImport(filename) → {boolean}

  Tests if the specified file is a valid import.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `filename` | string |

  ##### Returns:

  true if valid, false if it should be skipped

  Type
    boolean

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

  Tests if a definition is a valid message definition.

  ##### Parameters:

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

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

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

  ##### Returns:

  true if valid, else false

  Type
    boolean

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

  Imports another definition into this builder.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `json` | Object.<string,*> |  | Parsed import
  `filename` | string | {root: string, file: string} | <optional> | Imported file name

  ##### Throws:

  If the definition or file cannot be imported
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

#### build(path) → {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 | Argument | Description
  --- | --- | --- | ---
  `path` | string | <optional> | Specifies what to return. If omitted, the entire namespace will be returned.

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

  ##### Throws:

  If a message definition is invalid
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

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

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

  ##### Parameters:

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

  ##### Throws:

  If the package name is invalid
  Type
    Error

  ##### Returns:

  this

  Type
    ProtoBuf.Builder

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

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

  ##### Parameters:

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

  ##### Returns:

  Reflection descriptor or `null` if not found

  Type
    ProtoBuf.Reflect.T

#### reset()

  Resets the pointer to the global namespace.

#### resolveAll()

  Resolves all namespace objects.

  ##### Throws:

  If a type cannot be resolved
  Type
    Error

#### toString() → {string}

  Returns a string representation of this object.

  ##### Returns:

  String representation as of "Builder"

  Type
    string