flatbuffers

moon add mizchi/flatbuffers@0.1.3
Download zip
Author
Version
0.1.3
License
Apache-2.0
Last updated
7 months ago
Downloads
56K

Dependencies

README

#FlatBuffers for MoonBit

A pure MoonBit implementation of Google FlatBuffers - an efficient cross-platform serialization library.

#Features

  • Zero-copy deserialization - Read data directly from buffer without parsing
  • Memory efficient - No intermediate allocations during read
  • Type safe - Compile-time type checking
  • Schema support - Parse .fbs schemas and generate MoonBit code
  • Full FlatBuffers compatibility - Binary format compatible with other languages

#Installation

Add to your moon.mod.json:

{ "deps": { "mizchi/flatbuffers": "0.1.0" } }

#Quick Start

#Basic Usage

// Create a FlatBuffer
let builder = @flatbuffers.Builder::new()

// Create a string (must be created before the table)
let name = builder.create_string("Alice")

// Build a table with 2 fields
builder.start_object(2)
builder.add_offset(0, name) // field 0: name (string)
builder.add_int32(1, 30, 0) // field 1: age (int32, default 0)
let person = builder.end_object()

// Finish the buffer
builder.finish(person)

// Get serialized bytes
let bytes = builder.to_bytes()

// Read it back
let buf = @flatbuffers.ByteBuffer::from_bytes(bytes)
let root = @flatbuffers.Table::get_root(buf)
let name = root.get_string(0, "") // "Alice"
let age = root.get_int32(1, 0) // 30

#Using Object API (Schema-based)

// Define schema
let schema = @flatbuffers.TableSchema::new("Person", [
@flatbuffers.FieldDef::new("name", 0, @flatbuffers.FieldType::string()),
@flatbuffers.FieldDef::with_default_int("age", 1, @flatbuffers.FieldType::int32(), 0),
])

// Build using ObjectBuilder
let builder = @flatbuffers.Builder::new()
let obj = @flatbuffers.ObjectBuilder::new(builder, schema)
.set_string("name", "Bob")
obj.start()
ignore(obj.add_int32("age", 25))
obj.finish_buffer()

// Read using ObjectReader
let buf = @flatbuffers.ByteBuffer::new(builder.to_fixed_array())
let root = @flatbuffers.Table::get_root(buf)
let reader = @flatbuffers.ObjectReader::new(root, schema)
println(reader.get_string("name")) // "Bob"
println(reader.get_int32("age")) // 25

#Code Generation

Generate MoonBit code from FlatBuffers schema:

///|
let schema_text =
#|table Monster {
#| name:string;
#| hp:short = 100;
#|}

///|
let schema = @flatbuffers.parse_schema(schema_text)

///|
let code = @flatbuffers.generate_moonbit(schema)
// Save `code` to a .mbt file

Run the code generator CLI:

moon run cmd/codegen

#API Reference

#Core Types

TypeDescription
ByteBufferRead-only buffer for deserialization
BuilderMutable builder for serialization
TableReader for table data

#Builder Methods

// Scalars
builder.add_bool(slot, value, default)
builder.add_int8(slot, value, default)
builder.add_uint8(slot, value, default)
builder.add_int16(slot, value, default)
builder.add_uint16(slot, value, default)
builder.add_int32(slot, value, default)
builder.add_uint32(slot, value, default)
builder.add_int64(slot, value, default)
builder.add_uint64(slot, value, default)
builder.add_float32(slot, value, default)
builder.add_float64(slot, value, default)

// Strings and Vectors
builder.create_string(s)
builder.create_shared_string(s) // Deduplicates strings
builder.create_byte_vector(data)
builder.create_int32_vector(data)

// Table construction
builder.start_object(num_fields)
builder.add_offset(slot, offset)
builder.end_object() -> Int

// Finishing
builder.finish(root_offset)
builder.finish_with_identifier(root_offset, "FILE")
builder.finish_size_prefixed(root_offset)

#Table Reader Methods

// Scalars
table.get_bool(slot, default) -> Bool
table.get_int8(slot, default) -> Int
table.get_int16(slot, default) -> Int
table.get_int32(slot, default) -> Int
table.get_int64(slot, default) -> Int64
table.get_float32(slot, default) -> Float
table.get_float64(slot, default) -> Double

// Strings
table.get_string(slot, default) -> String

// Vectors
table.get_vector_length(slot) -> Int
table.get_vector_byte(slot, index) -> Byte
table.get_vector_int32(slot, index) -> Int

// Nested tables
table.get_table(slot) -> Table?

// Unions
table.get_union_type(slot) -> Int
table.get_union_table(slot) -> Table?

#Advanced Features

#Shared Strings

Reduce buffer size by deduplicating identical strings:

///|
let s1 = builder.create_shared_string("repeated")

///|
let s2 = builder.create_shared_string("repeated") // Same offset as s1

#Force Defaults

Serialize fields even when they equal the default value:

builder.set_force_defaults(true)
builder.add_int32(0, 0, 0) // Serialized even though value == default

#JSON Conversion

Convert FlatBuffers to JSON:

///|
let json = @flatbuffers.JsonObjectBuilder::new()
.add_string("name", table.get_string(0, ""))
.add_int("hp", table.get_int32(1, 0))
.to_json_string()
// {"name": "Monster", "hp": 100}

#Verifier

Validate buffer integrity before reading:

let buf = @flatbuffers.ByteBuffer::new(data)
if buf.verify() {
let root = @flatbuffers.Table::get_root(buf)
// Safe to read
}

#Nested FlatBuffers

Embed complete FlatBuffers inside other FlatBuffers:

// Create nested buffer
let inner_builder = @flatbuffers.Builder::new()
// ... build inner ...

// Embed in outer buffer
let nested = outer_builder.create_nested_flatbuffer(inner_builder.to_fixed_array())
outer_builder.add_offset(slot, nested)

// Read nested
let nested_root = table.get_nested_root(slot)

#Supported Schema Features

FeatureStatus
TablesSupported
StructsSupported
EnumsSupported
UnionsSupported
VectorsSupported
StringsSupported
Nested FlatBuffersSupported
Default valuesSupported
File identifiersSupported
Size-prefixed buffersSupported

#Running Tests

moon test

#Running Benchmarks

moon bench

#License

Apache-2.0

#Acknowledgments

#
BaseType

pub enum BaseType {
None
UType
Bool
Byte
UByte
Short
UShort
Int
UInt
Long
ULong
Float
Double
String
Vector
Obj
Union
Array
MaxBaseType
}

Base types for FlatBuffers fields
impl Show for BaseType

#
BaseType::from_int

fn BaseType::from_int(value : Int) -> BaseType

#
BaseType::to_int

fn BaseType::to_int(self : BaseType) -> Int

#
Builder

pub struct Builder {
buf : FixedArray[Byte]
head : Int
minalign : Int
vtable : Array[Int]
object_start : Int
vtables : Array[Int]
nested : Bool
finished : Bool
force_defaults : Bool
string_cache : Map[String, Int]
}

Builder is used to construct FlatBuffers. Data is written backwards from the end of the buffer.

#
Builder::add_bool

fn Builder::add_bool(self : Builder, slot_num : Int, val : Bool, default : Bool) -> Unit

Add a boolean field

#
Builder::add_float32

fn Builder::add_float32(self : Builder, slot_num : Int, val : Float, default : Float) -> Unit

Add a Float32 field

#
Builder::add_float64

fn Builder::add_float64(self : Builder, slot_num : Int, val : Double, default : Double) -> Unit

Add a Float64 field

#
Builder::add_int16

fn Builder::add_int16(self : Builder, slot_num : Int, val : Int, default : Int) -> Unit

Add an Int16 field

#
Builder::add_int32

fn Builder::add_int32(self : Builder, slot_num : Int, val : Int, default : Int) -> Unit

Add an Int32 field

#
Builder::add_int64

fn Builder::add_int64(self : Builder, slot_num : Int, val : Int64, default : Int64) -> Unit

Add an Int64 field

#
Builder::add_int8

fn Builder::add_int8(self : Builder, slot_num : Int, val : Int, default : Int) -> Unit

Add an Int8 field

#
Builder::add_offset

fn Builder::add_offset(self : Builder, slot_num : Int, val : Int) -> Unit

Add an offset field (for strings, vectors, tables)

#
Builder::add_struct

fn Builder::add_struct(self : Builder, slot_num : Int, val : Int) -> Unit

Add a struct inline (structs are stored inline, not as offsets)

#
Builder::add_uint16

fn Builder::add_uint16(self : Builder, slot_num : Int, val : Int, default : Int) -> Unit

Add a UInt16 field

#
Builder::add_uint32

fn Builder::add_uint32(self : Builder, slot_num : Int, val : UInt, default : UInt) -> Unit

Add a UInt32 field

#
Builder::add_uint64

fn Builder::add_uint64(self : Builder, slot_num : Int, val : UInt64, default : UInt64) -> Unit

Add a UInt64 field

#
Builder::add_uint8

fn Builder::add_uint8(self : Builder, slot_num : Int, val : Int, default : Int) -> Unit

Add a UInt8 field

#
Builder::add_union

fn Builder::add_union(self : Builder, type_slot : Int, type_value : Int, value_slot : Int, table_offset : Int) -> Unit

