From 31a04e9fba199c3b477472b016f57d82def16b25 Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Thu, 31 Jul 2025 15:00:24 +0200 Subject: [PATCH] Provide last value for status json --- src/ca/proto.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ca/proto.rs b/src/ca/proto.rs index 4029901..1b745a0 100644 --- a/src/ca/proto.rs +++ b/src/ca/proto.rs @@ -367,6 +367,36 @@ impl CaEventValue { } } } + + pub fn to_json_value(&self) -> serde_json::Value { + use serde_json::json; + match &self.data { + CaDataValue::Scalar(val) => { + use super::proto::CaDataScalarValue::*; + match val { + I8(x) => json!(*x), + I16(x) => json!(*x), + I32(x) => json!(*x), + F32(x) => json!(*x), + F64(x) => json!(*x), + Enum(x) => json!(*x), + String(x) => json!(x), + Bool(x) => json!(*x), + } + } + CaDataValue::Array(val) => { + use super::proto::CaDataArrayValue::*; + match val { + I8(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + I16(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + I32(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + F32(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + F64(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + Bool(x) => x.get(0).map_or(json!(null), |x| json!(*x)), + } + } + } + } } #[derive(Debug, Clone, PartialEq, Serialize)]