Skip to main content

deserialize

Function deserialize 

Source
pub fn deserialize(input: &str) -> Result<DxDocument, ConvertError>
Expand description

Deserialize LLM text format to a DxDocument.

This parses the token-efficient LLM format back into a structured document.

§Example

use serializer::{deserialize, DxLlmValue};

let text = "name=MyApp\nversion=1.0.0";
let doc = deserialize(text).unwrap();

assert!(doc.context.contains_key("name"));

§Errors

Returns a ConvertError in the following cases:

  • ConvertError::LlmParse - When the input contains invalid DX Serializer/LLM syntax:
    • Unexpected character: Invalid character at a specific position
    • Unexpected EOF: Input ends prematurely (e.g., unclosed brackets)
    • Invalid value format: Malformed value that cannot be parsed
    • Schema mismatch: Table row has wrong number of columns
    • UTF-8 error: Input contains invalid UTF-8 sequences (with byte offset)
    • Input too large: Input exceeds MAX_INPUT_SIZE (100 MB)
    • Unclosed bracket/parenthesis: Missing closing delimiter
    • Missing value: Key without corresponding value after =
    • Invalid table format: Malformed table definition

§Example Error Handling

use serializer::{deserialize, ConvertError};

let result = deserialize("invalid[[[");
match result {
    Ok(doc) => println!("Parsed {} context entries", doc.context.len()),
    Err(ConvertError::LlmParse(e)) => eprintln!("Parse error: {}", e),
    Err(e) => eprintln!("Other error: {}", e),
}