Crate umicp_core

Crate umicp_core 

Source
Expand description

§UMICP Rust Bindings

High-performance Rust bindings for the Universal Matrix Inter-Communication Protocol (UMICP).

UMICP provides a universal communication framework for distributed systems, federated learning, and real-time applications with built-in matrix operations and type-safe messaging.

§Features

  • 🔗 Universal Communication: WebSocket and HTTP/2 transport layers
  • 📦 Type-Safe Envelopes: Strongly-typed message serialization and validation
  • ⚡ High Performance: SIMD-optimized matrix operations with parallel processing
  • 🔄 Federated Learning: Built-in support for ML model distribution and aggregation
  • 🛡️ Security First: Input validation, authentication, and encrypted communication
  • 📊 Real-time: Low-latency communication for IoT and financial applications
  • 🧪 Well Tested: Comprehensive test suite with async testing support

§Quick Start

§Basic Envelope Usage

use umicp_core::{Envelope, OperationType};

// Create a UMICP envelope
let envelope = Envelope::builder()
    .from("client-001")
    .to("server-001")
    .operation(OperationType::Data)
    .message_id("msg-12345")
    .capability_str("content-type", "application/json")
    .build()?;

// Serialize for transmission
let serialized = envelope.serialize()?;

// Deserialize received data
let received = Envelope::deserialize(&serialized)?;

§WebSocket Transport

use umicp_core::{WebSocketTransport, Envelope, OperationType};

// Server setup (requires websocket feature)
#[cfg(feature = "websocket")]
let server = WebSocketTransport::new_server("127.0.0.1:8080")?;

// Client setup (requires websocket feature)
#[cfg(feature = "websocket")]
let client = WebSocketTransport::new_client("ws://127.0.0.1:8080")?;

// Message handling
#[cfg(feature = "websocket")]
server.set_message_handler(|envelope, conn_id| async move {
    println!("Received: {:?}", envelope.capabilities());
    // Echo response
    let response = Envelope::builder()
        .from("server")
        .to(envelope.from())
        .operation(OperationType::Ack)
        .message_id(&format!("response-{}", uuid::Uuid::new_v4()))
        .build()?;

    server.send(response, &conn_id).await?;
    Ok(())
});

// Send message
let message = Envelope::builder()
    .from("client")
    .to("server")
    .operation(OperationType::Data)
    .message_id("hello-001")
    .capability_str("message", "Hello UMICP!")
    .build()?;

#[cfg(feature = "websocket")]
client.send(message, "")?;

§Matrix Operations

use umicp_core::Matrix;

// Create matrix instance
let mut matrix = Matrix::new();

// Vector operations
let vector1 = vec![1.0f32, 2.0, 3.0, 4.0];
let vector2 = vec![5.0f32, 6.0, 7.0, 8.0];
let mut result = vec![0.0f32; 4];

// Vector addition
matrix.vector_add(&vector1, &vector2, &mut result)?;
println!("Addition result: {:?}", result); // [6.0, 8.0, 10.0, 12.0]

// Dot product
let dot_product = matrix.dot_product(&vector1, &vector2)?;
println!("Dot product: {:?}", dot_product); // 70.0

// Matrix multiplication (2x2 * 2x2 = 2x2)
let matrix_a = vec![1.0, 2.0, 3.0, 4.0]; // 2x2 matrix
let matrix_b = vec![5.0, 6.0, 7.0, 8.0]; // 2x2 matrix
let mut matrix_result = vec![0.0; 4]; // 2x2 result

matrix.multiply(&matrix_a, &matrix_b, &mut matrix_result, 2, 2, 2)?;
println!("Matrix multiplication: {:?}", matrix_result);

Re-exports§

pub use envelope::Envelope;
pub use matrix::Matrix;
pub use events::EventEmitter;
pub use events::EventType;
pub use events::EventData;
pub use events::EventListener;
pub use discovery::ServiceDiscovery;
pub use discovery::ServiceInfo;
pub use tool_discovery::DiscoverableService;
pub use tool_discovery::OperationSchema;
pub use tool_discovery::ServerInfo;
pub use load_balancer::LoadBalancer;
pub use load_balancer::LoadBalancingStrategy;
pub use load_balancer::BackendEndpoint;
pub use load_balancer::LoadBalancerStats;
pub use load_balancer::ConnectionGuard;
pub use transport::WebSocketTransport;
pub use transport::Http2Transport;
pub use types::*;
pub use error::*;

Modules§

discovery
Service Discovery
envelope
UMICP Envelope
error
UMICP Error Types
events
Event System
load_balancer
Load Balancing
matrix
UMICP Matrix Operations
pool
Connection Pool
tool_discovery
UMICP Tool Discovery
transport
UMICP Transport Layer - Legacy Placeholders
types
UMICP Types
umicp
Utility functions and constants
utils
UMICP Utilities

Constants§

UMICP_VERSION
VERSION
Version information