Kinetica   C#   API  Version 7.2.3.0
Avro.Generic.DefaultWriter Class Reference

A General purpose writer for serializing objects into a Stream using Avro. More...

+ Inheritance diagram for Avro.Generic.DefaultWriter:

Public Member Functions

 DefaultWriter (Schema schema)
 Constructs a generic writer for the given schema. More...
 
void Write< T > (T value, Encoder encoder)
 
virtual void Write (Schema schema, object value, Encoder encoder)
 Examines the schema and dispatches the actual work to one of the other methods of this class. More...
 

Protected Member Functions

virtual void WriteNull (object value, Encoder encoder)
 Serializes a "null" More...
 
virtual void Write< S > (object value, Schema.Type tag, Writer< S > writer)
 A generic method to serialize primitive Avro types. More...
 
virtual void WriteRecord (RecordSchema schema, object value, Encoder encoder)
 Serialized a record using the given RecordSchema. More...
 
virtual void EnsureRecordObject (RecordSchema s, object value)
 
virtual object GetField (object value, string fieldName, int fieldPos)
 Extracts the field value from the given object. More...
 
virtual void WriteEnum (EnumSchema es, object value, Encoder encoder)
 Serializes an enumeration. More...
 
virtual void WriteArray (ArraySchema schema, object value, Encoder encoder)
 Serialized an array. More...
 
virtual void EnsureArrayObject (object value)
 Checks if the given object is an array. More...
 
virtual long GetArrayLength (object value)
 Returns the length of an array. More...
 
virtual object GetArrayElement (object value, long index)
 Returns the element at the given index from the given array object. More...
 
virtual void WriteMap (MapSchema schema, object value, Encoder encoder)
 Serialized a map. More...
 
virtual void EnsureMapObject (object value)
 Checks if the given object is a map. More...
 
virtual long GetMapSize (object value)
 Returns the size of the map object. More...
 
virtual IEnumerable< KeyValuePair< string, object > > GetMapValues (object value)
 Returns the contents of the given map object. More...
 
virtual void WriteUnion (UnionSchema us, object value, Encoder encoder)
 Resolves the given value against the given UnionSchema and serializes the object against the resolved schema member. More...
 
virtual int ResolveUnion (UnionSchema us, object obj)
 Finds the branch within the given UnionSchema that matches the given object. More...
 
virtual void WriteFixed (FixedSchema es, object value, Encoder encoder)
 Serialized a fixed object. More...
 
AvroException TypeMismatch (object obj, string schemaType, string type)
 
virtual bool Matches (Schema sc, object obj)
 

Properties

Schema Schema [get]
 

Detailed Description

A General purpose writer for serializing objects into a Stream using Avro.

This class implements a default way of serializing objects. But one can derive a class from this and override different methods to acheive results that are different from the default implementation.

Definition at line 63 of file GenericWriter.cs.

Constructor & Destructor Documentation

◆ DefaultWriter()

Avro.Generic.DefaultWriter.DefaultWriter ( Schema  schema)
inline

Constructs a generic writer for the given schema.

Parameters
schemaThe schema for the object to be serialized

Definition at line 71 of file GenericWriter.cs.

Member Function Documentation

◆ EnsureArrayObject()

virtual void Avro.Generic.DefaultWriter.EnsureArrayObject ( object  value)
inlineprotectedvirtual

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

Definition at line 252 of file GenericWriter.cs.

◆ EnsureMapObject()

virtual void Avro.Generic.DefaultWriter.EnsureMapObject ( object  value)
inlineprotectedvirtual

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
value

Definition at line 311 of file GenericWriter.cs.

◆ EnsureRecordObject()

virtual void Avro.Generic.DefaultWriter.EnsureRecordObject ( RecordSchema  s,
object  value 
)
inlineprotectedvirtual

Definition at line 189 of file GenericWriter.cs.

◆ GetArrayElement()

virtual object Avro.Generic.DefaultWriter.GetArrayElement ( object  value,
long  index 
)
inlineprotectedvirtual

Returns the element at the given index from the given array object.

The default implementation requires that the value is an object array and returns the element in that array. The defaul implementation gurantees that EnsureArrayObject() has been called on the value before this function is called.

Parameters
valueThe array object
indexThe index to look for
Returns
The array element at the index

Definition at line 279 of file GenericWriter.cs.

◆ GetArrayLength()

virtual long Avro.Generic.DefaultWriter.GetArrayLength ( object  value)
inlineprotectedvirtual

Returns the length of an array.

The default implementation requires the object to be an array of objects and returns its length. The defaul implementation gurantees 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

Definition at line 265 of file GenericWriter.cs.

◆ GetField()

virtual object Avro.Generic.DefaultWriter.GetField ( object  value,
string  fieldName,
int  fieldPos 
)
inlineprotectedvirtual

Extracts the field value from the given object.