Add a union to the object being built. type_slot: slot for the union type (ubyte) type_value: the union type value (0 = NONE, 1 = first type, etc.) value_slot: slot for the union value (offset) table_offset: offset to the table returned by end_object

#
Builder::clear_string_cache

fn Builder::clear_string_cache(self : Builder) -> Unit

Clear the shared string cache. Call this if you want to create duplicate strings intentionally.

#
Builder::create_bool_vector

fn Builder::create_bool_vector(self : Builder, data : Array[Bool]) -> Int

Create a vector of Bool values

#
Builder::create_byte_vector

fn Builder::create_byte_vector(self : Builder, data : FixedArray[Byte]) -> Int

Create a byte vector in the buffer

#
Builder::create_float64_vector

fn Builder::create_float64_vector(self : Builder, data : Array[Double]) -> Int

Create a vector of Float64 (Double) values

#
Builder::create_int32_vector

fn Builder::create_int32_vector(self : Builder, data : Array[Int]) -> Int

Create a vector of Int32 values

#
Builder::create_int64_vector

fn Builder::create_int64_vector(self : Builder, data : Array[Int64]) -> Int

Create a vector of Int64 values

#
Builder::create_nested_flatbuffer

fn Builder::create_nested_flatbuffer(self : Builder, nested_bytes : FixedArray[Byte]) -> Int

Create a nested FlatBuffer field from serialized bytes. The bytes should be a complete FlatBuffer (from Builder::to_bytes or similar). Returns an offset to use with add_offset.

#
Builder::create_nested_flatbuffer_from_builder

fn Builder::create_nested_flatbuffer_from_builder(self : Builder, nested_builder : Builder) -> Int

Create a nested FlatBuffer field from another builder's output. This is a convenience method that gets the bytes from the builder.

#
Builder::create_offset_vector

fn Builder::create_offset_vector(self : Builder, offsets : Array[Int]) -> Int

Create a vector of offsets (for tables/strings that were already created)

#
Builder::create_shared_string

fn Builder::create_shared_string(self : Builder, s : String) -> Int

Create a shared string in the buffer. If the same string was already created, returns the existing offset. This reduces buffer size when the same string appears multiple times.

#
Builder::create_string

fn Builder::create_string(self : Builder, s : String) -> Int

Create a string in the buffer

#
Builder::create_string_vector

fn Builder::create_string_vector(self : Builder, strings : Array[String]) -> Int

Create a vector of strings (convenience method)

#
Builder::end_object

fn Builder::end_object(self : Builder) -> Int

End building a table and return its offset

#
Builder::end_vector

fn Builder::end_vector(self : Builder, num_elems : Int) -> Int

End building a vector

#
Builder::finish

fn Builder::finish(self : Builder, root_table : Int) -> Unit

Finish building the buffer with root table

#
Builder::finish_size_prefixed

fn Builder::finish_size_prefixed(self : Builder, root_table : Int) -> Unit

Finish building the buffer with a size prefix

#
Builder::finish_with_identifier

fn Builder::finish_with_identifier(self : Builder, root_table : Int, identifier : String) -> Unit

Finish building the buffer with a file identifier

#
Builder::get_force_defaults

fn Builder::get_force_defaults(self : Builder) -> Bool

Get the current force_defaults setting

#
Builder::new

fn Builder::new(initial_size? : Int) -> Builder

Create a new Builder with initial capacity

#
Builder::offset

fn Builder::offset(self : Builder) -> Int

Get current offset from the end of the buffer

#
Builder::place_bool

fn Builder::place_bool(self : Builder, val : Bool) -> Unit

Place a bool at current position (for struct building)

#
Builder::place_float32

fn Builder::place_float32(self : Builder, val : Float) -> Unit

Place a Float32 at current position (for struct building)

#
Builder::place_float64

fn Builder::place_float64(self : Builder, val : Double) -> Unit

Place a Float64 at current position (for struct building)

#
Builder::place_int16

fn Builder::place_int16(self : Builder, val : Int) -> Unit

Place an Int16 at current position (for struct building)

#
Builder::place_int32

fn Builder::place_int32(self : Builder, val : Int) -> Unit

Place an Int32 at current position (for struct building)

#
Builder::place_int64

fn Builder::place_int64(self : Builder, val : Int64) -> Unit

Place an Int64 at current position (for struct building)

#
Builder::place_int8

fn Builder::place_int8(self : Builder, val : Int) -> Unit

Place an Int8 at current position (for struct building)

#
Builder::place_uint16

fn Builder::place_uint16(self : Builder, val : Int) -> Unit

Place a UInt16 at current position (for struct building)

#
Builder::place_uint32

fn Builder::place_uint32(self : Builder, val : UInt) -> Unit

Place a UInt32 at current position (for struct building)

#
Builder::place_uint64

fn Builder::place_uint64(self : Builder, val : UInt64) -> Unit

Place a UInt64 at current position (for struct building)

#
Builder::place_uint8

fn Builder::place_uint8(self : Builder, val : Int) -> Unit

Place a UInt8 at current position (for struct building)

#
Builder::prep

fn Builder::prep(self : Builder, size : Int, additional : Int) -> Unit

Prepare to write data with alignment

#
Builder::prep_struct

fn Builder::prep_struct(self : Builder, size : Int, alignment : Int) -> Int

Prepare to write a struct with the given size and alignment

#
Builder::reset

fn Builder::reset(self : Builder) -> Unit

Reset the builder to reuse it

#
Builder::set_force_defaults

fn Builder::set_force_defaults(self : Builder, force : Bool) -> Unit

Set whether to force serialization of default values. When true, fields are written even if they equal the default value. This is useful for debugging or when you need to see all fields.

#
Builder::slot

fn Builder::slot(self : Builder, slot_num : Int) -> Unit

Record a field slot

#
Builder::start_object

fn Builder::start_object(self : Builder, num_fields : Int) -> Unit

Start building a new table/object

#
Builder::start_vector

fn Builder::start_vector(self : Builder, elem_size : Int, num_elems : Int, alignment : Int) -> Unit

Start building a new vector

#
Builder::struct_add_double

fn Builder::struct_add_double(self : Builder, val : Double) -> Unit

Write a struct's double field

#
Builder::struct_add_float

fn Builder::struct_add_float(self : Builder, val : Float) -> Unit

Write a struct's float field (for inline struct building)

#
Builder::struct_add_int16

fn Builder::struct_add_int16(self : Builder, val : Int) -> Unit

Write a struct's int16 field

#
Builder::struct_add_int32

fn Builder::struct_add_int32(self : Builder, val : Int) -> Unit

Write a struct's int32 field

#
Builder::struct_add_int64

fn Builder::struct_add_int64(self : Builder, val : Int64) -> Unit

Write a struct's int64 field

#
Builder::struct_add_int8

fn Builder::struct_add_int8(self : Builder, val : Int) -> Unit

Write a struct's int8 field

#
Builder::struct_pad

fn Builder::struct_pad(self : Builder, bytes : Int) -> Unit

Pad struct to alignment

#
Builder::to_bytes

fn Builder::to_bytes(self : Builder) -> Bytes

Get the finished buffer as bytes

#
Builder::to_fixed_array

fn Builder::to_fixed_array(self : Builder) -> FixedArray[Byte]

Get the finished buffer as FixedArray

#
Builder::write_byte

fn Builder::write_byte(self : Builder, val : Byte) -> Unit

Write a byte at current position

#
Builder::write_float32

fn Builder::write_float32(self : Builder, val : Float) -> Unit

Write a Float32 (little-endian)

#
Builder::write_float64

fn Builder::write_float64(self : Builder, val : Double) -> Unit

Write a Float64/Double (little-endian)

#
Builder::write_int16

fn Builder::write_int16(self : Builder, val : Int) -> Unit

Write an Int16 (little-endian)

#
Builder::write_int32

fn Builder::write_int32(self : Builder, val : Int) -> Unit

Write an Int32 (little-endian)

#
Builder::write_int64

fn Builder::write_int64(self : Builder, val : Int64) -> Unit

Write an Int64 (little-endian)

#
Builder::write_int8

fn Builder::write_int8(self : Builder, val : Int) -> Unit

Write an Int8

#
Builder::write_uint16

fn Builder::write_uint16(self : Builder, val : Int) -> Unit

Write a UInt16 (little-endian)

#
Builder::write_uint32

fn Builder::write_uint32(self : Builder, val : UInt) -> Unit

Write a UInt32 (little-endian)

#
Builder::write_uint64

fn Builder::write_uint64(self : Builder, val : UInt64) -> Unit

Write a UInt64 (little-endian)

#
Builder::write_uint8

fn Builder::write_uint8(self : Builder, val : Int) -> Unit

Write a UInt8

#
BuilderPool

pub struct BuilderPool {
pool : Array[Builder]
default_size : Int
}

Builder pool for reusing builders to reduce allocations. Use when building many FlatBuffers in a loop.

#
BuilderPool::acquire

fn BuilderPool::acquire(self : BuilderPool) -> Builder

Get a builder from the pool (or create a new one if empty)

#
BuilderPool::new

fn BuilderPool::new(pool_size? : Int, default_buffer_size? : Int) -> BuilderPool

Create a new BuilderPool

#
BuilderPool::release

fn BuilderPool::release(self : BuilderPool, builder : Builder) -> Unit

