hiroz 0.1.0

Native Rust ROS 2 implementation using Zenoh
Documentation
//! Wire format types for rcl_interfaces parameter messages.
//!
//! These types match the ROS 2 rcl_interfaces message definitions exactly
//! for CDR serialization compatibility. They are hand-implemented because
//! hiroz cannot depend on hiroz-msgs (circular dependency).
//!
//! The type hashes are computed from the .msg/.srv definitions and must
//! match those generated by hiroz-codegen for interop with rclcpp nodes.

use serde::{Deserialize, Serialize};

use crate::ServiceTypeInfo;
use crate::ZBuf;
use crate::entity::{TypeHash, TypeInfo};
use crate::msg::{SerdeCdrSerdes, ZMessage, ZService};

// ============================================================================
// Parameter type constants (from ParameterType.msg)
// ============================================================================

pub mod parameter_type {
    pub const NOT_SET: u8 = 0;
    pub const BOOL: u8 = 1;
    pub const INTEGER: u8 = 2;
    pub const DOUBLE: u8 = 3;
    pub const STRING: u8 = 4;
    pub const BYTE_ARRAY: u8 = 5;
    pub const BOOL_ARRAY: u8 = 6;
    pub const INTEGER_ARRAY: u8 = 7;
    pub const DOUBLE_ARRAY: u8 = 8;
    pub const STRING_ARRAY: u8 = 9;
}

// ============================================================================
// Message types (from rcl_interfaces/msg/)
// ============================================================================

/// FloatingPointRange.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireFloatingPointRange {
    pub from_value: f64,
    pub to_value: f64,
    pub step: f64,
}

/// IntegerRange.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireIntegerRange {
    pub from_value: i64,
    pub to_value: i64,
    pub step: u64,
}

/// ParameterValue.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireParameterValue {
    pub r#type: u8,
    pub bool_value: bool,
    pub integer_value: i64,
    pub double_value: f64,
    pub string_value: String,
    pub byte_array_value: ZBuf,
    pub bool_array_value: Vec<bool>,
    pub integer_array_value: Vec<i64>,
    pub double_array_value: Vec<f64>,
    pub string_array_value: Vec<String>,
}

/// Parameter.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireParameter {
    pub name: String,
    pub value: WireParameterValue,
}

/// ParameterDescriptor.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireParameterDescriptor {
    pub name: String,
    pub r#type: u8,
    pub description: String,
    pub additional_constraints: String,
    pub read_only: bool,
    pub dynamic_typing: bool,
    pub floating_point_range: Vec<WireFloatingPointRange>,
    pub integer_range: Vec<WireIntegerRange>,
}

/// ParameterEvent.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireParameterEvent {
    pub stamp: WireTime,
    pub node: String,
    pub new_parameters: Vec<WireParameter>,
    pub changed_parameters: Vec<WireParameter>,
    pub deleted_parameters: Vec<WireParameter>,
}

/// SetParametersResult.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireSetParametersResult {
    pub successful: bool,
    pub reason: String,
}

/// ListParametersResult.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireListParametersResult {
    pub names: Vec<String>,
    pub prefixes: Vec<String>,
}

/// ParameterEventDescriptors.msg
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireParameterEventDescriptors {
    pub new_parameters: Vec<WireParameterDescriptor>,
    pub changed_parameters: Vec<WireParameterDescriptor>,
    pub deleted_parameters: Vec<WireParameterDescriptor>,
}

/// builtin_interfaces/Time (needed by ParameterEvent)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WireTime {
    pub sec: i32,
    pub nanosec: u32,
}

// ============================================================================
// Service request/response types (from rcl_interfaces/srv/)
// ============================================================================

/// DescribeParameters.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DescribeParametersRequest {
    pub names: Vec<String>,
}

/// DescribeParameters.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DescribeParametersResponse {
    pub descriptors: Vec<WireParameterDescriptor>,
}

/// GetParameters.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetParametersRequest {
    pub names: Vec<String>,
}

/// GetParameters.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetParametersResponse {
    pub values: Vec<WireParameterValue>,
}

/// GetParameterTypes.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetParameterTypesRequest {
    pub names: Vec<String>,
}

/// GetParameterTypes.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetParameterTypesResponse {
    pub types: Vec<u8>,
}

/// ListParameters.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ListParametersRequest {
    pub prefixes: Vec<String>,
    pub depth: u64,
}

/// ListParameters.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ListParametersResponse {
    pub result: WireListParametersResult,
}

/// SetParameters.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SetParametersRequest {
    pub parameters: Vec<WireParameter>,
}

