moon/fory Apache Fory · MoonBit

API · enum

Value

Values · defined at value.mbt:14

pub(all) enum Value {
  Null
  Bool(Bool)
  Int(Int64)
  UInt(UInt64)
  Float(Double)
  Str(String)
  Binary(Bytes)
  List(TypeId, Array[Value])
  Map(Array[(Value, Value)])
  Struct(StructMeta, Array[(String, Value)])
  Enum(Int32, Int32)
  Timestamp(Int64, Int32)
  Date(Int64)
  Duration(Int64, Int32)
  …
}

3 more, listed under variants below.

A value whose type travels with it.

A message written by another language arrives with nothing but its bytes, so this is what loads builds when the caller has no schema to hand: the cross-language types, the containers, and the three time types.

An integer of any width reads as Int or UInt at sixty-four bits, and a float of any width as Float, because a value read without a schema has no width to be. The typed codecs keep the width they were given.

Variants

VariantMeaning
Null

Nothing, which is what a nullable field holds when it holds nothing.

Bool(Bool)

1 or 0, one byte.

Int(Int64)

A signed integer of any width, at sixty-four.

UInt(UInt64)

An unsigned integer of any width, at sixty-four.

Float(Double)

A float of any width, at double.

Str(String)

A string, in whichever of the three encodings it arrived in.

Binary(Bytes)

Bytes: the BINARY type.

List(TypeId, Array[Value])

A list or a set: which one, and the elements.

Map(Array[(Value, Value)])

A map: the pairs, in the order they were written.

Struct(StructMeta, Array[(String, Value)])

A struct: its schema, and its fields by name.

Enum(Int32, Int32)

An enum: the user type ID of its type, and the variant's ID.

Timestamp(Int64, Int32)

Seconds and nanoseconds since the epoch: the TIMESTAMP type.

Date(Int64)

Days since the epoch: the DATE type.

Duration(Int64, Int32)

Seconds and nanoseconds: the DURATION type.

Decimal(Int32, @bigint.BigInt)

A decimal: the scale, and the unscaled value.

Shared(Int32, Value)

A value that may be pointed at, and the key it is remembered under.

Identity is the caller's, because a MoonBit value carries none: two values filed under the same key are one value on the wire, and the second of them is written as a Pointer.

Pointer(Int32)

A reference to a value already written under a key.

A cycle read back looks like this: the value it starts at is a Shared, and the field that leads back to it is a Pointer to the same key. That is a value a reader can hold without it holding itself, and a writer can send again byte for byte.

Built in

derives Eq @debug.Debug

pub impl Show for Value

pub impl Codec for Value

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