msgpack

Generated by tinox doc

Compact binary serialization (MessagePack, https://msgpack.org/) — a binary counterpart to tinox.core.json's text-based JsonValue tree, useful for AMQP payloads, inter-service RPC, or storing structured data more compactly than JSON. Same self-describing dynamic-value model as JSON (object/array/string/int/float/bool/null), no schema/codegen step.

Encode decode

import tinox.core.msgpack;

class Main
{
    fnc main() -> Int32
    {
        var fields: Map<String, MsgpackValue> = Map::new();
        fields["name"] = MsgpackValue { kind: "string", stringValue: "Ada", intValue: 0, floatValue: 0.0, boolValue: false, arrayValue: [], objectValue: Map::new() };
        fields["age"] = MsgpackValue { kind: "int", stringValue: "", intValue: 36, floatValue: 0.0, boolValue: false, arrayValue: [], objectValue: Map::new() };

        let payload: MsgpackValue = MsgpackValue { kind: "object", stringValue: "", intValue: 0, floatValue: 0.0, boolValue: false, arrayValue: [], objectValue: fields };
        let bytes: List<Int64> = Msgpack::encode(payload);
        println("encoded " + bytes.len().toString() + " bytes");

        let decoded: MsgpackValue = Msgpack::decode(bytes);
        println("name = " + decoded.getField("name").getString());
        return 0;
    }
}

fn msgpackFloat64ToBits(f: Float64) → Int64

fn msgpackBitsToFloat64(bits: Int64) → Float64

fn msgpackBitsToFloat32(bits32: Int64) → Float64

fn tinoxBytesToString(bytes: List<Int64>) → String

class Msgpack

Methods

fn encode(value: MsgpackValue) → List<Int64>
fn decode(bytes: List<Int64>) → MsgpackValue
fn encodeInto(value: MsgpackValue, out: List<Int64>) → Nothing
fn encodeInt(n: Int64, out: List<Int64>) → Nothing
fn encodeFloat(f: Float64, out: List<Int64>) → Nothing
fn encodeString(s: String, out: List<Int64>) → Nothing
fn encodeArray(items: List<MsgpackValue>, out: List<Int64>) → Nothing
fn encodeMap(m: Map<String, MsgpackValue>, out: List<Int64>) → Nothing
fn pushBE(v: Int64, n: Int64, out: List<Int64>) → Nothing
fn decodeValue(reader: MsgpackReader) → MsgpackValue
fn intResult(reader: MsgpackReader, v: Int64) → MsgpackValue
fn signExtend(v: Int64, byteWidth: Int64) → Int64
fn decodeString(reader: MsgpackReader, len: Int64) → MsgpackValue
fn decodeArray(reader: MsgpackReader, len: Int64) → MsgpackValue
fn decodeMap(reader: MsgpackReader, len: Int64) → MsgpackValue

class MsgpackReader

* Cursor over a byte array for decoding (issue #136). Every read * checks bounds before advancing; once `failed` is set (EOF mid-value, * or a declared length exceeding what's actually left in the buffer), * every subsequent read is a safe no-op returning 0 instead of * indexing past the end -- kein Silent-Garbage in the crash sense: * a truncated/malformed input never reads out of bounds or loops * proportionally to an attacker-declared length that vastly exceeds * the real buffer (the same declared-length-vs-actual-size amplification * shape runtime.c's httpConnReadN/httpServerReadRawBytes fixes were * for, issue #111, just here in the decoder's own bounds checks * instead of an allocation). It does NOT try to distinguish "genuinely * decoded a nil value" from "decode failed" in the returned * MsgpackValue -- same as this stdlib's other self-contained-buffer * parsers (Toml::parse, Yaml::parse, Xml::parse, Csv::parse), which * don't expose a separate ok flag either; Msgpack::decode's contract * is "never crashes, never hangs," not "always reports success/failure."

Fields

bytesList<Int64>
posInt64
failedBool

Methods

fn new(bytes: List<Int64>) → MsgpackReader
fn remaining() → Int64
fn readByte() → Int64
fn readBE(n: Int64) → Int64

class MsgpackValue

* A dynamically-typed MessagePack value -- mirrors tinox.core.json's * JsonValue API shape (isString/getString/isInt/getInt/isArray/ * asArray/isObject/getField/... same names) since MessagePack's data * model is the same object/array/string/int/float/bool/null tree * JsonValue already represents, just with a compact binary wire * format instead of text. Unlike JsonValue (a C-backed opaque * handle), this is a plain Tinox tagged union: construct one * directly via a struct literal for encoding (e.g. * `MsgpackValue { kind: "string", stringValue: "hi", intValue: 0, * floatValue: 0.0, boolValue: false, arrayValue: [], objectValue: * Map::new() }`), the same convention tinox.core.toml's TomlValue * already uses. EVERY field must be given (Bug 130: an omitted field * left the corresponding heap slot as uninitialized garbage) -- only * `kind` and the one field it selects are ever actually read, the * rest are inert placeholders. * * Map keys are always String (matching JsonValue's object model) -- * MessagePack itself allows any value as a map key, but a decoded * map with a non-string key fails the whole decode rather than * silently coercing or dropping it (see MsgpackReader.failed).

Fields

kindString
stringValueString
intValueInt64
floatValueFloat64
boolValueBool
arrayValueList<MsgpackValue>
objectValueMap<String, MsgpackValue>

Methods

fn isNull() → Bool
fn isBool() → Bool
fn isInt() → Bool
fn isFloat() → Bool
fn isString() → Bool
fn isArray() → Bool
fn isObject() → Bool
fn getBool() → Bool
fn getInt() → Int64
fn getFloat() → Float64
fn getString() → String
fn asArray() → List<MsgpackValue>
fn asMap() → Map<String, MsgpackValue>
fn getField(key: String) → MsgpackValue