Avro C#
Loading...
Searching...
No Matches
Avro.Generic.PreresolvingDatumWriter< T > Class Template Referenceabstract

A general purpose writer of data from avro streams. This writer analyzes the writer schema when constructed so that writes can be more efficient. Once constructed, a writer can be reused or shared among threads to avoid incurring more resolution costs. More...

Inheritance diagram for Avro.Generic.PreresolvingDatumWriter< T >:
Avro.Generic.DatumWriter< T > Avro.Generic.GenericDatumWriter< T > Avro.Specific.SpecificDatumWriter< T >

Classes

class  RecordFieldWriter
 Correlates a record field with the writer used to serialize that field. More...
interface  EnumAccess
 Obsolete - This will be removed from the public API in a future version. More...
interface  ArrayAccess
 Defines the interface for a class that provides access to an array implementation. More...
interface  MapAccess
 Defines the interface for a class that provides access to a map implementation. More...
class  DictionaryMapAccess
 Provides access to map properties from an IDictionary. More...

Public Member Functions

void Write (T datum, Encoder encoder)
 Write a datum. Traverse the schema, depth first, writing each leaf value in the schema from the datum to the output.
Parameters
datumDatum to write
encoderEncoder to write to

void WriteEnum (object value)
 Obsolete - This will be removed from the public API in a future version.
void EnsureArrayObject (object value)
 Checks if the given object is an array. If it is a valid array, this function returns normally. Otherwise, it throws an exception. The default implementation checks if the value is an array.
long GetArrayLength (object value)
 Returns the length of an array. The default implementation requires the object to be an array of objects and returns its length. The default implementation guarantees that EnsureArrayObject() has been called on the value before this function is called.
void WriteArrayValues (object array, WriteItem valueWriter, Encoder encoder)
 Writes each value in the given array to the encoder using the valueWriter . The default implementation of this method requires that the array is an object array.
void EnsureMapObject (object value)
 Checks if the given object is a map. If it is a valid map, this function returns normally. Otherwise, it throws an exception. The default implementation checks if the value is an IDictionary<string, object>.
long GetMapSize (object value)
 Returns the size of the map object. The default implementation guarantees that EnsureMapObject has been successfully called with the given value. The default implementation requires the value to be an IDictionary<string, object> and returns the number of elements in it.
void WriteMapValues (object map, WriteItem valueWriter, Encoder encoder)
 Writes each value in the given map to the encoder using the valueWriter . The default implementation of this method requires that the map is an IDictionary<string, object>.
void EnsureMapObject (object value)
long GetMapSize (object value)
void WriteMapValues (object map, WriteItem valueWriter, Encoder encoder)

Protected Member Functions

delegate void WriteItem (object value, Encoder encoder)
 Defines the signature for a method that writes a value to an encoder.
 PreresolvingDatumWriter (Schema schema, ArrayAccess arrayAccess, MapAccess mapAccess)
 Initializes a new instance of the PreresolvingDatumWriter<T> class.
void WriteNull (object value, Encoder encoder)
 Serializes a "null".
void Write< TValue > (object value, Schema.Type tag, Writer< TValue > writer)
 A generic method to serialize primitive Avro types.
void WriteRecordFields (object record, RecordFieldWriter[] writers, Encoder encoder)
 Writes each field of a record to the encoder.
void EnsureRecordObject (RecordSchema recordSchema, object value)
 Ensures that the given value is a record and that it corresponds to the given schema. Throws an exception if either of those assertions are false.
void WriteField (object record, string fieldName, int fieldPos, WriteItem writer, Encoder encoder)
 Writes a field from the record to the encoder using the writer .
WriteItem ResolveEnum (EnumSchema es)
 Serializes an enumeration.
WriteItem ResolveArray (ArraySchema schema)
 Creates a WriteItem delegate that serializes an array. The default implementation calls EnsureArrayObject() to ascertain that the given value is an array. It then calls GetArrayLength() and GetArrayElement() to access the members of the array and then serialize them.
WriteItem ResolveLogical (LogicalSchema schema)
 Serializes a logical value object by using the underlying logical type to convert the value to its base value.
void WriteMap (WriteItem itemWriter, object value, Encoder encoder)
 Serializes a map. The default implementation first ensure that the value is indeed a map and then uses GetMapSize() and GetMapElements() to access the contents of the map.
int ResolveUnion (UnionSchema us, Schema[] branchSchemas, object obj)
 Finds the branch within the given UnionSchema that matches the given object. The default implementation calls Matches() method in the order of branches within the UnionSchema. If nothing matches, throws an exception.