Return a builder to the pool

#
ByteBuffer

pub struct ByteBuffer {
data : FixedArray[Byte]
pos : Int
}

ByteBuffer provides read access to a FlatBuffer binary. All multi-byte values are stored in little-endian format.

#
ByteBuffer::from_bytes

fn ByteBuffer::from_bytes(bytes : Bytes) -> ByteBuffer

Create a ByteBuffer from a Bytes object

#
ByteBuffer::get_byte

fn ByteBuffer::get_byte(self : ByteBuffer, offset : Int) -> Byte

Get a byte at the given offset

#
ByteBuffer::get_identifier

fn ByteBuffer::get_identifier(self : ByteBuffer) -> String

Get the file identifier from a buffer

#
ByteBuffer::get_root_offset

fn ByteBuffer::get_root_offset(self : ByteBuffer) -> Int

Get the root table offset from the buffer start

#
ByteBuffer::has_identifier

fn ByteBuffer::has_identifier(self : ByteBuffer, identifier : String) -> Bool

Check if buffer has a file identifier

#
ByteBuffer::length

fn ByteBuffer::length(self : ByteBuffer) -> Int

Get the underlying data length

#
ByteBuffer::new

fn ByteBuffer::new(data : FixedArray[Byte]) -> ByteBuffer

Create a new ByteBuffer from bytes

#
ByteBuffer::read_float32

fn ByteBuffer::read_float32(self : ByteBuffer, offset : Int) -> Float

Read a Float32 (little-endian) at offset

#
ByteBuffer::read_float64

fn ByteBuffer::read_float64(self : ByteBuffer, offset : Int) -> Double

Read a Float64/Double (little-endian) at offset

#
ByteBuffer::read_int16

fn ByteBuffer::read_int16(self : ByteBuffer, offset : Int) -> Int

Read an Int16 (little-endian) at offset

#
ByteBuffer::read_int32

fn ByteBuffer::read_int32(self : ByteBuffer, offset : Int) -> Int

Read an Int32 (little-endian) at offset

#
ByteBuffer::read_int64

fn ByteBuffer::read_int64(self : ByteBuffer, offset : Int) -> Int64

Read an Int64 (little-endian) at offset

#
ByteBuffer::read_int8

fn ByteBuffer::read_int8(self : ByteBuffer, offset : Int) -> Int

Read an Int8 (signed byte) at offset

#
ByteBuffer::read_string

fn ByteBuffer::read_string(self : ByteBuffer, offset : Int) -> String

Read a string at offset (FlatBuffer string format: length + UTF-8 data)

#
ByteBuffer::read_uint16

fn ByteBuffer::read_uint16(self : ByteBuffer, offset : Int) -> Int

Read a UInt16 (little-endian) at offset

#
ByteBuffer::read_uint32

fn ByteBuffer::read_uint32(self : ByteBuffer, offset : Int) -> UInt

Read a UInt32 (little-endian) at offset

#
ByteBuffer::read_uint64

fn ByteBuffer::read_uint64(self : ByteBuffer, offset : Int) -> UInt64

Read a UInt64 (little-endian) at offset

#
ByteBuffer::read_uint8

fn ByteBuffer::read_uint8(self : ByteBuffer, offset : Int) -> Int

Read a UInt8 (unsigned byte) at offset

#
ByteBuffer::verify

fn ByteBuffer::verify(self : ByteBuffer) -> Bool

Verify a buffer (convenience function)

#
ByteBuffer::verify_size_prefixed

fn ByteBuffer::verify_size_prefixed(self : ByteBuffer) -> Bool

Verify a size-prefixed buffer (convenience function)

#
ByteBuffer::verify_with_identifier

fn ByteBuffer::verify_with_identifier(self : ByteBuffer, identifier : String) -> Bool

Verify a buffer with identifier (convenience function)

#
ByteBuffer::write_bool

fn ByteBuffer::write_bool(self : ByteBuffer, offset : Int, value : Bool) -> Unit

Write a Bool at offset

#
ByteBuffer::write_float32

fn ByteBuffer::write_float32(self : ByteBuffer, offset : Int, value : Float) -> Unit

Write a Float32 (little-endian) at offset

#
ByteBuffer::write_float64

fn ByteBuffer::write_float64(self : ByteBuffer, offset : Int, value : Double) -> Unit

Write a Float64/Double (little-endian) at offset

#
ByteBuffer::write_int16

fn ByteBuffer::write_int16(self : ByteBuffer, offset : Int, value : Int) -> Unit

Write an Int16 (little-endian) at offset

#
ByteBuffer::write_int32

fn ByteBuffer::write_int32(self : ByteBuffer, offset : Int, value : Int) -> Unit

Write an Int32 (little-endian) at offset

#
ByteBuffer::write_int64

fn ByteBuffer::write_int64(self : ByteBuffer, offset : Int, value : Int64) -> Unit

Write an Int64 (little-endian) at offset

#
ByteBuffer::write_int8

fn ByteBuffer::write_int8(self : ByteBuffer, offset : Int, value : Int) -> Unit

Write an Int8 at offset

#
ByteBuffer::write_uint16

fn ByteBuffer::write_uint16(self : ByteBuffer, offset : Int, value : Int) -> Unit

Write a UInt16 (little-endian) at offset

#
ByteBuffer::write_uint32

fn ByteBuffer::write_uint32(self : ByteBuffer, offset : Int, value : UInt) -> Unit

Write a UInt32 (little-endian) at offset

#
ByteBuffer::write_uint64

fn ByteBuffer::write_uint64(self : ByteBuffer, offset : Int, value : UInt64) -> Unit

Write a UInt64 (little-endian) at offset

#
ByteBuffer::write_uint8

fn ByteBuffer::write_uint8(self : ByteBuffer, offset : Int, value : Int) -> Unit

Write a UInt8 at offset

#
CachedTableReader

pub struct CachedTableReader {
table : Table
vtable_offset : Int
vtable_size : Int
}

Pre-compute vtable offset once and use for multiple field reads

#
CachedTableReader::get_bool

fn CachedTableReader::get_bool(self : CachedTableReader, field_slot : Int, default : Bool) -> Bool

Fast bool read

#
CachedTableReader::get_float64

fn CachedTableReader::get_float64(self : CachedTableReader, field_slot : Int, default : Double) -> Double

Fast float64 read

#
CachedTableReader::get_int32

fn CachedTableReader::get_int32(self : CachedTableReader, field_slot : Int, default : Int) -> Int

Fast int32 read

#
CachedTableReader::get_string

fn CachedTableReader::get_string(self : CachedTableReader, field_slot : Int, default : String) -> String

Fast string read

#
CachedTableReader::new

Create a cached table reader for faster repeated field access

#
CallOptions

pub struct CallOptions {
timeout_ms : Int?
metadata : Metadata
compression : Bool
}

Options for a gRPC call

#
CallOptions::new

#
CallOptions::with_compression

fn CallOptions::with_compression(self : CallOptions, enabled : Bool) -> CallOptions

#
CallOptions::with_metadata

fn CallOptions::with_metadata(self : CallOptions, metadata : Metadata) -> CallOptions

#
CallOptions::with_timeout

fn CallOptions::with_timeout(self : CallOptions, ms : Int) -> CallOptions

#
Channel

pub struct Channel {
target : String
state : ChannelState
codec : FlatBuffersCodec
}

Abstract channel for gRPC communication

#
Channel::connect

fn Channel::connect(self : Channel) -> Unit

#
Channel::get_state

fn Channel::get_state(self : Channel) -> ChannelState

#
Channel::get_target

fn Channel::get_target(self : Channel) -> String

#
Channel::new

fn Channel::new(target : String) -> Channel

#
Channel::shutdown

fn Channel::shutdown(self : Channel) -> Unit

#
ChannelState

pub(all) enum ChannelState {
Idle
Connecting
Ready
TransientFailure
Shutdown
}

Channel state
impl Eq for ChannelState

#
ClientContext

pub struct ClientContext {
metadata : Metadata
response_headers : Metadata
response_trailers : Metadata
options : CallOptions
}

Context for client-side call handling

#
ClientContext::add_metadata

fn ClientContext::add_metadata(self : ClientContext, key : String, value : String) -> ClientContext

#
ClientContext::new

#
ClientContext::with_metadata

fn ClientContext::with_metadata(self : ClientContext, metadata : Metadata) -> ClientContext

#
ClientContext::with_options

fn ClientContext::with_options(self : ClientContext, options : CallOptions) -> ClientContext

#
ClientInterceptor

pub struct ClientInterceptor {
on_request : (ClientContext, FixedArray[Byte]) -> FixedArray[Byte]
on_response : (ClientContext, FixedArray[Byte]) -> FixedArray[Byte]
}

Client interceptor for modifying outgoing calls

#
ClientInterceptor::new

fn ClientInterceptor::new(on_request : (ClientContext, FixedArray[Byte]) -> FixedArray[Byte], on_response : (ClientContext, FixedArray[Byte]) -> FixedArray[Byte]) -> ClientInterceptor

#
ClientStream

pub struct ClientStream[T] {
write_fn : (T) -> Bool
close_fn : () -> Unit
closed : Bool
}

Writable stream of messages

#
ClientStream::close

fn[T] ClientStream::close(self : ClientStream[T]) -> Unit

