Avro C#
 All Classes Namespaces Functions Variables Enumerations Properties
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Properties | List of all members
Avro.Generic.DefaultReader Class Reference

The default implementation for the generic reader. It constructs new .NET objects for avro objects on the stream and returns the .NET object. Users can directly use this class or, if they want to customize the object types for differnt Avro schema types, can derive from this class. There are enough hooks in this class to allow customization. More...

Inheritance diagram for Avro.Generic.DefaultReader:
Avro.Specific.SpecificDefaultReader

Public Member Functions

 DefaultReader (Schema writerSchema, Schema readerSchema)
 Constructs the default reader for the given schemas using the DefaultReader. If the reader's and writer's schemas are different this class performs the resolution. This default implemenation maps Avro types to .NET types as follows: More...
 
Read< T > (T reuse, Decoder decoder)
 Reads an object off the stream. More...
 
object Read (object reuse, Schema writerSchema, Schema readerSchema, Decoder d)
 

Protected Member Functions

virtual object ReadNull (Schema readerSchema, Decoder d)
 Deserializes a null from the stream. More...
 
Read< S > (Schema.Type tag, Schema readerSchema, Reader< S > reader)
 A generic function to read primitive types More...
 
virtual object ReadRecord (object reuse, RecordSchema writerSchema, Schema readerSchema, Decoder dec)
 Deserializes a record from the stream. More...
 
virtual object CreateRecord (object reuse, RecordSchema readerSchema)
 Creates a new record object. Derived classes can override this to return an object of their choice. More...
 
virtual bool TryGetField (object record, string fieldName, int fieldPos, out object value)
 Used by the default implementation of ReadRecord() to get the existing field of a record object. The derived classes can override this to make their own interpretation of the record object. More...
 
virtual void AddField (object record, string fieldName, int fieldPos, object fieldValue)
 Used by the default implementation of ReadRecord() to add a field to a record object. The derived classes can override this to suit their own implementation of the record object. More...
 
virtual object ReadEnum (object reuse, EnumSchema writerSchema, Schema readerSchema, Decoder d)
 Deserializes a enum. Uses CreateEnum to construct the new enum object. More...
 
virtual object CreateEnum (object reuse, EnumSchema es, string symbol)
 Used by the default implementation of ReadEnum to construct a new enum object. More...
 
virtual object ReadArray (object reuse, ArraySchema writerSchema, Schema readerSchema, Decoder d)
 Deserializes an array and returns an array object. It uses CreateArray() and works on it before returning it. It also uses GetArraySize(), ResizeArray(), SetArrayElement() and GetArrayElement() methods. Derived classes can override these methods to customize their behavior. More...
 
virtual object CreateArray (object reuse, ArraySchema rs)
 Creates a new array object. The initial size of the object could be anything. The users should use GetArraySize() to determine the size. The default implementation creates an object[]. More...
 
virtual int GetArraySize (object array)
 Returns the size of the given array object. More...
 
virtual void ResizeArray (ref object array, int n)
 Resizes the array to the new value. More...
 
virtual void SetArrayElement (object array, int index, object value)
 Assigns a new value to the object at the given index More...
 
virtual object GetArrayElement (object array, int index)
 Returns the element at the given index. More...
 
virtual object ReadMap (object reuse, MapSchema writerSchema, Schema readerSchema, Decoder d)
 Deserialized an avro map. The default implemenation creats a new map using CreateMap() and then adds elements to the map using AddMapEntry(). More...
 
virtual object CreateMap (object reuse, MapSchema ms)
 Used by the default implementation of ReadMap() to create a fresh map object. The default implementaion of this method returns a IDictionary<string, map>. More...
 
virtual void AddMapEntry (object map, string key, object value)
 Adds an entry to the map. More...
 
virtual object ReadUnion (object reuse, UnionSchema writerSchema, Schema readerSchema, Decoder d)
 Deserialized an object based on the writer's uninon schema. More...
 
virtual object ReadFixed (object reuse, FixedSchema writerSchema, Schema readerSchema, Decoder d)
 Deserializes a fixed object and returns the object. The default implementation uses CreateFixed() and GetFixedBuffer() and returns what CreateFixed() returned. More...
 
virtual object CreateFixed (object reuse, FixedSchema rs)
 Returns a fixed object. More...
 
virtual byte[] GetFixedBuffer (object f)
 Returns a buffer of appropriate size to read data into. More...
 
virtual void Skip (Schema writerSchema, Decoder d)
 

Static Protected Member Functions

static Schema findBranch (UnionSchema us, Schema s)
 

Properties

Schema ReaderSchema [get]
 
Schema WriterSchema [get]
 

Detailed Description

