Skip to main content

parse

Function parse 

Source
pub fn parse(input: &[u8]) -> Result<DxValue>
Expand description

Parse DX bytes into a value

Parses the DX machine format (binary) into a structured DxValue. This is the primary entry point for parsing DX-formatted data.

§Example

use serializer::parse;

let input = b"name:Alice\nage:30\nactive:+";
let value = parse(input).unwrap();

§Errors

Returns a DxError in the following cases:

§Example Error Handling

use serializer::{parse, DxError};

let result = parse(b"key:");
match result {
    Ok(value) => println!("Parsed successfully"),
    Err(DxError::UnexpectedEof(pos)) => eprintln!("Unexpected EOF at position {}", pos),
    Err(DxError::InvalidSyntax { pos, msg }) => eprintln!("Syntax error at {}: {}", pos, msg),
    Err(DxError::InputTooLarge { size, max }) => eprintln!("Input {} bytes exceeds {} limit", size, max),
    Err(e) => eprintln!("Other error: {}", e),
}