moon/fory Apache Fory · MoonBit

API · struct

FieldMeta

Schemas · defined at struct.mbt:15

pub(all) struct FieldMeta {
  desc : @moonmodel.Field
  ty : TypeId
  tag : Int32?
  track_ref : Bool
  child : StructMeta?
  element : TypeId?
}

One field of a struct: the description it carries, and what the wire needs that a description has no word for.

The description is a @moonmodel.Field — a name, a kind, whether the value may be absent, and what it means — so that a type described once can be written by this package and still be published as a JSON Schema or a CREATE TABLE without being written down twice. The three other members are the wire's own: the type ID that kind goes out as, the tag that identifies the field when the schema configures one, and whether the value may be shared.

Fields

FieldMeaning
desc : @moonmodel.Field

The description: name, kind, nullability, documentation.

ty : TypeId

The type ID the description's kind goes out as.

tag : Int32?

The tag ID, when the schema configures one.

The specification allows 0 <= tag < 2^29 and requires tags to be unique within a type; a tag sorts before every name, so adding one to a field moves it.

track_ref : Bool

Whether the value may be shared, and so preceded by the tracking byte rather than the plain not-null one.

child : StructMeta?

The struct this field holds, when it holds one.

A field's type is declared, so the wire does not say it again: a nested struct arrives as its fingerprint and its fields, with no type ID and no user type ID in front. The schema has to know which struct the field is, and this is where it says so — a field of type Struct with no child is one this reader cannot follow.

element : TypeId?

The element type of a list, when the schema declares one.

A writer that knows a list holds strings says so in the schema and leaves the type out of the list header, which is a byte saved per list. Reading such a list needs the type the schema left out, and this is where it is.

Methods

from

fn FieldMeta::from(@moonmodel.Field, tag? : Int32?, track_ref? : Bool, child? : StructMeta?, element? : TypeId?) -> Self raise

The field a description asks for: its kind decides the type ID.

A kind with no wire type — Any, or a Raw that does not name one of this format's own — is refused rather than guessed at, because a field whose type the other side cannot name is a field neither side can read.

identifier

fn FieldMeta::identifier(Self) -> String

The field's identifier as the order sees it: the tag when there is one, and the snake_case of the name when there is not.

kind

fn FieldMeta::kind(Self) -> @moonmodel.Type

The kind the description gives this field.

name

fn FieldMeta::name(Self) -> String

The field's name, which is what a peer reads it by.

new

fn FieldMeta::new(String, TypeId, tag? : Int32?, nullable? : Bool, track_ref? : Bool, child? : StructMeta?, element? : TypeId?) -> Self

A field that is simply there, named by hand.

nullable is a question about the value and goes into the description; a kind the description has no word for is written as Raw, and the type ID the caller gave stays the one it goes out as.

nullable

fn FieldMeta::nullable(Self) -> Bool

Whether the value may be absent. A nullable field is preceded by a flag byte and sorts after every primitive that is not.

Built in

derives Eq @debug.Debug

pub impl Show for FieldMeta

Generated from src/pkg.generated.mbti and the doc comments beside this declaration.