#
ClientStream::new

fn[T] ClientStream::new(write_fn : (T) -> Bool, close_fn : () -> Unit) -> ClientStream[T]

#
ClientStream::write

fn[T] ClientStream::write(self : ClientStream[T], msg : T) -> Bool

#
EnumAst

pub struct EnumAst {
name : String
base_type : ScalarType
bit_flags : Bool
values : Array[EnumValueAst]
}

Enum definition in schema

#
EnumVal

pub struct EnumVal {
buf : ByteBuffer
pos : Int
}

An enumeration value

#
EnumVal::name

fn EnumVal::name(self : EnumVal) -> String

#
EnumVal::new

fn EnumVal::new(buf : ByteBuffer, pos : Int) -> EnumVal

#
EnumVal::union_type

fn EnumVal::union_type(self : EnumVal) -> ReflectionType?

Get union type (for union enum values)

#
EnumVal::value

fn EnumVal::value(self : EnumVal) -> Int64

#
EnumValueAst

pub struct EnumValueAst {
name : String
value : Int?
}

Enum value definition

#
FieldAst

pub struct FieldAst {
name : String
field_type : FieldTypeAst
default_value : String?
deprecated : Bool
id : Int?
}

Field definition in schema

#
FieldDef

pub struct FieldDef {
name : String
slot : Int
field_type : FieldType
default_int : Int
default_bool : Bool
}

Field definition for schema

#
FieldDef::new

fn FieldDef::new(name : String, slot : Int, field_type : FieldType) -> FieldDef

Create a new field definition

#
FieldDef::with_default_bool

fn FieldDef::with_default_bool(name : String, slot : Int, default : Bool) -> FieldDef

Create a field definition with bool default

#
FieldDef::with_default_int

fn FieldDef::with_default_int(name : String, slot : Int, field_type : FieldType, default : Int) -> FieldDef

Create a field definition with int default

#
FieldType

pub enum FieldType {
Bool
Int8
UInt8
Int16
UInt16
Int32
UInt32
Int64
UInt64
Float32
Float64
String
Vector(FieldType)
Table
}

Field types supported by the Object API

#
FieldType::bool

fn FieldType::bool() -> FieldType

#
FieldType::float32

fn FieldType::float32() -> FieldType

#
FieldType::float64

fn FieldType::float64() -> FieldType

#
FieldType::int16

fn FieldType::int16() -> FieldType

#
FieldType::int32

fn FieldType::int32() -> FieldType

#
FieldType::int64

fn FieldType::int64() -> FieldType

#
FieldType::int8

fn FieldType::int8() -> FieldType

#
FieldType::string

fn FieldType::string() -> FieldType

#
FieldType::table

fn FieldType::table() -> FieldType

#
FieldType::uint16

fn FieldType::uint16() -> FieldType

#
FieldType::uint32

fn FieldType::uint32() -> FieldType

#
FieldType::uint64

fn FieldType::uint64() -> FieldType

#
FieldType::uint8

fn FieldType::uint8() -> FieldType

#
FieldType::vector

fn FieldType::vector(elem_type : FieldType) -> FieldType

#
FieldTypeAst

pub enum FieldTypeAst {
Scalar(ScalarType)
String
Vector(FieldTypeAst)
Reference(String)
}

Field type in schema

#
FlatBuffersCodec

pub struct FlatBuffersCodec {
content_type : String
}

Codec for encoding/decoding FlatBuffers messages

#
FlatBuffersCodec::decode

fn FlatBuffersCodec::decode(self : FlatBuffersCodec, data : FixedArray[Byte]) -> ByteBuffer

Decode bytes to a ByteBuffer for reading

#
FlatBuffersCodec::encode

fn FlatBuffersCodec::encode(self : FlatBuffersCodec, builder : Builder) -> FixedArray[Byte]

Encode a FlatBuffers message to bytes

#
FlatBuffersCodec::get_content_type

fn FlatBuffersCodec::get_content_type(self : FlatBuffersCodec) -> String

Get the content type

#
FlatBuffersCodec::new

#
FlexBuilder

pub struct FlexBuilder {
buf : Array[Byte]
stack : Array[FlexValue]
string_pool : Map[String, Int]
key_pool : Map[String, Int]
finished : Bool
}

FlexBuffer builder

#
FlexBuilder::add_blob

fn FlexBuilder::add_blob(self : FlexBuilder, data : FixedArray[Byte]) -> FlexBuilder

Add a blob (binary data)

#
FlexBuilder::add_bool

fn FlexBuilder::add_bool(self : FlexBuilder, val : Bool) -> FlexBuilder

Add bool value

#
FlexBuilder::add_float

fn FlexBuilder::add_float(self : FlexBuilder, val : Double) -> FlexBuilder

Add float value

#
FlexBuilder::add_int

fn FlexBuilder::add_int(self : FlexBuilder, val : Int64) -> FlexBuilder

Add int value

#
FlexBuilder::add_key

fn FlexBuilder::add_key(self : FlexBuilder, key : String) -> FlexBuilder

Add a key (for maps) - keys are null-terminated strings without length prefix

#
FlexBuilder::add_null

fn FlexBuilder::add_null(self : FlexBuilder) -> FlexBuilder

Add null value

#
FlexBuilder::add_string

fn FlexBuilder::add_string(self : FlexBuilder, s : String) -> FlexBuilder

Add string value

#
FlexBuilder::add_uint

fn FlexBuilder::add_uint(self : FlexBuilder, val : UInt64) -> FlexBuilder

Add uint value

#
FlexBuilder::end_float_vector

fn FlexBuilder::end_float_vector(self : FlexBuilder, count : Int) -> FlexBuilder

End a typed vector of floats

#
FlexBuilder::end_int_vector

fn FlexBuilder::end_int_vector(self : FlexBuilder, count : Int) -> FlexBuilder

End a typed vector of ints

#
FlexBuilder::end_map

fn FlexBuilder::end_map(self : FlexBuilder, count : Int) -> FlexBuilder

End a map and push it onto the stack Map format: keys vector followed by values vector with type info Stack should contain: key1, val1, key2, val2, ... (pairs)

#
FlexBuilder::end_vector

fn FlexBuilder::end_vector(self : FlexBuilder, count : Int) -> FlexBuilder

End a vector and push it onto the stack

#
FlexBuilder::finish

fn FlexBuilder::finish(self : FlexBuilder) -> FixedArray[Byte]

Finish building and get the buffer

#
FlexBuilder::new

Create a new FlexBuilder

#
FlexRef

pub struct FlexRef {
data : FixedArray[Byte]
offset : Int
parent_width : Int
byte_width : Int
flex_type : FlexType
}

A reference to a value in a FlexBuffer

#
FlexRef::as_blob

fn FlexRef::as_blob(self : FlexRef) -> FixedArray[Byte]

Get blob data

#
FlexRef::as_bool

fn FlexRef::as_bool(self : FlexRef) -> Bool

Get value as Bool

#
FlexRef::as_double

fn FlexRef::as_double(self : FlexRef) -> Double

Get value as Double

#
FlexRef::as_int

fn FlexRef::as_int(self : FlexRef) -> Int

Get value as Int

#
FlexRef::as_int64

fn FlexRef::as_int64(self : FlexRef) -> Int64

Get value as Int64

#
FlexRef::as_string

fn FlexRef::as_string(self : FlexRef) -> String

Get value as String

#
FlexRef::as_uint64

fn FlexRef::as_uint64(self : FlexRef) -> UInt64

Get value as UInt64

#
FlexRef::from_bytes

fn FlexRef::from_bytes(data : FixedArray[Byte]) -> FlexRef

Create a FlexRef from raw bytes

#
FlexRef::get

fn FlexRef::get(self : FlexRef, index : Int) -> FlexRef

Get element from vector by index

#
FlexRef::get_by_key

fn FlexRef::get_by_key(self : FlexRef, key : String) -> FlexRef

Get value from map by key

#
FlexRef::get_type

fn FlexRef::get_type(self : FlexRef) -> FlexType

Get the type of a FlexRef

#
FlexRef::is_map

fn FlexRef::is_map(self : FlexRef) -> Bool

Check if this is a Map

#
FlexRef::is_null

fn FlexRef::is_null(self : FlexRef) -> Bool

Check if value is null

#
FlexRef::is_vector

fn FlexRef::is_vector(self : FlexRef) -> Bool

Check if this is a Vector

#
FlexRef::keys

fn FlexRef::keys(self : FlexRef) -> Array[String]

Get all keys from a map

#
FlexRef::length

fn FlexRef::length(self : FlexRef) -> Int

Get vector length (for Vector, Map, typed vectors)

#
FlexType

pub enum FlexType {
Null
Int
UInt
Float
Key
String
IndirectInt
IndirectUInt
IndirectFloat
Map
Vector
VectorInt
VectorUInt
VectorFloat
VectorKey
VectorString
VectorInt2
VectorUInt2
VectorFloat2
VectorInt3
VectorUInt3
VectorFloat3
VectorInt4
VectorUInt4
VectorFloat4
Blob
Bool
VectorBool
}

FlexBuffer value types
impl Show for FlexType

#
FlexType::from_int

fn FlexType::from_int(value : Int) -> FlexType

#
FlexType::is_fixed_typed_vector

fn FlexType::is_fixed_typed_vector(self : FlexType) -> Bool