/// SetParameters.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SetParametersResponse {
    pub results: Vec<WireSetParametersResult>,
}

/// SetParametersAtomically.srv request
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SetParametersAtomicallyRequest {
    pub parameters: Vec<WireParameter>,
}

/// SetParametersAtomically.srv response
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SetParametersAtomicallyResponse {
    pub result: WireSetParametersResult,
}

// ============================================================================
// ZService marker types + ServiceTypeInfo implementations
// ============================================================================

pub struct DescribeParametersSrv;

impl ZService for DescribeParametersSrv {
    type Request = DescribeParametersRequest;
    type Response = DescribeParametersResponse;
}

impl ServiceTypeInfo for DescribeParametersSrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::DescribeParameters_",
            TypeHash::from_rihs_string(
                "RIHS01_845b484d71eb0673dae682f2e3ba3c4851a65a3dcfb97bddd82c5b57e91e4cff",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

pub struct GetParametersSrv;

impl ZService for GetParametersSrv {
    type Request = GetParametersRequest;
    type Response = GetParametersResponse;
}

impl ServiceTypeInfo for GetParametersSrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::GetParameters_",
            TypeHash::from_rihs_string(
                "RIHS01_bf9803d5c74cf989a5de3e0c2e99444599a627c7ff75f97b8c05b01003675cbc",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

pub struct GetParameterTypesSrv;

impl ZService for GetParameterTypesSrv {
    type Request = GetParameterTypesRequest;
    type Response = GetParameterTypesResponse;
}

impl ServiceTypeInfo for GetParameterTypesSrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::GetParameterTypes_",
            TypeHash::from_rihs_string(
                "RIHS01_da199c878688b3e530bdfe3ca8f74cb9fa0c303101e980a9e8f260e25e1c80ca",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

pub struct ListParametersSrv;

impl ZService for ListParametersSrv {
    type Request = ListParametersRequest;
    type Response = ListParametersResponse;
}

impl ServiceTypeInfo for ListParametersSrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::ListParameters_",
            TypeHash::from_rihs_string(
                "RIHS01_3e6062bfbb27bfb8730d4cef2558221f51a11646d78e7bb30a1e83afac3aad9d",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

pub struct SetParametersSrv;

impl ZService for SetParametersSrv {
    type Request = SetParametersRequest;
    type Response = SetParametersResponse;
}

impl ServiceTypeInfo for SetParametersSrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::SetParameters_",
            TypeHash::from_rihs_string(
                "RIHS01_56eed9a67e169f9cb6c1f987bc88f868c14a8fc9f743a263bc734c154015d7e0",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

pub struct SetParametersAtomicallySrv;

impl ZService for SetParametersAtomicallySrv {
    type Request = SetParametersAtomicallyRequest;
    type Response = SetParametersAtomicallyResponse;
}

impl ServiceTypeInfo for SetParametersAtomicallySrv {
    fn service_type_info() -> TypeInfo {
        TypeInfo::new(
            "rcl_interfaces::srv::dds_::SetParametersAtomically_",
            TypeHash::from_rihs_string(
                "RIHS01_0e192ef259c07fc3c07a13191d27002222e65e00ccec653ca05e856f79285fcd",
            )
            .expect("Invalid RIHS hash"),
        )
    }
}

// ============================================================================
// ParameterEvent type info (for the publisher)
// ============================================================================

/// Type info for ParameterEvent message (used for the /parameter_events publisher).
pub fn parameter_event_type_info() -> TypeInfo {
    TypeInfo::new(
        "rcl_interfaces::msg::dds_::ParameterEvent_",
        TypeHash::from_rihs_string(
            "RIHS01_043e627780fcad87a22d225bc2a037361dba713fca6a6b9f4b869a5aa0393204",
        )
        .expect("Invalid RIHS hash"),
    )
}

/// Constant for ListParameters: recursively get parameters with unlimited depth.
pub const DEPTH_RECURSIVE: u64 = 0;

// ============================================================================
// ZMessage impls for service request/response types and ParameterEvent
// ============================================================================

impl ZMessage for DescribeParametersRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for DescribeParametersResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for GetParametersRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for GetParametersResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for GetParameterTypesRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for GetParameterTypesResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for ListParametersRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for ListParametersResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for SetParametersRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for SetParametersResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for SetParametersAtomicallyRequest {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for SetParametersAtomicallyResponse {
    type Serdes = SerdeCdrSerdes<Self>;
}
impl ZMessage for WireParameterEvent {
    type Serdes = SerdeCdrSerdes<Self>;
}