void WriteFixed (FixedSchema es, object value, Encoder encoder)
 Serialized a fixed object. The default implementation requires that the value is a GenericFixed object with an identical schema as es.
bool UnionBranchMatches (Schema sc, object obj)
 Tests whether the given schema an object are compatible.

Static Protected Member Functions

static AvroException TypeMismatch (object obj, string schemaType, string type)
 Creates a new AvroException and uses the provided parameters to build an exception message indicating there was a type mismatch.

Properties

Schema Schema [get]
 Schema used to write the data.
WriteItem WriteField [get, set]
 Delegate used to write the Field to an encoder.
Field Field [get, set]
 Field this object is associated with.

Detailed Description

A general purpose writer of data from avro streams. This writer analyzes the writer schema when constructed so that writes can be more efficient. Once constructed, a writer can be reused or shared among threads to avoid incurring more resolution costs.

Member Function Documentation

◆ EnsureArrayObject()

void Avro.Generic.PreresolvingDatumWriter< T >.EnsureArrayObject ( object value)

Checks if the given object is an array. If it is a valid array, this function returns normally. Otherwise, it throws an exception. The default implementation checks if the value is an array.

Parameters
value

◆ EnsureMapObject()

void Avro.Generic.PreresolvingDatumWriter< T >.EnsureMapObject ( object value)

Checks if the given object is a map. If it is a valid map, this function returns normally. Otherwise, it throws an exception. The default implementation checks if the value is an IDictionary<string, object>.

Parameters
valueEnsures that this object is a valid map.

◆ EnsureRecordObject()

void Avro.Generic.PreresolvingDatumWriter< T >.EnsureRecordObject ( RecordSchema recordSchema,
object value )
abstractprotected

Ensures that the given value is a record and that it corresponds to the given schema. Throws an exception if either of those assertions are false.

Parameters
recordSchemaSchema associated with the record
valueEnsure this object is a record

◆ GetArrayLength()

long Avro.Generic.PreresolvingDatumWriter< T >.GetArrayLength ( object value)

Returns the length of an array. The default implementation requires the object to be an array of objects and returns its length. The default implementation guarantees that EnsureArrayObject() has been called on the value before this function is called.

Parameters
valueThe object whose array length is required
Returns
The array length of the given object

◆ GetMapSize()

long Avro.Generic.PreresolvingDatumWriter< T >.GetMapSize ( object value)

Returns the size of the map object. The default implementation guarantees that EnsureMapObject has been successfully called with the given value. The default implementation requires the value to be an IDictionary<string, object> and returns the number of elements in it.

Parameters
valueThe map object whose size is desired
Returns
The size of the given map object

◆ PreresolvingDatumWriter()

Avro.Generic.PreresolvingDatumWriter< T >.PreresolvingDatumWriter ( Schema schema,
ArrayAccess arrayAccess,
MapAccess mapAccess )
inlineprotected

Initializes a new instance of the PreresolvingDatumWriter<T> class.

Parameters
schemaSchema used by this writer
arrayAccessObject used to access array properties
mapAccessObject used to access map properties

◆ ResolveArray()

WriteItem Avro.Generic.PreresolvingDatumWriter< T >.ResolveArray ( ArraySchema schema)
inlineprotected

Creates a WriteItem delegate that serializes an array. The default implementation calls EnsureArrayObject() to ascertain that the given value is an array. It then calls GetArrayLength() and GetArrayElement() to access the members of the array and then serialize them.

Parameters
schemaThe ArraySchema for serialization
Returns
A WriteItem that serializes an array.

◆ ResolveEnum()

WriteItem Avro.Generic.PreresolvingDatumWriter< T >.ResolveEnum ( EnumSchema es)
abstractprotected

Serializes an enumeration.

Parameters
esThe EnumSchema for serialization

◆ ResolveLogical()

WriteItem Avro.Generic.PreresolvingDatumWriter< T >.ResolveLogical ( LogicalSchema schema)
inlineprotected

Serializes a logical value object by using the underlying logical type to convert the value to its base value.

Parameters
schemaThe logical schema.

◆ ResolveUnion()

int Avro.Generic.PreresolvingDatumWriter< T >.ResolveUnion ( UnionSchema us,
Schema[] branchSchemas,
object obj )
inlineprotected

Finds the branch within the given UnionSchema that matches the given object. The default implementation calls Matches() method in the order of branches within the UnionSchema. If nothing matches, throws an exception.

