OxL Reference

fn encode

Encodes x (§9, II.2). Compile error if T is not Serializable, or contains secret<T> and fmt is statically Format.Json ([С §9.3]).

Example:

oxl✓ checked in CI
use std.ser { encode, decode }

fn main() io {
  let b = encode(&42)!
  let back: i32 = decode(&b)!
  print("{back}")
}
Output
42
@intrinsic("ser.encode") pub(api) fn encode<T: Serializable>(x: &T, fmt: Format = Format.Oxl) -> bytes | EncodeError

Since. 1.0.0-beta

Parameters

NameType
x&T
fmtFormat = Format.Oxl

Returns

bytes

Errors

Effects

none declared (pure unless the body says otherwise)

Defined in: std/ser/ser.oxl:2289

See also