mz_storage/decode/
avro.rs1use mz_interchange::avro::Decoder;
11use mz_ore::error::ErrorExt;
12use mz_repr::Row;
13use mz_storage_types::errors::DecodeErrorKind;
14
15#[derive(Debug)]
16pub struct AvroDecoderState {
17 decoder: Decoder,
18 events_success: i64,
19}
20
21impl AvroDecoderState {
22 pub fn new(
23 value_schema: &str,
24 ccsr_client: Option<mz_ccsr::Client>,
25 debug_name: String,
26 confluent_wire_format: bool,
27 ) -> Result<Self, anyhow::Error> {
28 Ok(AvroDecoderState {
29 decoder: Decoder::new(value_schema, ccsr_client, debug_name, confluent_wire_format)?,
30 events_success: 0,
31 })
32 }
33
34 pub async fn decode(
35 &mut self,
36 bytes: &mut &[u8],
37 ) -> Result<Result<Option<Row>, DecodeErrorKind>, anyhow::Error> {
38 let result = match self.decoder.decode(bytes).await? {
39 Ok(row) => {
40 self.events_success += 1;
41 Ok(Some(row))
42 }
43 Err(err) => Err(DecodeErrorKind::Text(
44 format!("avro deserialization error: {}", err.display_with_causes()).into(),
45 )),
46 };
47 Ok(result)
48 }
49}