In this default implementation, value should be of type GenericRecord.

Parameters
valueThe 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
Returns

Definition at line 205 of file GenericWriter.cs.

◆ GetMapSize()

virtual long Avro.Generic.DefaultWriter.GetMapSize ( object  value)
inlineprotectedvirtual

Returns the size of the map object.

The default implementation gurantees 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

Definition at line 323 of file GenericWriter.cs.

◆ GetMapValues()

virtual IEnumerable<KeyValuePair<string, object> > Avro.Generic.DefaultWriter.GetMapValues ( object  value)
inlineprotectedvirtual

Returns the contents of the given map object.

The default implementation guarantees that EnsureMapObject has been called with the given value. The defualt implementation of this method requires that the value is an IDictionary<string, object> and returns its contents.

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

Definition at line 335 of file GenericWriter.cs.

◆ Matches()

virtual bool Avro.Generic.DefaultWriter.Matches ( Schema  sc,
object  obj 
)
inlineprotectedvirtual

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 405 of file GenericWriter.cs.

◆ ResolveUnion()

virtual int Avro.Generic.DefaultWriter.ResolveUnion ( UnionSchema  us,
object  obj 
)
inlineprotectedvirtual

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
objThe object that should be used in matching
Returns

Definition at line 363 of file GenericWriter.cs.

◆ TypeMismatch()

AvroException Avro.Generic.DefaultWriter.TypeMismatch ( object  obj,
string  schemaType,
string  type 
)
inlineprotected

Definition at line 389 of file GenericWriter.cs.

◆ Write()

virtual void Avro.Generic.DefaultWriter.Write ( Schema  schema,
object  value,
Encoder  encoder 
)
inlinevirtual

Examines the schema and dispatches the actual work to one of the other methods of this class.

This allows the derived classes to override specific methods and get custom results.

Parameters
schemaThe schema to use for serializing
valueThe value to be serialized
encoderThe encoder to use during serialization

Definition at line 88 of file GenericWriter.cs.

◆ Write< S >()

virtual void Avro.Generic.DefaultWriter.Write< S > ( object  value,
Schema.Type  tag,
Writer< S >  writer 
)
inlineprotectedvirtual

A generic method to serialize primitive Avro types.

Template Parameters
SType 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.

Definition at line 158 of file GenericWriter.cs.

◆ Write< T >()

void Avro.Generic.DefaultWriter.Write< T > ( value,
Encoder  encoder 
)
inline

Definition at line 76 of file GenericWriter.cs.

◆ WriteArray()

virtual void Avro.Generic.DefaultWriter.WriteArray ( ArraySchema  schema,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Serialized 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
valueThe value being serialized
encoderThe encoder for serialization

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 233 of file GenericWriter.cs.

◆ WriteEnum()

virtual void Avro.Generic.DefaultWriter.WriteEnum ( EnumSchema  es,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Serializes an enumeration.

The default implementation expectes the value to be string whose value is the name of the enumeration.

Parameters
esThe EnumSchema for serialization
valueValue to be written
encoderEncoder for serialization

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 218 of file GenericWriter.cs.

◆ WriteFixed()

virtual void Avro.Generic.DefaultWriter.WriteFixed ( FixedSchema  es,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

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

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 379 of file GenericWriter.cs.

◆ WriteMap()

virtual void Avro.Generic.DefaultWriter.WriteMap ( MapSchema  schema,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Serialized 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
schemaThe MapSchema for serialization
valueThe value to be serialized
encoderThe encoder for serialization

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 291 of file GenericWriter.cs.

◆ WriteNull()

virtual void Avro.Generic.DefaultWriter.WriteNull ( object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Serializes a "null"

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

Definition at line 146 of file GenericWriter.cs.

◆ WriteRecord()

virtual void Avro.Generic.DefaultWriter.WriteRecord ( RecordSchema  schema,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Serialized a record using the given RecordSchema.

It uses GetField method to extract the field value from the given object.

Parameters
schemaThe RecordSchema to use for serialization
valueThe value to be serialized
encoderThe Encoder for serialization

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 172 of file GenericWriter.cs.

◆ WriteUnion()

virtual void Avro.Generic.DefaultWriter.WriteUnion ( UnionSchema  us,
object  value,
Encoder  encoder 
)
inlineprotectedvirtual

Resolves the given value against the given UnionSchema and serializes the object against the resolved schema member.

The default implementation of this method uses ResolveUnion to find the member schema within the UnionSchema.

Parameters
usThe UnionSchema to resolve against
valueThe value to be serialized
encoderThe encoder for serialization

Reimplemented in Avro.Specific.SpecificDefaultWriter.

Definition at line 348 of file GenericWriter.cs.

Property Documentation

◆ Schema

Schema Avro.Generic.DefaultWriter.Schema
get

Definition at line 65 of file GenericWriter.cs.


The documentation for this class was generated from the following file: