Struct apache_avro::Writer
source · pub struct Writer<'a, W> { /* private fields */ }Expand description
Main interface for writing Avro formatted values.
Implementations§
source§impl<'a, W> Writer<'a, W>
impl<'a, W> Writer<'a, W>
sourcepub fn builder() -> WriterBuilder<'a, W, ((), (), (), (), (), ())>
pub fn builder() -> WriterBuilder<'a, W, ((), (), (), (), (), ())>
Create a builder for building Writer.
On the builder, call .schema(...), .writer(...), .codec(...)(optional), .block_size(...)(optional), .marker(...)(optional), .user_metadata(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of Writer.
source§impl<'a, W: Write> Writer<'a, W>
impl<'a, W: Write> Writer<'a, W>
sourcepub fn new(schema: &'a Schema, writer: W) -> Self
pub fn new(schema: &'a Schema, writer: W) -> Self
Creates a Writer given a Schema and something implementing the io::Write trait to write
to.
No compression Codec will be used.
sourcepub fn with_codec(schema: &'a Schema, writer: W, codec: Codec) -> Self
pub fn with_codec(schema: &'a Schema, writer: W, codec: Codec) -> Self
Creates a Writer with a specific Codec given a Schema and something implementing the
io::Write trait to write to.
sourcepub fn with_schemata(
schema: &'a Schema,
schemata: Vec<&'a Schema>,
writer: W,
codec: Codec
) -> Self
pub fn with_schemata( schema: &'a Schema, schemata: Vec<&'a Schema>, writer: W, codec: Codec ) -> Self
Creates a Writer with a specific Codec given a Schema and something implementing the
io::Write trait to write to.
If the schema is incomplete, i.e. contains Schema::Refs then all dependencies must
be provided in schemata.
sourcepub fn append_to(schema: &'a Schema, writer: W, marker: [u8; 16]) -> Self
pub fn append_to(schema: &'a Schema, writer: W, marker: [u8; 16]) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
No compression Codec will be used.
sourcepub fn append_to_with_codec(
schema: &'a Schema,
writer: W,
codec: Codec,
marker: [u8; 16]
) -> Self
pub fn append_to_with_codec( schema: &'a Schema, writer: W, codec: Codec, marker: [u8; 16] ) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
sourcepub fn append_to_with_codec_schemata(
schema: &'a Schema,
schemata: Vec<&'a Schema>,
writer: W,
codec: Codec,
marker: [u8; 16]
) -> Self
pub fn append_to_with_codec_schemata( schema: &'a Schema, schemata: Vec<&'a Schema>, writer: W, codec: Codec, marker: [u8; 16] ) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
sourcepub fn append<T: Into<Value>>(&mut self, value: T) -> AvroResult<usize>
pub fn append<T: Into<Value>>(&mut self, value: T) -> AvroResult<usize>
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.
sourcepub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize>
pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize>
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.
sourcepub fn append_ser<S: Serialize>(&mut self, value: S) -> AvroResult<usize>
pub fn append_ser<S: Serialize>(&mut self, value: S) -> AvroResult<usize>
Append anything implementing the Serialize trait to a Writer for
serde compatibility, also performing schema
validation.
Return the number of bytes written.
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.
sourcepub fn extend<I, T: Into<Value>>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
pub fn extend<I, T: Into<Value>>(&mut self, values: I) -> AvroResult<usize>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).
sourcepub fn extend_ser<I, T: Serialize>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
pub fn extend_ser<I, T: Serialize>(&mut self, values: I) -> AvroResult<usize>where I: IntoIterator<Item = T>,
sourcepub fn extend_from_slice(&mut self, values: &[Value]) -> AvroResult<usize>
pub fn extend_from_slice(&mut self, values: &[Value]) -> AvroResult<usize>
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).
sourcepub fn flush(&mut self) -> AvroResult<usize>
pub fn flush(&mut self) -> AvroResult<usize>
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.
sourcepub fn into_inner(self) -> AvroResult<W>
pub fn into_inner(self) -> AvroResult<W>
Return what the Writer is writing to, consuming the Writer itself.
NOTE This function forces the written data to be flushed (an implicit
call to flush is performed).
sourcepub fn add_user_metadata<T: AsRef<[u8]>>(
&mut self,
key: String,
value: T
) -> AvroResult<()>
pub fn add_user_metadata<T: AsRef<[u8]>>( &mut self, key: String, value: T ) -> AvroResult<()>
Adds custom metadata to the file. This method could be used only before adding the first record to the writer.