FeagiByteStructure

Struct FeagiByteStructure 

Source
pub struct FeagiByteStructure { /* private fields */ }
Expand description

Core container for validated FEAGI bytes structure data.

FeagiByteStructure is the central type for handling serialized FEAGI data structures. It provides a validated wrapper around raw bytes data, ensuring format compliance and offering high-level operations for manipulation and extraction.

§Key Features

  • Format Validation: Ensures bytes data conforms to FEAGI standards
  • Type Safety: Validates structure types and versions before operations
  • Multi-Structure Support: Can contain and manage multiple structures in one container
  • Zero-Copy Operations: Provides efficient access to internal data without unnecessary copying
  • Extensible Design: Supports new formats through the trait system

§Binary Format Overview

§Single Structure Format

[Type=? (1)][Version (1)][Type-specific payload...]

§Multi-Structure Container Format

[Type=9 (1)][Version (1)][Count (1)][Headers...][Data...]
 
Where Headers = [Start₁ (4)][Length₁ (4)][Start₂ (4)][Length₂ (4)]...
And Data = [Structure₁][Structure₂]...

§Thread Safety

FeagiByteStructure is thread-safe for concurrent read operations. Write operations (like capacity management) require exclusive access.

Implementations§

Source§

impl FeagiByteStructure

Source

pub const GLOBAL_BYTE_HEADER_BYTE_SIZE_IN_BYTES: usize = 2usize

Size of the global header (type + version) in bytes.

Source

pub const MINIMUM_LENGTH_TO_BE_CONSIDERED_VALID: usize = 4usize

Minimum bytes length required for a valid FEAGI bytes structure.

Source

pub const MULTISTRUCT_STRUCT_COUNT_BYTE_SIZE: usize = 1usize

Size of the structure count field in multi-structure wrapped_io_data.

Source

pub const MULTISTRUCT_PER_STRUCT_HEADER_SIZE_IN_BYTES: usize = 8usize

Size of each structure’s header entry in multi-structure wrapped_io_data (start position + length).

Source

pub const SUPPORTED_VERSION_JSON: u8 = 1u8

Currently supported version for JSON format structures.

Source

pub const SUPPORTED_VERSION_MULTI_STRUCT: u8 = 1u8

Currently supported version for multi-structure wrapped_io_data.

Source

pub const SUPPORTED_VERSION_NEURON_XYZP: u8 = 1u8

Currently supported version for neuron XYZP format structures.

Source

pub fn create_from_bytes( bytes: Vec<u8>, ) -> Result<FeagiByteStructure, FeagiDataError>

Creates a new FeagiByteStructure from raw bytes data with full validation.

This is the primary constructor that validates the provided bytes data against FEAGI format requirements. It performs comprehensive checks to ensure the data represents a valid bytes structure before creating the container.

§Arguments
  • bytes - Raw bytes data containing a serialized FEAGI structure
§Returns
  • Ok(FeagiByteStructure) - Validated bytes structure ready for use
  • Err(FeagiDataError) - If validation fails due to:
    • Insufficient data length (< 4 bytes minimum)
    • Invalid structure type identifier
    • Version number of 0 (reserved/invalid)
    • Format-specific validation failures
§Validation Performed
  • Minimum length check (at least 4 bytes)
  • Valid structure type identifier (bytes 0)
  • Non-zero version number (bytes 1)
  • Additional format-specific validations may be added
Source

pub fn create_from_2_existing( a: &FeagiByteStructure, b: &FeagiByteStructure, ) -> Result<FeagiByteStructure, FeagiDataError>

Creates a multi-structure container from exactly two existing structures.

This convenience method combines two FEAGI bytes structures into a single multi-structure container. It’s optimized for the common case of combining two structures and delegates to the general multi-structure creation logic.

§Arguments
  • a - First structure to include in the container
  • b - Second structure to include in the container
§Returns
  • Ok(FeagiByteStructure) - Multi-structure container with both inputs
  • Err(FeagiDataError) - If container creation fails
§Behavior
  • If either input is already a multi-structure, it will be flattened
  • The result will contain exactly the individual structures from both inputs
  • No nested multi-structures are created
Source

pub fn create_from_multiple_existing( existing: Vec<&FeagiByteStructure>, ) -> Result<FeagiByteStructure, FeagiDataError>

Creates a multi-structure container from multiple existing structures.

This method combines any number of FEAGI bytes structures into a single multi-structure container. It automatically flattens any input multi-structures to avoid nesting and enforces reasonable limits on container size.

§Arguments
  • existing - Vector of references to structures to combine
§Returns
  • Ok(FeagiByteStructure) - Multi-structure container with all inputs
  • Err(FeagiDataError) - If creation fails due to:
    • Empty input vector (at least one structure required)
    • Too many structures (maximum 255 supported)
    • Memory allocation failures
§Behavior
  • Single Input: Returns a clone of the input (no container needed)
  • Multiple Inputs: Creates a new multi-structure container
  • Flattening: Any input multi-structures are flattened into individual structures
  • Ordering: Output order matches input order, with multi-structure contents expanded in place
§Container Limits
  • Maximum of 255 individual structures in the final container
  • This limit is enforced after flattening all input multi-structures
