moon/fory Apache Fory · MoonBit

API · enum

TypeId

Type IDs · defined at type_id.mbt:13

pub(all) enum TypeId {
  Unknown
  Bool
  Int8
  Int16
  Int32
  VarInt32
  Int64
  VarInt64
  TaggedInt64
  UInt8
  UInt16
  UInt32
  VarUInt32
  UInt64
  …
}

43 more, listed under variants below.

The internal type ID: the byte that begins a value's type meta, and the number every language agrees on.

The numbers are the specification's, and they are not ours to choose: a reader in Go reads 21 as a string because the type mapping says so. The variant names are the specification's too, except NoneType, which Python calls NoneType and the table calls NONE; MoonBit spells nothing None, so the spelling here is Python's.

Variants

Unknown Bool Int8 Int16 Int32 VarInt32 Int64 VarInt64 TaggedInt64 UInt8 UInt16 UInt32 VarUInt32 UInt64 VarUInt64 TaggedUInt64 Float8 Float16 BFloat16 Float32 Float64 String List Set Map Enum NamedEnum Struct CompatibleStruct NamedStruct NamedCompatibleStruct Ext NamedExt Union TypedUnion NamedUnion NoneType Duration Timestamp Date Decimal Binary Array BoolArray Int8Array Int16Array Int32Array Int64Array UInt8Array UInt16Array UInt32Array UInt64Array Float8Array Float16Array BFloat16Array Float32Array Float64Array

Methods

arrayed

fn TypeId::arrayed(Self) -> Self?

The dense array of this element type, when there is one.

Only the fourteen element types above have one; array<string> stays a list, which is why the answer is optional.

code

fn TypeId::code(Self) -> Int32

The number on the wire.

element

fn TypeId::element(Self) -> Self?

The element type of a dense array, which is what the bytes are.

fixed_size

fn TypeId::fixed_size(Self) -> Int32?

How many bytes a value of this type occupies, when the type decides it.

None for the compressed integers and for everything whose length is part of the value.

is_collection

fn TypeId::is_collection(Self) -> Bool

Whether values of this kind are counted: a list, a set or a map.

is_compressed

fn TypeId::is_compressed(Self) -> Bool

Whether the width of this type is decided by the value rather than by the type: the compressed integers, which sort after every fixed-width one.

is_dense

fn TypeId::is_dense(Self) -> Bool

Whether this kind is one of the dense primitive arrays: a run of raw little-endian elements rather than a list of values.

is_named_by_id

fn TypeId::is_named_by_id(Self) -> Bool

Whether this kind is one of the five that hold a user type ID in same-schema mode: the four that a struct can be, and the enum.

is_primitive

fn TypeId::is_primitive(Self) -> Bool

Whether a field of this type belongs to the primitive groups when the field order is decided: numbers and booleans, not strings and not containers.

is_user

fn TypeId::is_user(Self) -> Bool

Whether a value of this kind names a type of the writer's own, and so carries a user type ID or type meta after the type ID byte.

These are the kinds a field must write type information for. An enum or a union inside a struct field does not: its type is the field's declared one.

kind

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

The kind a type ID stands for, which is how a wire type is described to a projection that has never heard of this format.

The widths collapse — every signed 32-bit type is Int, every 64-bit one a Big — because the description is not the place a width is decided. What the vocabulary has no word for is a Raw naming the wire type, which is what Raw is for; nothing reads inside it, and the wire record beside the description still holds the type ID itself.

of

fn TypeId::of(Int32) -> Self?

The type a number on the wire stands for, when the mapping has one.

57 and up are unmapped: the specification reserves them, and a reader that met one could not know what to build.

of_kind

fn TypeId::of_kind(@moonmodel.Type) -> Self raise

The type ID a kind goes out as.

The widths are the compact ones — a field that is Int goes out as a VARINT32 and a Big as a VARINT64 — because that is what every peer's own mapping table chooses for the same word, and a field only interoperates when the two sides agree on the type ID as well as on the value.

A kind the format cannot carry — Any, which has no type ID at all — is refused by name.

Built in

derives Eq @debug.Debug

pub impl Show for TypeId

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