Parameters
usThe UnionSchema to resolve against
branchSchemasSchemas for types within the union
objThe object that should be used in matching
Returns
Index of the schema in branchSchemas that matches the obj .
Exceptions
AvroExceptionNo match found for the object in the union schema.

◆ TypeMismatch()

AvroException Avro.Generic.PreresolvingDatumWriter< T >.TypeMismatch ( object obj,
string schemaType,
string type )
inlinestaticprotected

Creates a new AvroException and uses the provided parameters to build an exception message indicating there was a type mismatch.

Parameters
objObject whose type does not the expected type
schemaTypeSchema that we tried to write against
typeType that we expected
Returns
A new AvroException indicating a type mismatch.

◆ UnionBranchMatches()

bool Avro.Generic.PreresolvingDatumWriter< T >.UnionBranchMatches ( Schema sc,
object obj )
abstractprotected

Tests whether the given schema an object are compatible.

Parameters
scSchema to compare
objObject to compare
Returns
True if the two parameters are compatible, false otherwise.

◆ Write()

void Avro.Generic.PreresolvingDatumWriter< T >.Write ( T datum,
Encoder encoder )
inline

Write a datum. Traverse the schema, depth first, writing each leaf value in the schema from the datum to the output.

Parameters
datumDatum to write
encoderEncoder to write to

Implements Avro.Generic.DatumWriter< T >.

◆ Write< TValue >()

void Avro.Generic.PreresolvingDatumWriter< T >.Write< TValue > ( object value,
Schema.Type tag,
Writer< TValue > writer )
inlineprotected

A generic method to serialize primitive Avro types.

Template Parameters
TValueType of the C# type to be serialized
Parameters
valueThe value to be serialized
tagThe schema type tag
writerThe writer which should be used to write the given type.

◆ WriteArrayValues()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteArrayValues ( object array,
WriteItem valueWriter,
Encoder encoder )

Writes each value in the given array to the encoder using the valueWriter . The default implementation of this method requires that the array is an object array.

Parameters
arrayThe array object
valueWriterValue writer to send the array to.
encoderEncoder to the write the array values to.

◆ WriteField()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteField ( object record,
string fieldName,
int fieldPos,
WriteItem writer,
Encoder encoder )
abstractprotected

Writes a field from the record to the encoder using the writer .

Parameters
recordThe record value from which the field needs to be extracted
fieldNameThe name of the field in the record
fieldPosThe position of field in the record
writerUsed to write the field value to the encoder
encoderEncoder to write to

◆ WriteFixed()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteFixed ( FixedSchema es,
object value,
Encoder encoder )
abstractprotected

Serialized a fixed object. The default implementation requires that the value is a GenericFixed object with an identical schema as es.

Parameters
esThe schema for serialization
valueThe value to be serialized
encoderThe encoder for serialization

◆ WriteItem()

delegate void Avro.Generic.PreresolvingDatumWriter< T >.WriteItem ( object value,
Encoder encoder )
protected

Defines the signature for a method that writes a value to an encoder.

Parameters
valueValue to write
encoderEncoder to write to

◆ WriteMap()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteMap ( WriteItem itemWriter,
object value,
Encoder encoder )
inlineprotected

Serializes a map. The default implementation first ensure that the value is indeed a map and then uses GetMapSize() and GetMapElements() to access the contents of the map.

Parameters
itemWriterDelegate used to write each map item.
valueThe value to be serialized
encoderThe encoder for serialization

◆ WriteMapValues()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteMapValues ( object map,
WriteItem valueWriter,
Encoder encoder )

Writes each value in the given map to the encoder using the valueWriter . The default implementation of this method requires that the map is an IDictionary<string, object>.

Parameters
mapMap object to write the contents of.
valueWriterValue writer to send the map to.
encoderEncoder to the write the map values to.

◆ WriteNull()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteNull ( object value,
Encoder encoder )
inlineprotected

Serializes a "null".

Parameters
valueThe object to be serialized using null schema
encoderThe encoder to use while serialization

◆ WriteRecordFields()

void Avro.Generic.PreresolvingDatumWriter< T >.WriteRecordFields ( object record,
RecordFieldWriter[] writers,
Encoder encoder )
abstractprotected

Writes each field of a record to the encoder.

Parameters
recordRecord to write
writersWriters for each field in the record
encoderEncoder to write to

Property Documentation

◆ Schema

Schema Avro.Generic.PreresolvingDatumWriter< T >.Schema
get

Schema used to write the data.

Implements Avro.Generic.DatumWriter< T >.


The documentation for this class was generated from the following file:
  • src/apache/main/Generic/PreresolvingDatumWriter.cs