The default implementation for the generic reader. It constructs new .NET objects for avro objects on the stream and returns the .NET object. Users can directly use this class or, if they want to customize the object types for differnt Avro schema types, can derive from this class. There are enough hooks in this class to allow customization.

Avro Type.NET Type
nullnull reference

Constructor & Destructor Documentation

Avro.Generic.DefaultReader.DefaultReader ( Schema  writerSchema,
Schema  readerSchema 
)
inline

Constructs the default reader for the given schemas using the DefaultReader. If the reader's and writer's schemas are different this class performs the resolution. This default implemenation maps Avro types to .NET types as follows:

Parameters
writerSchemaThe schema used while generating the data
readerSchemaThe schema desired by the reader

Member Function Documentation

virtual void Avro.Generic.DefaultReader.AddField ( object  record,
string  fieldName,
int  fieldPos,
object  fieldValue 
)
inlineprotectedvirtual

Used by the default implementation of ReadRecord() to add a field to a record object. The derived classes can override this to suit their own implementation of the record object.

Parameters
recordThe record object to be probed into. This is guaranteed to be one that was returned by a previous call to CreateRecord.
fieldNameThe name of the field to probe.
fieldValueThe value to be added for the field
virtual void Avro.Generic.DefaultReader.AddMapEntry ( object  map,
string  key,
object  value 
)
inlineprotectedvirtual

Adds an entry to the map.

Parameters
mapA map object, which is guaranteed to be one returned by a previous call to CreateMap().
keyThe key to add.
valueThe value to add.
virtual object Avro.Generic.DefaultReader.CreateArray ( object  reuse,
ArraySchema  rs 
)
inlineprotectedvirtual

Creates a new array object. The initial size of the object could be anything. The users should use GetArraySize() to determine the size. The default implementation creates an object[].

Parameters
reuseIf appropriate use this instead of creating a new one.
Returns
An object suitable to deserialize an avro array
virtual object Avro.Generic.DefaultReader.CreateEnum ( object  reuse,
EnumSchema  es,
string  symbol 
)
inlineprotectedvirtual

Used by the default implementation of ReadEnum to construct a new enum object.

Parameters
reuseIf appropriate, use this enum object instead of a new one.
esThe enum schema used by the reader.
symbolThe symbol that needs to be used.
Returns
The default implemenation returns a GenericEnum.
virtual object Avro.Generic.DefaultReader.CreateFixed ( object  reuse,
FixedSchema  rs 
)
inlineprotectedvirtual

Returns a fixed object.

Parameters
reuseIf appropriate, uses this object instead of creating a new one.
rsThe reader's FixedSchema.
Returns
A fixed object with an appropriate buffer.
virtual object Avro.Generic.DefaultReader.CreateMap ( object  reuse,
MapSchema  ms 
)
inlineprotectedvirtual

Used by the default implementation of ReadMap() to create a fresh map object. The default implementaion of this method returns a IDictionary<string, map>.

Parameters
reuseIf appropriate, use this map object instead of creating a new one.
Returns
An empty map object.
virtual object Avro.Generic.DefaultReader.CreateRecord ( object  reuse,
RecordSchema  readerSchema 
)
inlineprotectedvirtual

Creates a new record object. Derived classes can override this to return an object of their choice.

Parameters
reuseIf appropriate, will reuse this object instead of constructing a new one
readerSchemaThe schema the reader is using
Returns
virtual object Avro.Generic.DefaultReader.GetArrayElement ( object  array,
int  index 
)
inlineprotectedvirtual

Returns the element at the given index.

Parameters
arrayArray object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray().
indexThe index to look into.
Returns
The object the given index. Null if no object has been assigned to that index.
virtual int Avro.Generic.DefaultReader.GetArraySize ( object  array)
inlineprotectedvirtual

Returns the size of the given array object.

Parameters
arrayArray object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray().
Returns
The size of the array
virtual byte [] Avro.Generic.DefaultReader.GetFixedBuffer ( object  f)
inlineprotectedvirtual

Returns a buffer of appropriate size to read data into.

Parameters
fThe fixed object. It is guaranteed that this is something that has been previously returned by CreateFixed
Returns
A byte buffer of fixed's size.
S Avro.Generic.DefaultReader.Read< S > ( Schema.Type  tag,
Schema  readerSchema,
Reader< S >  reader 
)
inlineprotected

A generic function to read primitive types

Template Parameters
SThe .NET type to read
Parameters
tagThe Avro type tag for the object on the stream
readerSchemaA schema compatible to the Avro type
readerA function that can read the avro type from the stream
Returns
The primitive type just read
T Avro.Generic.DefaultReader.Read< T > ( reuse,
Decoder  decoder 
)
inline

Reads an object off the stream.

