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:
-
DxError::InputTooLarge- Input exceedsMAX_INPUT_SIZE(100 MB). This check happens before any allocation to prevent memory exhaustion. -
DxError::InvalidSyntax- Invalid syntax at a specific position:- Unexpected token where a key, value, or operator was expected
- Invalid operator after key (expected
:,=,>,!, or?) - Unexpected character in value position
-
DxError::UnexpectedEof- Input ends prematurely:- EOF after
:when a value was expected - EOF after
@when an anchor reference was expected - EOF in the middle of a table row
- EOF after
-
DxError::Utf8Error- Input contains invalid UTF-8 sequences. The error includes the byte offset of the first invalid byte. -
DxError::UnknownAlias- Reference to an undefined alias (e.g.,$undefined). -
DxError::UnknownAnchor- Reference to an undefined anchor (e.g.,@999). -
DxError::TypeMismatch- Value doesn’t match the expected type hint:- Integer expected but got string
- Float expected but got boolean
- Boolean expected but got number
-
DxError::DittoNoPrevious- Ditto operator (_) used without a previous row. -
DxError::RecursionLimitExceeded- Nesting depth exceedsMAX_RECURSION_DEPTH(1000). -
DxError::TableTooLarge- Table has more thanMAX_TABLE_ROWS(10 million) rows. -
DxError::SchemaError- Invalid table schema definition. -
DxError::Base62Error- Invalid Base62 encoded value in a%xcolumn.
§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),
}