Skip to main content

OpOutput

Struct OpOutput 

Source
pub struct OpOutput { /* private fields */ }
Expand description

The buffered output side an crate::Operator writes through.

Sends accumulate in the order they were made and are read out with OpOutput::drain; nothing is delivered until the host does that, so an operator can call send/send_batch/send_bytes any number of times within one crate::Operator::on_event call without touching a connection.

use astrs_data::prelude::*;
use astrs_operator_api::OpOutput;
use astrs_time::HlcTimestamp;
use astrs_wire::Metadata;

#[derive(Debug, PartialEq)]
struct Ping;

impl astrs_data::AstrsMessage for Ping {
    const URN: &'static str = "std/core/v1/PingMsg";
    fn data_type() -> DataType {
        DataType::strukt([Field::required("tick", DataType::UInt8)])
    }
    fn to_record_batch(&self) -> astrs_data::Result<RecordBatch> {
        let DataType::Struct(fields) = Self::data_type() else { unreachable!() };
        let column = UInt8Array::from_values([1u8]).into_array_ref();
        let strukt = StructArray::try_new(fields, vec![column], None)?;
        Ok(RecordBatch::from_payload(strukt.into_array_ref()))
    }
    fn from_record_batch(_: &RecordBatch) -> astrs_data::Result<Self> {
        Ok(Self)
    }
}

let mut out = OpOutput::new();
assert!(out.is_empty());
out.send("tick", Metadata::new(HlcTimestamp::EPOCH), &Ping)?;
assert_eq!(out.len(), 1);

let sends = out.drain();
assert_eq!(sends[0].id().as_str(), "tick");
assert!(out.is_empty(), "drain empties the buffer");

Implementations§

Source§

impl OpOutput

Source

pub fn new() -> Self

An empty output buffer.

Source

pub fn send_bytes( &mut self, id: &str, metadata: Metadata, payload: Vec<u8>, ) -> OpResult<()>

Buffers a send of already-encoded bytes.

The escape hatch for a payload an operator built itself (or is forwarding unchanged from an input) — send/send_batch are the typed front doors that end up calling this.

§Errors

OpError::InvalidOutputId when id is not a valid astrs_wire::DataId.

Source

pub fn send_batch( &mut self, id: &str, metadata: Metadata, batch: &RecordBatch, ) -> OpResult<()>

Buffers a send of an already-built RecordBatch.

§Errors

OpError::InvalidOutputId as OpOutput::send_bytes, or OpError::Ipc when Arrow IPC encoding fails (blueprint §6.1’s 256 MB payload cap, for example).

Source

pub fn send<M: AstrsMessage>( &mut self, id: &str, metadata: Metadata, message: &M, ) -> OpResult<()>

Buffers a send of a typed AstrsMessage value.

Encodes message to its one-row RecordBatch and then to Arrow IPC bytes — the same two steps a hand-written send_batch call would make, saved for the common case of sending a #[derive(AstrsMessage)] type directly.

§Errors

OpError::InvalidOutputId as OpOutput::send_bytes, OpError::Encode when AstrsMessage::to_record_batch fails, or OpError::Ipc as OpOutput::send_batch.

Source

pub fn drain(&mut self) -> Vec<OpSend>

Removes and returns every buffered send, oldest first.

Source

pub fn len(&self) -> usize

Number of buffered sends.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been buffered (or everything was drained).

Trait Implementations§

Source§

impl Debug for OpOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OpOutput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeDebug for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V