Template Parameters
TThe type of object to read. A single schema typically returns an object of a single .NET class. The only exception is UnionSchema, which can return a object of different types based on the branch selected.
Parameters
reuseIf not null, the implemenation will try to use to return the object
decoderThe decoder for deserialization
Returns
virtual object Avro.Generic.DefaultReader.ReadArray ( object  reuse,
ArraySchema  writerSchema,
Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserializes an array and returns an array object. It uses CreateArray() and works on it before returning it. It also uses GetArraySize(), ResizeArray(), SetArrayElement() and GetArrayElement() methods. Derived classes can override these methods to customize their behavior.

Parameters
reuseIf appropriate, uses this instead of creating a new array object.
writerSchemaThe schema used by the writer.
readerSchemaThe schema that the reader uses.
dThe decoder for deserialization.
Returns
The deserialized array object.

Reimplemented in Avro.Specific.SpecificDefaultReader.

virtual object Avro.Generic.DefaultReader.ReadEnum ( object  reuse,
EnumSchema  writerSchema,
Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserializes a enum. Uses CreateEnum to construct the new enum object.

Parameters
reuseIf appropirate, uses this instead of creating a new enum object.
writerSchemaThe schema the writer used while writing the enum
readerSchemaThe schema the reader is using
dThe decoder for deserialization.
Returns
An enum object.

Reimplemented in Avro.Specific.SpecificDefaultReader.

virtual object Avro.Generic.DefaultReader.ReadFixed ( object  reuse,
FixedSchema  writerSchema,
Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserializes a fixed object and returns the object. The default implementation uses CreateFixed() and GetFixedBuffer() and returns what CreateFixed() returned.

Parameters
reuseIf appropriate, uses this object instead of creating a new one.
writerSchemaThe FixedSchema the writer used during serialization.
readerSchemaThe schema that the readr uses. Must be a FixedSchema with the same size as the writerSchema.
dThe decoder for deserialization.
Returns
The deserilized object.

Reimplemented in Avro.Specific.SpecificDefaultReader.

virtual object Avro.Generic.DefaultReader.ReadMap ( object  reuse,
MapSchema  writerSchema,
Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserialized an avro map. The default implemenation creats a new map using CreateMap() and then adds elements to the map using AddMapEntry().

Parameters
reuseIf appropriate, use this instead of creating a new map object.
writerSchemaThe schema the writer used to write the map.
readerSchemaThe schema the reader is using.
dThe decoder for serialization.
Returns
The deserialized map object.

Reimplemented in Avro.Specific.SpecificDefaultReader.

virtual object Avro.Generic.DefaultReader.ReadNull ( Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserializes a null from the stream.

Parameters
readerSchemaReader's schema, which should be a NullSchema
dThe decoder for deserialization
Returns
virtual object Avro.Generic.DefaultReader.ReadRecord ( object  reuse,
RecordSchema  writerSchema,
Schema  readerSchema,
Decoder  dec 
)
inlineprotectedvirtual

Deserializes a record from the stream.

Parameters
reuseIf not null, a record object that could be reused for returning the result
writerSchemaThe writer's RecordSchema
readerSchemaThe reader's schema, must be RecordSchema too.
decThe decoder for deserialization
Returns
The record object just read

Reimplemented in Avro.Specific.SpecificDefaultReader.

virtual object Avro.Generic.DefaultReader.ReadUnion ( object  reuse,
UnionSchema  writerSchema,
Schema  readerSchema,
Decoder  d 
)
inlineprotectedvirtual

Deserialized an object based on the writer's uninon schema.

Parameters
reuseIf appropriate, uses this object instead of creating a new one.
writerSchemaThe UnionSchema that the writer used.
readerSchemaThe schema the reader uses.
dThe decoder for serialization.
Returns
The deserialized object.
virtual void Avro.Generic.DefaultReader.ResizeArray ( ref object  array,
int  n 
)
inlineprotectedvirtual

Resizes the array to the new value.

Parameters
arrayArray object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray().
nThe new size.
virtual void Avro.Generic.DefaultReader.SetArrayElement ( object  array,
int  index,
object  value 
)
inlineprotectedvirtual

Assigns a new value to the object at the given index

Parameters
arrayArray object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray().
indexThe index to reassign to.
valueThe value to assign.
virtual bool Avro.Generic.DefaultReader.TryGetField ( object  record,
string  fieldName,
int  fieldPos,
out object  value 
)
inlineprotectedvirtual

Used by the default implementation of ReadRecord() to get the existing field of a record object. The derived classes can override this to make their own interpretation of the record object.

Parameters
recordThe record object to be probed into. This is guaranteed to be one that was returned by a previous call to CreateRecord.
fieldNameThe name of the field to probe.
valueThe value of the field, if found. Null otherwise.
Returns
True if and only if a field with the given name is found.

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