Check if type is a fixed typed vector

#
FlexType::is_inline

fn FlexType::is_inline(self : FlexType) -> Bool

Check if type is inline (stored directly in the data)

#
FlexType::is_typed_vector

fn FlexType::is_typed_vector(self : FlexType) -> Bool

Check if type is a typed vector

#
FlexType::to_int

fn FlexType::to_int(self : FlexType) -> Int

#
FlexValue

pub struct FlexValue {
flex_type : FlexType
min_bit_width : Int
value_int : Int64
value_uint : UInt64
value_float : Double
offset : Int
}

A value to be written to a FlexBuffer

#
FlexValue::blob_ref

fn FlexValue::blob_ref(offset : Int) -> FlexValue

#
FlexValue::bool_val

fn FlexValue::bool_val(val : Bool) -> FlexValue

#
FlexValue::float

fn FlexValue::float(val : Double) -> FlexValue

#
FlexValue::int

fn FlexValue::int(val : Int64) -> FlexValue

#
FlexValue::key_ref

fn FlexValue::key_ref(offset : Int, min_bit_width : Int) -> FlexValue

#
FlexValue::null

fn FlexValue::null() -> FlexValue

#
FlexValue::string_ref

fn FlexValue::string_ref(offset : Int, min_bit_width : Int) -> FlexValue

#
FlexValue::uint

fn FlexValue::uint(val : UInt64) -> FlexValue

#
FlexValue::vector_ref

fn FlexValue::vector_ref(offset : Int, flex_type : FlexType, min_bit_width : Int) -> FlexValue

#
GrpcError

pub struct GrpcError {
status : GrpcStatus
message : String
metadata : Metadata
}

gRPC error with status and message
impl Show for GrpcError

#
GrpcError::new

fn GrpcError::new(status : GrpcStatus, message : String) -> GrpcError

#
GrpcError::with_metadata

fn GrpcError::with_metadata(status : GrpcStatus, message : String, metadata : Metadata) -> GrpcError

#
GrpcStatus

pub(all) enum GrpcStatus {
Ok
Cancelled
Unknown
InvalidArgument
DeadlineExceeded
NotFound
AlreadyExists
PermissionDenied
ResourceExhausted
FailedPrecondition
Aborted
OutOfRange
Unimplemented
Internal
Unavailable
DataLoss
Unauthenticated
}

gRPC status codes
impl Eq for GrpcStatus
impl Show for GrpcStatus

#
GrpcStatus::code

fn GrpcStatus::code(self : GrpcStatus) -> Int

#
GrpcStatus::from_code

fn GrpcStatus::from_code(code : Int) -> GrpcStatus

#
HealthService

pub struct HealthService {
status_map : Array[(String, ServingStatus)]
}

Health check service

#
HealthService::check

fn HealthService::check(self : HealthService, service : String) -> ServingStatus

#
HealthService::clear_status

fn HealthService::clear_status(self : HealthService, service : String) -> Unit

#
HealthService::new

#
HealthService::set_status

fn HealthService::set_status(self : HealthService, service : String, status : ServingStatus) -> Unit

#
JsonObjectBuilder

pub struct JsonObjectBuilder {
fields : Array[(String, JsonValue)]
}

JSON object builder for convenient construction

#
JsonObjectBuilder::add_array

fn JsonObjectBuilder::add_array(self : JsonObjectBuilder, name : String, value : Array[JsonValue]) -> JsonObjectBuilder

Add an array field

#
JsonObjectBuilder::add_bool

fn JsonObjectBuilder::add_bool(self : JsonObjectBuilder, name : String, value : Bool) -> JsonObjectBuilder

Add a boolean field

#
JsonObjectBuilder::add_float

fn JsonObjectBuilder::add_float(self : JsonObjectBuilder, name : String, value : Double) -> JsonObjectBuilder

Add a float field

#
JsonObjectBuilder::add_int

fn JsonObjectBuilder::add_int(self : JsonObjectBuilder, name : String, value : Int) -> JsonObjectBuilder

Add an integer field

#
JsonObjectBuilder::add_int64

fn JsonObjectBuilder::add_int64(self : JsonObjectBuilder, name : String, value : Int64) -> JsonObjectBuilder

Add an Int64 field

#
JsonObjectBuilder::add_null

fn JsonObjectBuilder::add_null(self : JsonObjectBuilder, name : String) -> JsonObjectBuilder

Add a null field

#
JsonObjectBuilder::add_object

fn JsonObjectBuilder::add_object(self : JsonObjectBuilder, name : String, value : JsonObjectBuilder) -> JsonObjectBuilder

Add a nested object field

#
JsonObjectBuilder::add_string

fn JsonObjectBuilder::add_string(self : JsonObjectBuilder, name : String, value : String) -> JsonObjectBuilder

Add a string field

#
JsonObjectBuilder::add_uint

fn JsonObjectBuilder::add_uint(self : JsonObjectBuilder, name : String, value : UInt) -> JsonObjectBuilder

Add a UInt field

#
JsonObjectBuilder::add_uint64

fn JsonObjectBuilder::add_uint64(self : JsonObjectBuilder, name : String, value : UInt64) -> JsonObjectBuilder

Add a UInt64 field

#
JsonObjectBuilder::add_value

fn JsonObjectBuilder::add_value(self : JsonObjectBuilder, name : String, value : JsonValue) -> JsonObjectBuilder

Add a JsonValue field

#
JsonObjectBuilder::build

Build the JSON value

#
JsonObjectBuilder::new

Create a new JSON object builder

#
JsonObjectBuilder::to_json_string

fn JsonObjectBuilder::to_json_string(self : JsonObjectBuilder) -> String

Convert to JSON string

#
JsonValue

pub enum JsonValue {
Null
Bool(Bool)
Int(Int)
Int64(Int64)
UInt(UInt)
UInt64(UInt64)
Float(Double)
String(String)
Array(Array[JsonValue])
Object(Array[(String, JsonValue)])
}

JSON value types

#
JsonValue::array

fn JsonValue::array(arr : Array[JsonValue]) -> JsonValue

Create an array JSON value

#
JsonValue::bool

fn JsonValue::bool(b : Bool) -> JsonValue

Create a boolean JSON value

#
JsonValue::float

fn JsonValue::float(f : Double) -> JsonValue

Create a float JSON value

#
JsonValue::int

fn JsonValue::int(n : Int) -> JsonValue

Create an integer JSON value

#
JsonValue::int64

fn JsonValue::int64(n : Int64) -> JsonValue

Create an Int64 JSON value

#
JsonValue::null

fn JsonValue::null() -> JsonValue

Create a null JSON value

#
JsonValue::object

fn JsonValue::object(fields : Array[(String, JsonValue)]) -> JsonValue

Create an object JSON value

#
JsonValue::string

fn JsonValue::string(s : String) -> JsonValue

Create a string JSON value

#
JsonValue::to_string

fn JsonValue::to_string(self : JsonValue) -> String

Convert a JsonValue to a JSON string

#
JsonValue::uint

fn JsonValue::uint(n : UInt) -> JsonValue

Create a UInt JSON value

#
JsonValue::uint64

fn JsonValue::uint64(n : UInt64) -> JsonValue

Create a UInt64 JSON value

#
KeyValue

pub struct KeyValue {
buf : ByteBuffer
pos : Int
}

Key-value pair for attributes

#
KeyValue::key

fn KeyValue::key(self : KeyValue) -> String

#
KeyValue::new

fn KeyValue::new(buf : ByteBuffer, pos : Int) -> KeyValue

#
KeyValue::value

fn KeyValue::value(self : KeyValue) -> String

#
MessageFrame

pub struct MessageFrame {
compressed : Bool
length : Int
data : FixedArray[Byte]
}

gRPC message frame (Length-Prefixed Message)

#
MessageFrame::decode

fn MessageFrame::decode(data : FixedArray[Byte]) -> MessageFrame?

Decode frame from wire format

#
MessageFrame::encode

fn MessageFrame::encode(self : MessageFrame) -> FixedArray[Byte]

Encode frame to wire format

#
MessageFrame::new

fn MessageFrame::new(data : FixedArray[Byte], compressed : Bool) -> MessageFrame

#
Metadata

pub struct Metadata {
entries : Array[(String, String)]
}

Key-value metadata for gRPC calls

#
Metadata::add

fn Metadata::add(self : Metadata, key : String, value : String) -> Metadata

#
Metadata::get

fn Metadata::get(self : Metadata, key : String) -> String?

#
Metadata::get_all

fn Metadata::get_all(self : Metadata, key : String) -> Array[String]

#
Metadata::is_empty

fn Metadata::is_empty(self : Metadata) -> Bool

#
Metadata::len

fn Metadata::len(self : Metadata) -> Int

#
Metadata::new

fn Metadata::new() -> Metadata

#
Metadata::remove

fn Metadata::remove(self : Metadata, key : String) -> Metadata

#
MethodDescriptor

pub struct MethodDescriptor {
service_name : String
method_name : String
method_type : MethodType
full_path : String
}

Method descriptor

#
MethodDescriptor::new

fn MethodDescriptor::new(service_name : String, method_name : String, method_type : MethodType) -> MethodDescriptor

#
MethodType

pub(all) enum MethodType {
Unary
ServerStreaming
ClientStreaming
BidirectionalStreaming
}