Source

pub fn create_from_compatible( object: Box<dyn FeagiByteStructureCompatible>, ) -> Result<FeagiByteStructure, FeagiDataError>

Creates a FeagiByteStructure from any compatible object.

This convenience constructor takes any object implementing the FeagiByteStructureCompatible trait and converts it to a validated bytes structure. Useful for serializing custom types.

§Arguments
  • object - Boxed object implementing FeagiByteStructureCompatible
§Returns
  • Ok(FeagiByteStructure) - Validated bytes structure containing the serialized object
  • Err(FeagiDataError) - If serialization or validation fails
Source

pub fn try_get_structure_type( &self, ) -> Result<FeagiByteStructureType, FeagiDataError>

Returns the format type of this bytes structure.

Extracts and validates the format type identifier from the first bytes of the structure. This is used to determine how to interpret the remaining data in the structure.

§Returns
  • Ok(FeagiByteStructureType) - The format type of this structure
  • Err(FeagiDataError) - If the structure is empty or contains an invalid type
Source

pub fn try_get_version(&self) -> Result<u8, FeagiDataError>

Returns the format version of this bytes structure.

Extracts the version number from the second bytes of the structure. Version numbers allow for format evolution while maintaining compatibility.

§Returns
  • Ok(u8) - The version number of this structure’s format
  • Err(FeagiDataError) - If the structure is too short to contain version information
Source

pub fn is_multistruct(&self) -> Result<bool, FeagiDataError>

Checks if this bytes structure is a multi-structure container.

Multi-structure wrapped_io_data can hold multiple individual FEAGI structures in a single bytes stream, each with its own format type and data.

§Returns
  • Ok(true) - This is a multi-structure container
  • Ok(false) - This is a single structure
  • Err(FeagiDataError) - If the structure type cannot be determined
Source

pub fn contained_structure_count(&self) -> Result<usize, FeagiDataError>

Returns the number of individual structures contained in this bytes structure.

For single structures, this always returns 1. For multi-structure wrapped_io_data, this returns the number of individual structures contained within.

§Returns
  • Ok(usize) - The number of contained structures (always ≥ 1)
  • Err(FeagiDataError) - If structure validation fails
Source

pub fn get_ordered_object_types( &self, ) -> Result<Vec<FeagiByteStructureType>, FeagiDataError>

Source

pub fn copy_out_single_byte_structure_from_multistruct( &self, index: usize, ) -> Result<FeagiByteStructure, FeagiDataError>

Source

pub fn copy_out_single_object_from_single_struct( &self, ) -> Result<Box<dyn FeagiByteStructureCompatible>, FeagiDataError>

Extracts the original object from a single (non-multi-structure) bytes structure.

This method deserializes the contained data back to its original object form using the appropriate deserialization logic based on the structure’s format type. Only works with single structures - use copy_out_single_object_from_multistruct() for multi-structure wrapped_io_data.

§Returns
  • Ok(Box<dyn FeagiByteStructureCompatible>) - The deserialized original object
  • Err(FeagiDataError) - If:
    • This is a multi-structure container (use the multistruct variant instead)
    • Deserialization fails due to corrupted data
    • Unsupported format type
§Supported Format Types
  • JSONJsonStructure
  • NeuronCategoricalXYZPCorticalMappedXYZPNeuronData
Source

pub fn copy_out_single_object_from_multistruct( &self, index: usize, ) -> Result<Box<dyn FeagiByteStructureCompatible>, FeagiDataError>

Source

pub fn copy_out_as_byte_vector(&self) -> Vec<u8>

Source

pub fn borrow_data_as_slice(&self) -> &[u8]

Returns a read-only reference to the internal bytes data.

Provides direct access to the underlying bytes array for reading. Useful for efficient transmission or when you need to work with the raw bytes format directly.

§Returns

Read-only slice containing the complete bytes structure data

Source

pub fn borrow_data_as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable reference to the internal bytes data.

Provides direct write access to the underlying bytes array. Caution: Modifying the data directly can invalidate the structure and cause deserialization failures. Use with care.

§Returns

Mutable slice for direct bytes manipulation

§Safety

Direct modification bypasses validation. Ensure any changes maintain proper FEAGI bytes structure format compliance.

Source

pub fn borrow_data_as_mut_vec(&mut self) -> &mut Vec<u8>

Returns a mutable reference to the internal bytes vector.

Provides full access to the underlying Vec for advanced operations like resizing or bulk modifications. Caution: Direct modifications can break format compliance.

§Returns

Mutable reference to the internal bytes vector

§Safety

Direct vector manipulation bypasses all validation. Only use when you understand the FEAGI bytes structure format requirements.

Source

pub fn get_wasted_capacity_count(&self) -> usize

Source

pub fn get_utilized_capacity_percentage(&self) -> f32

Source

pub fn ensure_capacity_of_at_least( &mut self, size: usize, ) -> Result<(), FeagiDataError>

Source

pub fn shed_wasted_capacity(&mut self)

Source

pub fn reset_write_index(&mut self)

Trait Implementations§

Source§

impl Clone for FeagiByteStructure

Source§

fn clone(&self) -> FeagiByteStructure

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.