springql_core/stream_engine/autonomous_executor/row/foreign_row/
source_row.rs

1// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.
2
3mod can_frame_source_row;
4mod json_source_row;
5
6pub use can_frame_source_row::CANFrameSourceRow;
7pub use json_source_row::JsonSourceRow;
8
9use crate::{
10    api::{error::Result, SpringError},
11    stream_engine::autonomous_executor::row::schemaless_row::SchemalessRow,
12};
13
14/// Input row from foreign sources (retrieved from SourceReader).
15///
16/// Immediately converted into `Row` on stream-engine boundary.
17#[derive(Clone, PartialEq, Debug)]
18pub enum SourceRow {
19    Json(JsonSourceRow),
20    CANFrame(CANFrameSourceRow),
21    Raw(SchemalessRow),
22}
23
24impl SourceRow {
25    /// # Failure
26    ///
27    /// - `SpringError::InvalidFormat` when:
28    ///   - `json` cannot be parsed as a JSON
29    pub fn from_json(json: &str) -> Result<Self> {
30        let json_source_row = JsonSourceRow::parse(json)?;
31        Ok(Self::Json(json_source_row))
32    }
33}
34
35impl TryFrom<SourceRow> for SchemalessRow {
36    type Error = SpringError;
37
38    fn try_from(row: SourceRow) -> Result<Self> {
39        match row {
40            SourceRow::Json(json_source_row) => json_source_row.into_schemaless_row(),
41            SourceRow::CANFrame(can_frame_source_row) => can_frame_source_row.into_schemaless_row(),
42            SourceRow::Raw(schemaless_row) => Ok(schemaless_row),
43        }
44    }
45}