protobuf

The runtime library for protobuf

idl
protobuf
codegen
moon add moonbitlang/protobuf@0.1.2
Download zip
Version
0.1.2
License
Apache-2.0 WITH LLVM-exception
Last updated
2 months ago
Downloads
1K
README

#Protobuf Runtime

This package contains the MoonBit Protobuf runtime library, providing essential support for Protobuf message serialization and deserialization.

#Directory Structure

  • src/
    • reader.mbt / writer.mbt: Basic read/write interfaces
    • async_reader.mbt / async_writer.mbt: Asynchronous read/write interfaces
    • json_utils.mbt: JSON utilities
    • proto.mbt: Protobuf traits definitions
    • types.mbt: Type definitions
    • sizeof.mbt: Message size calculation
    • reader_impl.mbt / writer_impl.mbt: Implementation reader/writer
    • reader_test.mbt / writer_test.mbt: Test cases

#
AsyncProto

pub(open) trait AsyncProto : AsyncRead + AsyncWrite {
}

#
AsyncRead

pub(open) trait AsyncRead {
async fn read(&AsyncReader) -> Self = _
async fn read_with_limit(LimitedReader[&AsyncReader]) -> Self
}

#
AsyncReader

pub(open) trait AsyncReader {
async fn read(Self, FixedArray[Byte], offset~ : Int, max_length~ : Int) -> Int?
}

#
AsyncWrite

pub(open) trait AsyncWrite {
async fn write(Self, &AsyncWriter) -> Unit
}

#
AsyncWriter

pub(open) trait AsyncWriter {
async fn write(Self, BytesView) -> Unit
}

#
Proto

pub(open) trait Proto : Read + Write {
}

#
Read

pub(open) trait Read {
fn read(&Reader) -> Self raise = _
fn read_with_limit(LimitedReader[&Reader]) -> Self raise
}

#
Reader

pub(open) trait Reader {
fn read(Self, FixedArray[Byte], offset~ : Int, max_length~ : Int) -> Int? raise
}

Trait representing the reader

#
Sized

pub(open) trait Sized {
fn size_of(Self) -> UInt
}

impl Sized for Bool
impl Sized for Int
impl Sized for Int64
impl Sized for UInt
impl Sized for UInt64
impl Sized for Float
impl Sized for Double
impl Sized for String
impl Sized for Bytes

#
Write

pub(open) trait Write {
fn write(Self, &Writer) -> Unit raise
}

#
Writer

pub(open) trait Writer {
fn write(Self, BytesView) -> Unit raise
}

Trait representing the Writer
impl Writer for Buffer

#
ReaderError

pub(all) suberror ReaderError {
EndOfStream
InvalidString
UnknownWireType(UInt)
} derive(Eq,
Debug
)

impl Show for ReaderError

#
BytesReader

type BytesReader

impl Show for BytesReader

#
BytesReader::from_bytes

fn BytesReader::from_bytes(data : Bytes) -> BytesReader

#
Enum

pub(all) struct Enum(UInt) derive(Default, Eq,
Debug
)

Enum
impl Show for Enum
impl Sized for Enum

#
Len

pub(all) struct Len(Int) derive(Default, Eq,
Debug
)

length
impl Show for Len

#
LimitedReader

pub(all) struct LimitedReader[T] {
reader : T
limit : Int?
}

impl Reader for LimitedReader[T]

#
LimitedReader::new

fn[T] LimitedReader::new(reader : T, limit? : Int) -> LimitedReader[T]

#
SInt

pub(all) struct SInt(Int) derive(Default, Eq,
Debug
)

sint32
impl Show for SInt
impl Sized for SInt

#
SInt64

pub(all) struct SInt64(Int64) derive(Default, Eq,
Debug
)

sint64
impl Show for SInt64
impl Sized for SInt64

#
async_read_bool

async fn[T : AsyncReader] async_read_bool(reader : T) -> Bool

#
async_read_bytes

async fn[T : AsyncReader] async_read_bytes(reader : T) -> Bytes

#
async_read_double

async fn[T : AsyncReader] async_read_double(reader : T) -> Double

#
async_read_enum

async fn[T : AsyncReader] async_read_enum(reader : T) -> Enum

#
async_read_fixed32

