OxL Reference

fn decode_view

Checks the structure of buf (missing fields, invariants, malformed input: [С §9.4]) and returns a view of it.

Example:

oxl✓ checked in CI
use std.ser { encode }
use std.core { decode_view }

data Person {
  id: i64
  name: str
}

fn main() io {
  let buf = encode(&Person{ id: 1, name: "bob" })!
  match decode_view<Person>(&buf) {
    DecodeError _ => print("bad buffer")
    _ => print("valid")
  }
}
Output
valid
pub(api) fn decode_view<T: Serializable>(buf: &bytes) -> view T | DecodeError

Complexity. O(size of the buffer): checks the structure once; fields are decoded lazily afterwards.

Since. 1.0.0-beta

Parameters

NameType
buf&bytes

Returns

view T

Errors

  • DecodeError @error
  • `DecodeError` (`Missing`, `Invalid`, `Malformed`) when the buffer is not a valid encoded `T`.

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/view.oxl:111

See also