Crate lnmp_core

Crate lnmp_core 

Source
Expand description

§lnmp-core

Core type definitions for LNMP (LLM Native Minimal Protocol).

This crate provides the fundamental data structures for representing LNMP data:

  • FieldId: Type alias for field identifiers (u16, range 0-65535)
  • LnmpValue: Enum representing all supported value types
  • LnmpField: A field ID and value pair
  • LnmpRecord: A collection of fields representing a complete record
  • TypeHint: Type annotations for values (v0.2+)

§LNMP v0.2 Features

Version 0.2 adds:

  • Type hints: Optional type annotations (:i, :f, :b, :s, :sa)
  • Sorted fields: sorted_fields() method for deterministic ordering

§Example

use lnmp_core::{LnmpField, LnmpRecord, LnmpValue};

// Create a new record
let mut record = LnmpRecord::new();

// Add fields
record.add_field(LnmpField {
    fid: 12,
    value: LnmpValue::Int(14532),
});

record.add_field(LnmpField {
    fid: 7,
    value: LnmpValue::Bool(true),
});

// Access fields
if let Some(field) = record.get_field(12) {
    println!("Field 12: {:?}", field.value);
}

// Get sorted fields (v0.2)
let sorted = record.sorted_fields();
for field in sorted {
    println!("F{} = {:?}", field.fid, field.value);
}

§Type Hints (v0.2)

use lnmp_core::{TypeHint, LnmpValue};

// Parse type hint from string
let hint = TypeHint::parse("i").unwrap();
assert_eq!(hint.as_str(), "i");

// Validate value matches type hint
let value = LnmpValue::Int(42);
assert!(hint.validates(&value));

Re-exports§

pub use container::LnmpContainerError;
pub use container::LnmpContainerHeader;
pub use container::LnmpFileMode;
pub use container::LNMP_CONTAINER_VERSION_1;
pub use container::LNMP_FLAG_CHECKSUM_REQUIRED;
pub use container::LNMP_FLAG_COMPRESSED;
pub use container::LNMP_FLAG_ENCRYPTED;
pub use container::LNMP_FLAG_EXT_META_BLOCK;
pub use container::LNMP_FLAG_QKEX;
pub use container::LNMP_FLAG_QSIG;
pub use container::LNMP_HEADER_SIZE;
pub use container::LNMP_MAGIC;
pub use limits::StructuralError;
pub use limits::StructuralLimits;
pub use record::LnmpField;
pub use record::LnmpRecord;
pub use types::FieldId;
pub use types::LnmpValue;
pub use types::TypeHint;

Modules§

checksum
Semantic checksum (SC32) system for LNMP v0.3.
container
Definitions for the .lnmp container header.
limits
Structural limit helpers for validating LNMP records and values.
record
Record and field structures for LNMP data.
types
Core type definitions for LNMP values and field identifiers.