Method type for gRPC
impl Eq for MethodType
impl Show for MethodType

#
ObjectBuilder

pub struct ObjectBuilder {
builder : Builder
schema : TableSchema
string_offsets : Map[String, Int]
vector_offsets : Map[String, Int]
table_offsets : Map[String, Int]
}

Object builder wraps a Builder with schema information

#
ObjectBuilder::add_bool

fn ObjectBuilder::add_bool(self : ObjectBuilder, name : String, value : Bool) -> ObjectBuilder

Add a boolean field

#
ObjectBuilder::add_int16

fn ObjectBuilder::add_int16(self : ObjectBuilder, name : String, value : Int) -> ObjectBuilder

Add an int16 field

#
ObjectBuilder::add_int32

fn ObjectBuilder::add_int32(self : ObjectBuilder, name : String, value : Int) -> ObjectBuilder

Add an int32 field

#
ObjectBuilder::add_uint8

fn ObjectBuilder::add_uint8(self : ObjectBuilder, name : String, value : Int) -> ObjectBuilder

Add a uint8 field

#
ObjectBuilder::end

fn ObjectBuilder::end(self : ObjectBuilder) -> Int

End the object and return its offset

#
ObjectBuilder::finish_buffer

fn ObjectBuilder::finish_buffer(self : ObjectBuilder) -> Unit

Convenience method to finish the buffer with this object as root

#
ObjectBuilder::finish_fields

fn ObjectBuilder::finish_fields(self : ObjectBuilder) -> Unit

Finish adding scalar fields and add pre-created offsets

#
ObjectBuilder::get_builder

fn ObjectBuilder::get_builder(self : ObjectBuilder) -> Builder

Get the underlying builder

#
ObjectBuilder::new

fn ObjectBuilder::new(builder : Builder, schema : TableSchema) -> ObjectBuilder

Create an object builder

#
ObjectBuilder::set_int32_vector

fn ObjectBuilder::set_int32_vector(self : ObjectBuilder, name : String, values : Array[Int]) -> ObjectBuilder

Set an int32 vector field (must be called before start_object)

#
ObjectBuilder::set_shared_string

fn ObjectBuilder::set_shared_string(self : ObjectBuilder, name : String, value : String) -> ObjectBuilder

Set a shared string field (must be called before start_object)

#
ObjectBuilder::set_string

fn ObjectBuilder::set_string(self : ObjectBuilder, name : String, value : String) -> ObjectBuilder

Set a string field (must be called before start_object)

#
ObjectBuilder::set_table_offset

fn ObjectBuilder::set_table_offset(self : ObjectBuilder, name : String, offset : Int) -> ObjectBuilder

Set a nested table offset (from another ObjectBuilder)

#
ObjectBuilder::start

fn ObjectBuilder::start(self : ObjectBuilder) -> Unit

Start building the object

#
ObjectReader

pub struct ObjectReader {
table : Table
schema : TableSchema
}

Object reader wraps a Table with schema information

#
ObjectReader::get_bool

fn ObjectReader::get_bool(self : ObjectReader, name : String) -> Bool

Get a boolean field by name

#
ObjectReader::get_int16

fn ObjectReader::get_int16(self : ObjectReader, name : String) -> Int

Get an int16 field by name

#
ObjectReader::get_int32

fn ObjectReader::get_int32(self : ObjectReader, name : String) -> Int

Get an int32 field by name

#
ObjectReader::get_string

fn ObjectReader::get_string(self : ObjectReader, name : String) -> String

Get a string field by name

#
ObjectReader::get_table

fn ObjectReader::get_table(self : ObjectReader) -> Table

Get the underlying table

#
ObjectReader::get_table_field

fn ObjectReader::get_table_field(self : ObjectReader, name : String) -> Table?

Get a nested table by name

#
ObjectReader::get_uint8

fn ObjectReader::get_uint8(self : ObjectReader, name : String) -> Int

Get a uint8 field by name

#
ObjectReader::get_vector_length

fn ObjectReader::get_vector_length(self : ObjectReader, name : String) -> Int

Get vector length by field name

#
ObjectReader::new

fn ObjectReader::new(table : Table, schema : TableSchema) -> ObjectReader

Create an object reader

#
ObjectReader::to_json

fn ObjectReader::to_json(self : ObjectReader) -> JsonValue

Convert to JSON using schema

#
ReflectionEnum

pub struct ReflectionEnum {
buf : ByteBuffer
pos : Int
}

An enumeration type definition

#
ReflectionEnum::is_union

fn ReflectionEnum::is_union(self : ReflectionEnum) -> Bool

#
ReflectionEnum::name

fn ReflectionEnum::name(self : ReflectionEnum) -> String

#
ReflectionEnum::new

fn ReflectionEnum::new(buf : ByteBuffer, pos : Int) -> ReflectionEnum

#
ReflectionEnum::underlying_type

fn ReflectionEnum::underlying_type(self : ReflectionEnum) -> ReflectionType?

#
ReflectionEnum::values

fn ReflectionEnum::values(self : ReflectionEnum, index : Int) -> EnumVal?

#
ReflectionEnum::values_length

fn ReflectionEnum::values_length(self : ReflectionEnum) -> Int

#
ReflectionField

pub struct ReflectionField {
buf : ByteBuffer
pos : Int
}

A field definition in a table or struct

#
ReflectionField::default_integer

fn ReflectionField::default_integer(self : ReflectionField) -> Int64

#
ReflectionField::default_real

fn ReflectionField::default_real(self : ReflectionField) -> Double

#
ReflectionField::deprecated

fn ReflectionField::deprecated(self : ReflectionField) -> Bool

#
ReflectionField::field_type

#
ReflectionField::id

fn ReflectionField::id(self : ReflectionField) -> Int

#
ReflectionField::key

fn ReflectionField::key(self : ReflectionField) -> Bool

#
ReflectionField::name

fn ReflectionField::name(self : ReflectionField) -> String

#
ReflectionField::new

fn ReflectionField::new(buf : ByteBuffer, pos : Int) -> ReflectionField

#
ReflectionField::offset

fn ReflectionField::offset(self : ReflectionField) -> Int

#
ReflectionField::optional

fn ReflectionField::optional(self : ReflectionField) -> Bool

#
ReflectionField::required

fn ReflectionField::required(self : ReflectionField) -> Bool

#
ReflectionObject

pub struct ReflectionObject {
buf : ByteBuffer
pos : Int
}

A table or struct definition

#
ReflectionObject::bytesize

fn ReflectionObject::bytesize(self : ReflectionObject) -> Int

#
ReflectionObject::field_by_name

fn ReflectionObject::field_by_name(self : ReflectionObject, name : String) -> ReflectionField?

Find a field by name

#
ReflectionObject::fields

fn ReflectionObject::fields(self : ReflectionObject, index : Int) -> ReflectionField?

#
ReflectionObject::fields_length

fn ReflectionObject::fields_length(self : ReflectionObject) -> Int

#
ReflectionObject::is_struct

fn ReflectionObject::is_struct(self : ReflectionObject) -> Bool

#
ReflectionObject::minalign

fn ReflectionObject::minalign(self : ReflectionObject) -> Int

#
ReflectionObject::name

fn ReflectionObject::name(self : ReflectionObject) -> String

#
ReflectionObject::new

fn ReflectionObject::new(buf : ByteBuffer, pos : Int) -> ReflectionObject

#
ReflectionSchema

pub struct ReflectionSchema {
buf : ByteBuffer
}

The root schema definition

#
ReflectionSchema::enum_by_name

fn ReflectionSchema::enum_by_name(self : ReflectionSchema, name : String) -> ReflectionEnum?

Find an enum by name

#
ReflectionSchema::enums

fn ReflectionSchema::enums(self : ReflectionSchema, index : Int) -> ReflectionEnum?

Get an enum by index

#
ReflectionSchema::enums_length

fn ReflectionSchema::enums_length(self : ReflectionSchema) -> Int

Get the number of enums

#
ReflectionSchema::file_ext

fn ReflectionSchema::file_ext(self : ReflectionSchema) -> String

Get the file extension

#
ReflectionSchema::file_ident

fn ReflectionSchema::file_ident(self : ReflectionSchema) -> String

Get the file identifier

#
ReflectionSchema::from_bytes

fn ReflectionSchema::from_bytes(data : FixedArray[Byte]) -> ReflectionSchema

Parse a binary schema (.bfbs) file

#
ReflectionSchema::is_valid

fn ReflectionSchema::is_valid(self : ReflectionSchema) -> Bool

Check if this is a valid binary schema

#
ReflectionSchema::object_by_name

fn ReflectionSchema::object_by_name(self : ReflectionSchema, name : String) -> ReflectionObject?

Find an object by name

#
ReflectionSchema::objects

fn ReflectionSchema::objects(self : ReflectionSchema, index : Int) -> ReflectionObject?

Get an object by index

#
ReflectionSchema::objects_length

fn ReflectionSchema::objects_length(self : ReflectionSchema) -> Int

Get the number of objects (tables/structs)

#
ReflectionSchema::root_table

Get the root table type

#
ReflectionService

pub struct ReflectionService {
services : Array[ServiceDescriptor]
}

Service for gRPC reflection

#
ReflectionService::get_service

