fluvio_smartmodule/
output.rs

1use fluvio_protocol::{
2    Encoder, Decoder,
3    record::Record,
4    link::smartmodule::{
5        SmartModuleTransformRuntimeError, SmartModuleInitRuntimeError,
6        SmartModuleLookbackRuntimeError,
7    },
8};
9
10/// A type used to return processed records and/or an error from a SmartModule
11#[derive(Debug, Default, Encoder, Decoder)]
12pub struct SmartModuleOutput {
13    /// The successfully processed output Records
14    pub successes: Vec<Record>,
15    /// Any runtime error if one was encountered
16    pub error: Option<SmartModuleTransformRuntimeError>,
17}
18
19impl SmartModuleOutput {
20    pub fn new(successes: Vec<Record>) -> Self {
21        Self {
22            successes,
23            error: None,
24        }
25    }
26
27    pub fn with_error(
28        successes: Vec<Record>,
29        error: Option<SmartModuleTransformRuntimeError>,
30    ) -> Self {
31        Self { successes, error }
32    }
33}
34
35/// A type used to return processed records and/or an error from an Aggregate SmartModule
36#[derive(Debug, Default, Encoder, Decoder)]
37pub struct SmartModuleAggregateOutput {
38    /// The base output required by all SmartModules
39    pub base: SmartModuleOutput,
40    #[fluvio(min_version = 16)]
41    pub accumulator: Vec<u8>,
42}
43
44impl SmartModuleAggregateOutput {
45    pub fn new(base: SmartModuleOutput, accumulator: Vec<u8>) -> Self {
46        Self { base, accumulator }
47    }
48}
49
50/// A type used to return processed records and/or an error from a SmartModule
51#[derive(Debug, Default, Encoder, Decoder)]
52pub struct SmartModuleInitOutput {
53    /// Any runtime error if one was encountered
54    pub error: SmartModuleInitRuntimeError,
55}
56
57/// A type used to return an error from a SmartModule Lookback
58#[derive(Debug, Default, Encoder, Decoder)]
59pub struct SmartModuleLookbackOutput {
60    /// Any runtime error if one was encountered
61    pub error: SmartModuleLookbackRuntimeError,
62}