Class: Field

Field

Reflected message field.

new Field(name, id, type, rule, extend, options)

Constructs a new message field instance. Note that map fields have their own class.

Parameters:
name string

Unique name within its namespace

id number

Unique id within its namespace

type string

Value type

rule string | Object.<string, *> "optional" optional

Field rule

extend string | Object.<string, *> optional

Extended type if different from parent

options Object.<string, *> optional

Declared options

Extends

Members

bytes { boolean }

Whether this field's value is a buffer.

comment { string | null }

Comment for this field.

declaringField { Field | null }

Sister-field within the declaring namespace if an extended field.

defaultValue { * }

The field's default value on prototypes.

delimited readonly{ boolean }

Determines whether this field uses tag-delimited encoding. In proto2 this
corresponded to group syntax.

extend { string | undefined }

Extended type if different from parent.

extensionField { Field | null }

Sister-field within the extended type if a declaring extension field.

filename { string | null }

Defining file name.

fullName readonly{ string }

Full name including leading dot.

hasPresence readonly{ boolean }

Determines whether this field tracks presence.

id { number }

Unique field id.

long { boolean }

Whether this field's value should be treated as a long.

map { boolean }

Whether this field is a map or not.

message { Type | null }

Message this field belongs to.

name { string }

Unique name within its namespace.

optional readonly{ boolean }

Determines whether this field is not required.

options { Object<string, *> | undefined }

Options.

packed readonly{ boolean }

Determines whether this field is packed. Only relevant when repeated.

parent { Namespace | null }

Parent namespace.

parsedOptions { Object<string, *>[] | undefined }

Parsed Options.

partOf { OneOf | null }

OneOf this field belongs to, if any,

repeated { boolean }

Whether this field is repeated.

required readonly{ boolean }

Determines whether this field is required.

resolved { boolean }

Whether already resolved or not.

resolvedType { Type | Enum | null }

Resolved type if not a basic type.

root readonly{ Root }

Reference to the root namespace.

type { string }

Field type.

typeDefault { * }

The field type's default value.

Methods

inherited getOption(name){ * }

Gets an option value.

Parameters:
name string

Option name

Returns:
* Option value or undefined if not set

inherited onAdd(parent){ undefined }

Called when this object is added to a parent.

Parameters:
parent ReflectionObject

Parent added to

Returns:
undefined

inherited onRemove(parent){ undefined }

Called when this object is removed from a parent.

Parameters:
parent ReflectionObject

Parent removed from

Returns:
undefined

inherited resolve(){ Field }

Resolves this field's type references.

Throws:
Error

If any reference cannot be resolved

Returns:
Field this

inherited setOptions(options, ifNotSet){ ReflectionObject }

Sets multiple options.

Parameters:
options Object.<string, *>

Options to set

ifNotSet boolean optional

Sets an option only if it isn't currently set

Returns:
ReflectionObject this

inherited setParsedOption(name, value, propName){ ReflectionObject }

Sets a parsed option.

Parameters:
name string

parsed Option name

value *

Option value

propName string

dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value

Returns:
ReflectionObject this

inherited toJSON(toJSONOptions){ IField }

Converts this field to a field descriptor.

Parameters:
toJSONOptions IToJSONOptions optional

JSON conversion options

Returns:
IField Field descriptor

inherited toString(){ string }

Converts this instance to its string representation.

Returns:
string Class name[, space, full name]

Field.d(fieldId, fieldType, fieldRule, defaultValue){ FieldDecorator }

Field decorator (TypeScript).

Parameters:
fieldId number

Field id

fieldType "double" | "float" | "int32" | "uint32" | "sint32" | "fixed32" | "sfixed32" | "int64" | "uint64" | "sint64" | "fixed64" | "sfixed64" | "string" | "bool" | "bytes" | Object

Field type

fieldRule "optional" | "required" | "repeated" "optional" optional

Field rule

defaultValue T optional

Default value

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
Returns:
FieldDecorator Decorator function

Field.d(2)(fieldId, fieldType, fieldRule){ FieldDecorator }

Field decorator (TypeScript).

Parameters:
fieldId number

Field id

fieldType Constructor.<T> | string

Field type

fieldRule "optional" | "required" | "repeated" "optional" optional

Field rule

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
Returns:
FieldDecorator Decorator function

Field.fromJSON(name, json){ Field }

Constructs a field from a field descriptor.

Parameters:
name string

Field name

json IField

Field descriptor

Throws:
TypeError

If arguments are invalid

Returns:
Field Created field