fn ReflectionService::get_service(self : ReflectionService, name : String) -> ServiceDescriptor?

#
ReflectionService::list_services

fn ReflectionService::list_services(self : ReflectionService) -> Array[String]

#
ReflectionService::new

#
ReflectionService::register

fn ReflectionService::register(self : ReflectionService, service : ServiceDescriptor) -> Unit

#
ReflectionType

pub struct ReflectionType {
buf : ByteBuffer
pos : Int
}

Type information for a field

#
ReflectionType::base_size

fn ReflectionType::base_size(self : ReflectionType) -> Int

Get base size (in bytes)

#
ReflectionType::base_type

fn ReflectionType::base_type(self : ReflectionType) -> BaseType

Get the base type

#
ReflectionType::element

fn ReflectionType::element(self : ReflectionType) -> BaseType

Get the element type (for vectors and arrays)

#
ReflectionType::element_size

fn ReflectionType::element_size(self : ReflectionType) -> Int

Get element size (for vectors)

#
ReflectionType::fixed_length

fn ReflectionType::fixed_length(self : ReflectionType) -> Int

Get fixed length (for Array type)

#
ReflectionType::index

fn ReflectionType::index(self : ReflectionType) -> Int

Get the index to the object (for Obj type)

#
ReflectionType::new

fn ReflectionType::new(buf : ByteBuffer, pos : Int) -> ReflectionType

#
ScalarType

pub enum ScalarType {
Bool
Byte
UByte
Short
UShort
Int
UInt
Long
ULong
Float
Double
}

Scalar types in FlatBuffers

#
ScalarType::default_value

fn ScalarType::default_value(self : ScalarType) -> String

#
ScalarType::from_string

fn ScalarType::from_string(s : String) -> ScalarType?

#
ScalarType::to_builder_method

fn ScalarType::to_builder_method(self : ScalarType) -> String

#
ScalarType::to_getter_method

fn ScalarType::to_getter_method(self : ScalarType) -> String

#
ScalarType::to_moonbit_type

fn ScalarType::to_moonbit_type(self : ScalarType) -> String

#
SchemaAst

pub struct SchemaAst {
ns : String
enums : Array[EnumAst]
structs : Array[StructAst]
tables : Array[TableAst]
unions : Array[UnionAst]
root_type : String?
}

Schema definition

#
SchemaAst::new

fn SchemaAst::new() -> SchemaAst

#
ServerContext

pub struct ServerContext {
metadata : Metadata
response_headers : Metadata
response_trailers : Metadata
deadline : Int64?
peer : String
cancelled : Bool
}

Context for server-side call handling

#
ServerContext::is_cancelled

fn ServerContext::is_cancelled(self : ServerContext) -> Bool

#
ServerContext::new

#
ServerContext::set_header

fn ServerContext::set_header(self : ServerContext, key : String, value : String) -> Unit

#
ServerContext::set_trailer

fn ServerContext::set_trailer(self : ServerContext, key : String, value : String) -> Unit

#
ServerContext::with_deadline

fn ServerContext::with_deadline(self : ServerContext, deadline : Int64) -> ServerContext

#
ServerContext::with_metadata

fn ServerContext::with_metadata(self : ServerContext, metadata : Metadata) -> ServerContext

#
ServerContext::with_peer

fn ServerContext::with_peer(self : ServerContext, peer : String) -> ServerContext

#
ServerInterceptor

pub struct ServerInterceptor {
on_request : (ServerContext, FixedArray[Byte]) -> FixedArray[Byte]
on_response : (ServerContext, FixedArray[Byte]) -> FixedArray[Byte]
}

Server interceptor for handling incoming calls

#
ServerInterceptor::new

fn ServerInterceptor::new(on_request : (ServerContext, FixedArray[Byte]) -> FixedArray[Byte], on_response : (ServerContext, FixedArray[Byte]) -> FixedArray[Byte]) -> ServerInterceptor

#
ServerStream

pub struct ServerStream[T] {
read_fn : () -> T?
done : Bool
}

Readable stream of messages

#
ServerStream::new

fn[T] ServerStream::new(read_fn : () -> T?) -> ServerStream[T]

#
ServerStream::read

fn[T] ServerStream::read(self : ServerStream[T]) -> T?

#
ServiceDescriptor

pub struct ServiceDescriptor {
name : String
methods : Array[MethodDescriptor]
}

Descriptor for a gRPC service

#
ServiceDescriptor::add_method

#
ServiceDescriptor::get_method

fn ServiceDescriptor::get_method(self : ServiceDescriptor, name : String) -> MethodDescriptor?

#
ServiceDescriptor::new

fn ServiceDescriptor::new(name : String) -> ServiceDescriptor

#
ServingStatus

pub(all) enum ServingStatus {
Unknown
Serving
NotServing
ServiceUnknown
}

Health check status
impl Eq for ServingStatus

#
ServingStatus::to_int

fn ServingStatus::to_int(self : ServingStatus) -> Int

#
StructAst

pub struct StructAst {
name : String
fields : Array[FieldAst]
}

Struct definition in schema (fixed-size)

#
Table

pub struct Table {
buf : ByteBuffer
pos : Int
}

Table provides read access to a FlatBuffer table. It handles vtable lookups and field access.

#
Table::get_bool

fn Table::get_bool(self : Table, field_slot : Int, default : Bool) -> Bool

Get a boolean field

#
Table::get_bool_optional

fn Table::get_bool_optional(self : Table, field_slot : Int) -> Bool?

Get an optional boolean field (returns None if not present)

#
Table::get_float32

fn Table::get_float32(self : Table, field_slot : Int, default : Float) -> Float

Get a Float32 field

#
Table::get_float32_optional

fn Table::get_float32_optional(self : Table, field_slot : Int) -> Float?

Get an optional Float32 field

#
Table::get_float64

fn Table::get_float64(self : Table, field_slot : Int, default : Double) -> Double

Get a Float64 field

#
Table::get_float64_optional

fn Table::get_float64_optional(self : Table, field_slot : Int) -> Double?

Get an optional Float64 field

#
Table::get_int16

fn Table::get_int16(self : Table, field_slot : Int, default : Int) -> Int

Get an Int16 field

#
Table::get_int16_optional

fn Table::get_int16_optional(self : Table, field_slot : Int) -> Int?

Get an optional Int16 field

#
Table::get_int32

fn Table::get_int32(self : Table, field_slot : Int, default : Int) -> Int

Get an Int32 field

#
Table::get_int32_optional

fn Table::get_int32_optional(self : Table, field_slot : Int) -> Int?

Get an optional Int32 field

#
Table::get_int64

fn Table::get_int64(self : Table, field_slot : Int, default : Int64) -> Int64

Get an Int64 field

#
Table::get_int64_optional

fn Table::get_int64_optional(self : Table, field_slot : Int) -> Int64?

Get an optional Int64 field

#
Table::get_int8

fn Table::get_int8(self : Table, field_slot : Int, default : Int) -> Int

Get an Int8 field

#
Table::get_int8_optional

fn Table::get_int8_optional(self : Table, field_slot : Int) -> Int?

Get an optional Int8 field

#
Table::get_nested_flatbuffer

fn Table::get_nested_flatbuffer(self : Table, field_slot : Int) -> ByteBuffer?

Get a nested FlatBuffer from a table field. Returns a ByteBuffer that can be used to read the nested data. Returns None if the field is not present.

#
Table::get_nested_root

fn Table::get_nested_root(self : Table, field_slot : Int) -> Table?

Get a nested FlatBuffer's root table directly. Returns None if the field is not present.

#
Table::get_root

fn Table::get_root(buf : ByteBuffer) -> Table

Get the root table from a buffer

#
Table::get_root_size_prefixed

fn Table::get_root_size_prefixed(buf : ByteBuffer) -> Table

Get root table from a size-prefixed buffer

#
Table::get_string

fn Table::get_string(self : Table, field_slot : Int, default : String) -> String

Get a string field

#
Table::get_string_optional

fn Table::get_string_optional(self : Table, field_slot : Int) -> String?

Get an optional string field

#
Table::get_struct

fn Table::get_struct(self : Table, field_slot : Int) -> Int?

Get a struct field (returns the position in buffer where struct data starts)

#
Table::get_table

fn Table::get_table(self : Table, field_slot : Int) -> Table?

Get a nested table field

#
Table::get_table_offset

fn Table::get_table_offset(self : Table, field_slot : Int) -> Int?

Get the offset to a nested table field

#
Table::get_uint16

fn Table::get_uint16(self : Table, field_slot : Int, default : Int) -> Int

Get a UInt16 field

#
Table::get_uint16_optional

fn Table::get_uint16_optional(self : Table, field_slot : Int) -> Int?

Get an optional UInt16 field

#
Table::get_uint32

fn Table::get_uint32(self : Table, field_slot : Int, default : UInt) -> UInt

Get a UInt32 field

#
Table::get_uint32_optional

fn Table::get_uint32_optional(self : Table, field_slot : Int) -> UInt?

Get an optional UInt32 field

#
Table::get_uint64

fn Table::get_uint64(self : Table, field_slot : Int, default : UInt64) -> UInt64

Get a UInt64 field

#
Table::get_uint64_optional

fn Table::get_uint64_optional(self : Table, field_slot : Int) -> UInt64?

Get an optional UInt64 field

#
Table::get_uint8

