alamb commented on code in PR #10713:
URL: https://github.com/apache/arrow-rs/pull/10713#discussion_r3866963639
##########
arrow-avro/src/lib.rs:
##########
@@ -64,6 +65,45 @@
//! # Ok(()) }
//! ```
//!
+//! ## Quickstart: unframed Avro datums *(runnable)*
+//!
+//! Kafka messages and other transports can contain bare Avro records without
an OCF header,
+//! single-object prefix, or schema-registry framing. When the writer schema
is already known,
+//! register it, select its fingerprint and
[`reader::DecoderMode::UnframedDatum`], and call
+//! [`reader::Decoder::decode`] once per record. The returned byte count also
supports
+//! consecutive datums in one buffer.
+//!
+//! ```
+//! use arrow_array::{Array, Int64Array};
+//! use arrow_avro::reader::{DecoderMode, ReaderBuilder};
+//! use arrow_avro::schema::{AvroSchema, SchemaStore};
+//!
+//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
+//! let schema = AvroSchema::new(
+//!
r#"{"type":"record","name":"Event","fields":[{"name":"id","type":"long"}]}"#
+//! .to_string(),
+//! );
+//! let mut store = SchemaStore::new();
+//! let fingerprint = store.register(schema)?;
+//! let mut decoder = ReaderBuilder::new()
+//! .with_writer_schema_store(store)
+//! .with_active_fingerprint(fingerprint)
+//! .with_decoder_mode(DecoderMode::UnframedDatum)
+//! .build_decoder()?;
+//!
+//! // Two consecutive records, {id: 7} and {id: 42}, in Avro zigzag encoding.
+//! let mut remaining: &[u8] = &[0x0e, 0x54];
+//! while !remaining.is_empty() {
+//! let consumed = decoder.decode(remaining)?;
Review Comment:
nice
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]