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
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
bytes | List<Int64> | |
pos | Int64 | |
failed | Bool |
Methods
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
kind | String | |
stringValue | String | |
intValue | Int64 | |
floatValue | Float64 | |
boolValue | Bool | |
arrayValue | List<MsgpackValue> | |
objectValue | Map<String, MsgpackValue> |