fn Table::get_uint8(self : Table, field_slot : Int, default : Int) -> Int

Get a UInt8 field

#
Table::get_uint8_optional

fn Table::get_uint8_optional(self : Table, field_slot : Int) -> Int?

Get an optional UInt8 field

#
Table::get_union_table

fn Table::get_union_table(self : Table, value_slot : Int) -> Table?

Get a union table from the value slot Returns None if the union type is NONE (0) or offset is invalid

#
Table::get_union_type

fn Table::get_union_type(self : Table, type_slot : Int) -> Int

Get the union type from a table

#
Table::get_vector_byte

fn Table::get_vector_byte(self : Table, field_slot : Int, index : Int) -> Byte

Get a byte element from a vector

#
Table::get_vector_bytes_slice

fn Table::get_vector_bytes_slice(self : Table, field_slot : Int) -> FixedArray[Byte]

Get entire byte vector as FixedArray (optimized with blit)

#
Table::get_vector_float64

fn Table::get_vector_float64(self : Table, field_slot : Int, index : Int) -> Double

Get a float64 element from a vector

#
Table::get_vector_float64_batch

fn Table::get_vector_float64_batch(self : Table, field_slot : Int, start_index : Int, count : Int) -> Array[Double]

Batch read multiple float64 values from a vector efficiently

#
Table::get_vector_int32

fn Table::get_vector_int32(self : Table, field_slot : Int, index : Int) -> Int

Get an Int32 element from a vector

#
Table::get_vector_int32_batch

fn Table::get_vector_int32_batch(self : Table, field_slot : Int, start_index : Int, count : Int) -> Array[Int]

Batch read multiple int32 values from a vector efficiently

#
Table::get_vector_length

fn Table::get_vector_length(self : Table, field_slot : Int) -> Int

Get the vector length for a vector field

#
Table::get_vector_start

fn Table::get_vector_start(self : Table, field_slot : Int) -> Int

Get the start of vector data

#
Table::get_vector_string

fn Table::get_vector_string(self : Table, field_slot : Int, index : Int) -> String

Get a string element from a vector of strings

#
Table::get_vector_table

fn Table::get_vector_table(self : Table, field_slot : Int, index : Int) -> Table?

Get a table element from a vector of tables

#
Table::has_field

fn Table::has_field(self : Table, field_slot : Int) -> Bool

Check if a field is present

#
Table::mutate_bool

fn Table::mutate_bool(self : Table, field_slot : Int, value : Bool) -> Bool

Mutate a boolean field in-place Returns true if the field exists and was mutated

#
Table::mutate_float32

fn Table::mutate_float32(self : Table, field_slot : Int, value : Float) -> Bool

Mutate a Float32 field in-place

#
Table::mutate_float64

fn Table::mutate_float64(self : Table, field_slot : Int, value : Double) -> Bool

Mutate a Float64 field in-place

#
Table::mutate_int16

fn Table::mutate_int16(self : Table, field_slot : Int, value : Int) -> Bool

Mutate an Int16 field in-place

#
Table::mutate_int32

fn Table::mutate_int32(self : Table, field_slot : Int, value : Int) -> Bool

Mutate an Int32 field in-place

#
Table::mutate_int64

fn Table::mutate_int64(self : Table, field_slot : Int, value : Int64) -> Bool

Mutate an Int64 field in-place

#
Table::mutate_int8

fn Table::mutate_int8(self : Table, field_slot : Int, value : Int) -> Bool

Mutate an Int8 field in-place

#
Table::mutate_uint16

fn Table::mutate_uint16(self : Table, field_slot : Int, value : Int) -> Bool

Mutate a UInt16 field in-place

#
Table::mutate_uint32

fn Table::mutate_uint32(self : Table, field_slot : Int, value : UInt) -> Bool

Mutate a UInt32 field in-place

#
Table::mutate_uint64

fn Table::mutate_uint64(self : Table, field_slot : Int, value : UInt64) -> Bool

Mutate a UInt64 field in-place

#
Table::mutate_uint8

fn Table::mutate_uint8(self : Table, field_slot : Int, value : Int) -> Bool

Mutate a UInt8 field in-place

#
Table::mutate_vector_byte

fn Table::mutate_vector_byte(self : Table, field_slot : Int, index : Int, value : Byte) -> Bool

Mutate an element in a byte vector

#
Table::mutate_vector_float64

fn Table::mutate_vector_float64(self : Table, field_slot : Int, index : Int, value : Double) -> Bool

Mutate an element in a Float64 vector

#
Table::mutate_vector_int32

fn Table::mutate_vector_int32(self : Table, field_slot : Int, index : Int, value : Int) -> Bool

Mutate an element in an Int32 vector

#
Table::new

fn Table::new(buf : ByteBuffer, pos : Int) -> Table

Create a Table from a ByteBuffer at the given position

#
Table::vector_byte_to_json

fn Table::vector_byte_to_json(self : Table, slot : Int) -> JsonValue

Convert a byte vector to JSON array

#
Table::vector_int32_to_json

fn Table::vector_int32_to_json(self : Table, slot : Int) -> JsonValue

Convert an int vector to JSON array

#
Table::verify_nested_flatbuffer

fn Table::verify_nested_flatbuffer(self : Table, field_slot : Int, verifier : Verifier) -> Bool

Verify a nested FlatBuffer field. Returns true if the field is absent or contains a valid FlatBuffer.

#
Table::vtable_offset

fn Table::vtable_offset(self : Table, field : Int) -> Int

Get the vtable offset for a field

#
TableAst

pub struct TableAst {
name : String
fields : Array[FieldAst]
}

Table definition in schema (variable-size)

#
TableSchema

pub struct TableSchema {
name : String
fields : Array[FieldDef]
field_map : Map[String, Int]
}

Table schema definition

#
TableSchema::field_count

fn TableSchema::field_count(self : TableSchema) -> Int

Get number of fields

#
TableSchema::get_field

fn TableSchema::get_field(self : TableSchema, name : String) -> FieldDef?

Get field definition by name

#
TableSchema::new

fn TableSchema::new(name : String, fields : Array[FieldDef]) -> TableSchema

Create a new table schema

#
UnionAst

pub struct UnionAst {
name : String
types : Array[String]
}

Union definition in schema

#
Verifier

pub struct Verifier {
buf : ByteBuffer
opts : VerifierOptions
depth : Int
num_tables : Int
}

Verifier for FlatBuffer validation

#
Verifier::from_buffer

fn Verifier::from_buffer(buf : ByteBuffer) -> Verifier

Create a verifier with default options

#
Verifier::new

fn Verifier::new(buf : ByteBuffer, opts : VerifierOptions) -> Verifier

Create a new verifier

#
Verifier::pop_depth

fn Verifier::pop_depth(self : Verifier) -> Unit

Pop depth after nested verification

#
Verifier::push_depth

fn Verifier::push_depth(self : Verifier) -> Bool

Push depth for nested verification

#
Verifier::verify_alignment

fn Verifier::verify_alignment(self : Verifier, pos : Int, align : Int) -> Bool

Check alignment

#
Verifier::verify_buffer

fn Verifier::verify_buffer(self : Verifier) -> Bool

Verify a buffer has a valid root table

#
Verifier::verify_buffer_with_identifier

fn Verifier::verify_buffer_with_identifier(self : Verifier, identifier : String) -> Bool

Verify a buffer with file identifier

#
Verifier::verify_range

fn Verifier::verify_range(self : Verifier, start : Int, len : Int) -> Bool

Check if a range is within buffer bounds

#
Verifier::verify_scalar

fn Verifier::verify_scalar(self : Verifier, pos : Int, size : Int) -> Bool

Verify a scalar at position

#
Verifier::verify_size_prefixed_buffer

fn Verifier::verify_size_prefixed_buffer(self : Verifier) -> Bool

Verify a size-prefixed buffer

#
Verifier::verify_string

fn Verifier::verify_string(self : Verifier, pos : Int) -> Bool

Verify a string at offset position

#
Verifier::verify_table_start

fn Verifier::verify_table_start(self : Verifier, pos : Int) -> Bool

Verify a table at position (basic verification)

#
Verifier::verify_vector

fn Verifier::verify_vector(self : Verifier, pos : Int, elem_size : Int) -> Bool

Verify a vector at offset position

#
VerifierOptions

pub struct VerifierOptions {
max_depth : Int
max_tables : Int
check_alignment : Bool
}

Verifier options

#
VerifierOptions::default

Create default verifier options

#
VerifierOptions::new

fn VerifierOptions::new(max_depth : Int, max_tables : Int, check_alignment : Bool) -> VerifierOptions

Create custom verifier options

#
flex_parse

fn flex_parse(data : FixedArray[Byte]) -> FlexRef

Parse FlexBuffer from bytes

#
generate_moonbit

fn generate_moonbit(schema : SchemaAst) -> String

Generate MoonBit code from schema

#
parse_schema

fn parse_schema(input : String) -> SchemaAst

Parse a FlatBuffers schema

#
read_field_dynamic

fn read_field_dynamic(table : Table, field : ReflectionField) -> JsonValue

Read a field value dynamically using reflection

#
table_to_json_dynamic

fn table_to_json_dynamic(table : Table, obj : ReflectionObject) -> JsonValue

Convert a table to JSON using schema reflection