async fn[T : AsyncReader] async_read_fixed32(reader : T) -> UInt

#
async_read_fixed64

async fn[T : AsyncReader] async_read_fixed64(reader : T) -> UInt64

#
async_read_float

async fn[T : AsyncReader] async_read_float(reader : T) -> Float

#
async_read_int32

async fn[T : AsyncReader] async_read_int32(reader : T) -> Int

#
async_read_int64

async fn[T : AsyncReader] async_read_int64(reader : T) -> Int64

#
async_read_message

async fn[M : AsyncRead + Default] async_read_message(reader : LimitedReader[&AsyncReader]) -> M

#
async_read_packed

async fn[M : Sized, R : AsyncReader] async_read_packed(reader : R, async_read_fn : async (LimitedReader[R]) -> M, size : UInt?) -> Array[M]

Reads packed repeated field (Array[M])

Note: packed field are stored as a variable length chunk of data, while regular repeated fields behaves like an iterator, yielding their tag everytime

#
async_read_sfixed32

async fn[T : AsyncReader] async_read_sfixed32(reader : T) -> Int

#
async_read_sfixed64

async fn[T : AsyncReader] async_read_sfixed64(reader : T) -> Int64

#
async_read_sint32

async fn[T : AsyncReader] async_read_sint32(reader : T) -> SInt

#
async_read_sint64

async fn[T : AsyncReader] async_read_sint64(reader : T) -> SInt64

#
async_read_string

async fn[T : AsyncReader] async_read_string(reader : T) -> String

#
async_read_tag

async fn[T : AsyncReader] async_read_tag(reader : T) -> (UInt, UInt)

#
async_read_uint32

async fn[T : AsyncReader] async_read_uint32(reader : T) -> UInt

#
async_read_uint64

async fn[T : AsyncReader] async_read_uint64(reader : T) -> UInt64

#
async_read_unknown

async fn[T : AsyncReader] async_read_unknown(reader : T, wire_type : UInt) -> Unit

#
async_read_varint32

async fn[T : AsyncReader] async_read_varint32(reader : T) -> UInt

#
async_write_bool

async fn[T : AsyncWriter] async_write_bool(writer : T, v : Bool) -> Unit

#
async_write_bytes

async fn[T : AsyncWriter] async_write_bytes(writer : T, v : Bytes) -> Unit

#
async_write_double

async fn[T : AsyncWriter] async_write_double(writer : T, v : Double) -> Unit

#
async_write_enum

async fn[T : AsyncWriter] async_write_enum(writer : T, v : Enum) -> Unit

#
async_write_fixed32

async fn[T : AsyncWriter] async_write_fixed32(writer : T, v : UInt) -> Unit

#
async_write_fixed64

async fn[T : AsyncWriter] async_write_fixed64(writer : T, v : UInt64) -> Unit

#
async_write_float

async fn[T : AsyncWriter] async_write_float(writer : T, v : Float) -> Unit

#
async_write_int32

async fn[T : AsyncWriter] async_write_int32(writer : T, v : Int) -> Unit

#
async_write_int64

async fn[T : AsyncWriter] async_write_int64(writer : T, v : Int64) -> Unit

#
async_write_sfixed32

async fn[T : AsyncWriter] async_write_sfixed32(writer : T, v : Int) -> Unit

#
async_write_sfixed64

async fn[T : AsyncWriter] async_write_sfixed64(writer : T, v : Int64) -> Unit

#
async_write_sint32

async fn[T : AsyncWriter] async_write_sint32(writer : T, v : Int) -> Unit

#
async_write_sint64

async fn[T : AsyncWriter] async_write_sint64(writer : T, v : Int64) -> Unit

#
async_write_string

async fn[T : AsyncWriter] async_write_string(writer : T, v : String) -> Unit

#
async_write_tag

async fn[T : AsyncWriter] async_write_tag(writer : T, tag : (UInt, UInt)) -> Unit

#
async_write_uint32

async fn[T : AsyncWriter] async_write_uint32(writer : T, v : UInt) -> Unit

#
async_write_uint64

async fn[T : AsyncWriter] async_write_uint64(writer : T, v : UInt64) -> Unit

#
async_write_varint

async fn[T : AsyncWriter] async_write_varint(writer : T, input : UInt64) -> Unit

#
base64_decode

