FieldGen

nscn.polaris2.protoc.codegen.FieldGen
final class FieldGen(val fd: FieldDescriptor, val ctx: GenContext)

One field, with every decision the printers need already made.

The reason this is a class rather than a pile of functions on FieldDescriptor is that most of the decisions - presence, packing, the Scala type, whether a TypeMapper is in play - are interdependent, and computing them once keeps the printers free of conditionals.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def baseAccessorName: String

The name of the per-instance cache of this field's base value.

The name of the per-instance cache of this field's base value.

Attributes

def isMessageLike: Boolean
Extension method from nscn.polaris2.protoc.codegen

Whether the field's element is a message, generated here or protobuf's own.

Whether the field's element is a message, generated here or protobuf's own.

Attributes

def isNonDefault(expr: String): String

The test that decides whether an implicit-presence field is written.

The test that decides whether an implicit-presence field is written.

Floats compare by raw bits rather than by value, because -0.0 == 0.0 and a value comparison would silently drop the sign of a negative zero.

Attributes

def readCustomOf(input: String): String

Reads one element and maps it to the field's Scala type.

Reads one element and maps it to the field's Scala type.

Attributes

def readOf(input: String): String

Reads one base-typed element.

Reads one base-typed element.

Attributes

def sizeNoTagOf(baseExpr: String): String

Size of one element without its tag, for the packed encoding.

Size of one element without its tag, for the packed encoding.

Attributes

def sizeOf(baseExpr: String): String

Size of one element including its tag, given an expression for the base value.

Size of one element including its tag, given an expression for the base value.

Attributes

def toBase(customExpr: String): String

Converts a Scala-typed expression back to the base type.

Converts a Scala-typed expression back to the base type.

Attributes

def writeNoTagOf(output: String, baseExpr: String): String
def writeOf(output: String, baseExpr: String): String

Writes one element, tag included.

Writes one element, tag included.

Attributes

def zeroValue: String
Extension method from nscn.polaris2.protoc.codegen

A value to give the field in defaultInstance when it has no constructor default.

A value to give the field in defaultInstance when it has no constructor default.

Only reached for a required or no_box field: those deliberately have no default in the constructor, so that forgetting one is a compile error, but defaultInstance still has to produce something.

Attributes

Concrete fields

val alternateTag: Option[Int]

The other tag a parser must also accept for a packable repeated field.

The other tag a parser must also accept for a packable repeated field.

protobuf requires readers to accept both encodings whatever the schema says, because the schema may have changed since the bytes were written.

Attributes

val baseType: String

The Scala type of one element at the proto level, before any mapping.

The Scala type of one element at the proto level, before any mapping.

Attributes

val containingOneof: Option[OneofDescriptor]
lazy val declaredType: String

The field's declared Scala type, collections and Option included.

The field's declared Scala type, collections and Option included.

Attributes

lazy val defaultValue: Option[String]

The default for the constructor parameter, or None when there must not be one.

The default for the constructor parameter, or None when there must not be one.

Attributes

val elementType: String

The Scala type of one element as it appears in the generated API.

The Scala type of one element as it appears in the generated API.

Attributes

val failIfMissing: Boolean

Whether parsing must fail when the field is absent.

Whether parsing must fail when the field is absent.

Attributes

val fd: FieldDescriptor
val hasPresence: Boolean

Whether the field tracks presence, i.e. whether its Scala type is an Option.

Whether the field tracks presence, i.e. whether its Scala type is an Option.

Asks the descriptor rather than the syntax. hasPresence is resolved from the edition's field_presence feature for an editions file, from optional/required for proto2 and from the optional keyword for proto3, so one question covers all three.

Attributes

lazy val isBoxed: Boolean

Whether the field's Scala type is wrapped in Option.

Whether the field's Scala type is wrapped in Option.

Presence is necessary but not sufficient. A required field has presence - protobuf tracks whether it was set, and rejects a message where it was not - yet wrapping it would be backwards: the whole point is that it is always there. It gets a bare type and no constructor default instead, so omitting it is a compile error. no_box says the same thing for a field the schema cannot mark required.

Attributes

val isInOneof: Boolean
val isMap: Boolean
val isPacked: Boolean

Whether a repeated field uses the packed encoding, resolved from the features.

Whether a repeated field uses the packed encoding, resolved from the features.

Attributes

val isRepeated: Boolean
val isRequired: Boolean

proto2's required, and editions' LEGACY_REQUIRED.

proto2's required, and editions' LEGACY_REQUIRED.

Attributes

lazy val mapKey: Option[FieldGen]
lazy val mapValue: Option[FieldGen]
val mapper: Option[String]

The TypeMapper expression, when the element's Scala type is not the base type.

The TypeMapper expression, when the element's Scala type is not the base type.

Attributes

val needsBaseAccessor: Boolean
val number: Int
val protoName: String
val scalaName: String

The Scala name, from (field).scala_name or the camel-cased proto name.

The Scala name, from (field).scala_name or the camel-cased proto name.

Attributes

val tag: Int

The tag protoc writes for this field in its declared encoding.

The tag protoc writes for this field in its declared encoding.

Attributes