moon/fory Apache Fory · MoonBit

API · struct

StructMeta

Schemas · defined at struct.mbt:253

pub struct StructMeta {
  model_ : @moonmodel.Model
  id_ : Int32
  wire_ : Array[(TypeId, Int32?, Bool, StructMeta?, TypeId?)]
}

A struct type: the description every projection shares, the user type ID it is registered under, and one wire record per field.

The description is @moonmodel.Model, which is what #model.derive hands back for a MoonBit type. The wire records are index-aligned with the model's fields and carry the three things a description does not: the type ID, the tag and the reference policy.

Fields

FieldMeaning
model_ : @moonmodel.Model

The description: the type's name, its documentation, and its fields.

id_ : Int32

The user type ID written after the type ID byte in same-schema mode.

wire_ : Array[(TypeId, Int32?, Bool, StructMeta?, TypeId?)]

Per field, in declaration order: the type ID, the tag, whether it may be shared, the struct it holds, and the element type of the list it holds.

Methods

fields

fn StructMeta::fields(Self) -> Array[FieldMeta]

The fields, in the order they are declared, each joined to its wire record.

find

fn StructMeta::find(Self, String) -> FieldMeta?

The field a name refers to, which is what a reader needs when the order on the wire is not the order it wants.

hash

fn StructMeta::hash(Self) -> Int32

The number written after a user type ID in same-schema mode.

model

fn StructMeta::model(Self) -> @moonmodel.Model

The description, as the projections outside this package read it.

name

fn StructMeta::name(Self) -> String

The struct's name, which a peer reading in compatible mode sees and which this package writes down in its errors.

new

fn StructMeta::new(String, Int32, Array[FieldMeta]) -> Self

A struct described field by field, which is how a schema is written when there is no @moonmodel.Model to hand.

The model is built from the fields: its name is name, its fields are the descriptions the caller gave, in the order they were given.

of

fn StructMeta::of(@moonmodel.Model, user~ : Int32, tags? : Map[String, Int32], refs? : Array[String], children? : Array[Self]) -> Self raise

A struct described by a model, which is what #model.derive produces.

tags names the fields whose identifier is a tag rather than a name, and refs the fields whose value may be shared; both are empty in the ordinary case, where a field is known by its name and sent as itself.

A field whose kind has no wire type is refused: a description this format cannot carry is better named than silently dropped.

order

fn StructMeta::order(Self) -> Array[Int32]

The indices of the fields in Fory order: the order their values are written in, which is not the order they were declared in.

The order is computed rather than asked for, because a field added in the middle of a declaration is a change no peer should have to be told about twice.

ordered

fn StructMeta::ordered(Self) -> Array[FieldMeta]

The fields in Fory order.

user

fn StructMeta::user(Self) -> Int32

The user type ID the struct is registered under.

Built in

derives Eq @debug.Debug

pub impl Show for StructMeta

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