fn base64_decode(s : String) -> Bytes

#
base64_encode

fn base64_encode(data : Bytes) -> String

#
read_bool

fn[T : Reader] read_bool(reader : T) -> Bool raise

#
read_bytes

fn[T : Reader] read_bytes(reader : T) -> Bytes raise

#
read_double

fn[T : Reader] read_double(reader : T) -> Double raise

#
read_enum

fn[T : Reader] read_enum(reader : T) -> Enum raise

#
read_fixed32

fn[T : Reader] read_fixed32(reader : T) -> UInt raise

#
read_fixed64

fn[T : Reader] read_fixed64(reader : T) -> UInt64 raise

#
read_float

fn[T : Reader] read_float(reader : T) -> Float raise

#
read_int32

fn[T : Reader] read_int32(reader : T) -> Int raise

#
read_int64

fn[T : Reader] read_int64(reader : T) -> Int64 raise

#
read_message

fn[M : Read + Default] read_message(reader : LimitedReader[&Reader]) -> M raise

#
read_packed

fn[M : Sized, R : Reader] read_packed(reader : R, read_fn : (LimitedReader[R]) -> M raise, size : UInt?) -> Array[M] raise

Reads packed repeated field (Array[M])

Note: packed field are stored as a variable length chunk of data, while regular repeated fields behaves like an iterator, yielding their tag everytime

#
read_sfixed32

fn[T : Reader] read_sfixed32(reader : T) -> Int raise

#
read_sfixed64

fn[T : Reader] read_sfixed64(reader : T) -> Int64 raise

#
read_sint32

fn[T : Reader] read_sint32(reader : T) -> SInt raise

#
read_sint64

fn[T : Reader] read_sint64(reader : T) -> SInt64 raise

#
read_string

fn[T : Reader] read_string(reader : T) -> String raise

#
read_tag

fn[T : Reader] read_tag(reader : T) -> (UInt, UInt) raise

#
read_uint32

fn[T : Reader] read_uint32(reader : T) -> UInt raise

#
read_uint64

fn[T : Reader] read_uint64(reader : T) -> UInt64 raise

#
read_unknown

fn[T : Reader] read_unknown(reader : T, wire_type : UInt) -> Unit raise

#
read_varint32

fn[T : Reader] read_varint32(reader : T) -> UInt raise

#
size_of

fn[T : Sized] size_of(t : T) -> UInt

#
write_bool

fn[T : Writer] write_bool(writer : T, v : Bool) -> Unit raise

#
write_bytes

fn[T : Writer] write_bytes(writer : T, v : Bytes) -> Unit raise

#
write_double

fn[T : Writer] write_double(writer : T, v : Double) -> Unit raise

#
write_enum

fn[T : Writer] write_enum(writer : T, v : Enum) -> Unit raise

#
write_fixed32

fn[T : Writer] write_fixed32(writer : T, v : UInt) -> Unit raise

#
write_fixed64

fn[T : Writer] write_fixed64(writer : T, v : UInt64) -> Unit raise

#
write_float

fn[T : Writer] write_float(writer : T, v : Float) -> Unit raise

#
write_int32

fn[T : Writer] write_int32(writer : T, v : Int) -> Unit raise

#
write_int64

fn[T : Writer] write_int64(writer : T, v : Int64) -> Unit raise

#
write_sfixed32

fn[T : Writer] write_sfixed32(writer : T, v : Int) -> Unit raise

#
write_sfixed64

fn[T : Writer] write_sfixed64(writer : T, v : Int64) -> Unit raise

#
write_sint32

fn[T : Writer] write_sint32(writer : T, v : Int) -> Unit raise

#
write_sint64

fn[T : Writer] write_sint64(writer : T, v : Int64) -> Unit raise

#
write_string

fn[T : Writer] write_string(writer : T, v : String) -> Unit raise

#
write_tag

fn[T : Writer] write_tag(writer : T, tag : (UInt, UInt)) -> Unit raise

#
write_uint32

fn[T : Writer] write_uint32(writer : T, v : UInt) -> Unit raise

#
write_uint64

fn[T : Writer] write_uint64(writer : T, v : UInt64) -> Unit raise

#
write_varint

fn[T : Writer] write_varint(writer : T, input : UInt64) -> Unit raise

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io