mz_avro

Struct Writer

Source
pub struct Writer<W> {
    schema: Schema,
    writer: W,
    buffer: Vec<u8>,
    num_values: usize,
    codec: Option<Codec>,
    marker: [u8; 16],
    has_header: bool,
}
Expand description

Main interface for writing Avro Object Container Files.

Fields§

§schema: Schema§writer: W§buffer: Vec<u8>§num_values: usize§codec: Option<Codec>§marker: [u8; 16]§has_header: bool

Implementations§

Source§

impl<W: Write> Writer<W>

Source

pub fn new(schema: Schema, writer: W) -> Writer<W>

Creates a Writer for the Schema and something implementing the std::io::Write trait to write to.

This uses the no-compression Codec::Null when appending records.

Source

pub fn with_codec(schema: Schema, writer: W, codec: Codec) -> Writer<W>

Creates a Writer given a Schema and a specific compression Codec

Source

pub fn with_codec_opt( schema: Schema, writer: W, codec: Option<Codec>, ) -> Writer<W>

Create a Writer with the given parameters.

All parameters have the same meaning as with_codec, but if codec is None then no compression will be used and the avro.codec field in the header will be omitted.

Source

pub fn append_to(file: W) -> Result<Writer<W>, Error>
where W: AvroRead + Seek + Unpin + Send,

Creates a Writer that appends to an existing OCF file.

Source

pub fn schema(&self) -> &Schema

Get a reference to the Schema associated to a Writer.

Source

pub fn append<T: ToAvro>(&mut self, value: T) -> Result<usize, Error>

Append a compatible value (implementing the ToAvro trait) to a Writer, also performing schema validation.

Return the number of bytes written (it might be 0, see below).

NOTE This function is not guaranteed to perform any actual write, since it relies on internal buffering for performance reasons. If you want to be sure the value has been written, then call flush.

Source

pub fn append_value_ref(&mut self, value: &Value) -> Result<usize, Error>

Append a compatible value to a Writer, also performing schema validation.

Return the number of bytes written (it might be 0, see below).

NOTE This function is not guaranteed to perform any actual write, since it relies on internal buffering for performance reasons. If you want to be sure the value has been written, then call flush.

Source

pub fn extend<I, T: ToAvro>(&mut self, values: I) -> Result<usize, Error>
where I: IntoIterator<Item = T>,

Extend a Writer with an Iterator of compatible values (implementing the ToAvro trait), also performing schema validation.

Return the number of bytes written.

NOTE This function forces the written data to be flushed (an implicit call to flush is performed).

Source

pub fn extend_from_slice(&mut self, values: &[Value]) -> Result<usize, Error>

Extend a Writer by appending each Value from a slice, while also performing schema validation on each value appended.

Return the number of bytes written.

NOTE This function forces the written data to be flushed (an implicit call to flush is performed).

Source

pub fn flush(&mut self) -> Result<usize, Error>

Flush the content appended to a Writer. Call this function to make sure all the content has been written before releasing the Writer.

Return the number of bytes written.

Source

pub fn into_inner(self) -> W

Return what the Writer is writing to, consuming the Writer itself.

NOTE This function doesn’t guarantee that everything gets written before consuming the buffer. Please call flush before.

Source

fn append_marker(&mut self) -> Result<usize, Error>

Generate and append synchronization marker to the payload.

Source

fn append_raw(&mut self, value: &Value, schema: &Schema) -> Result<usize, Error>

Append a raw Avro Value to the payload avoiding to encode it again.

Source

fn append_bytes(&mut self, bytes: &[u8]) -> Result<usize, Error>

Append pure bytes to the payload.

Source

fn header(&self) -> Result<Vec<u8>, Error>

Create an Avro header based on schema, codec and sync marker.

Auto Trait Implementations§

§

impl<W> Freeze for Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>
where W: Send,

§

impl<W> Sync for Writer<W>
where W: Sync,

§

impl<W> Unpin for Writer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>
where W: UnwindSafe,

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<T, U> CastInto<U> for T
where U: CastFrom<T>,

Source§

fn cast_into(self) -> U

Performs the cast.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,