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...
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: | |
T | Read< T > (T reuse, Decoder decoder) |
Reads an object off the stream. | |
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. | |
S | Read< S > (Schema.Type tag, Schema readerSchema, Reader< S > reader) |
A generic function to read primitive types. | |
virtual object | ReadRecord (object reuse, RecordSchema writerSchema, Schema readerSchema, Decoder dec) |
Deserializes a record from the stream. | |
virtual object | CreateRecord (object reuse, RecordSchema readerSchema) |
Creates a new record object. Derived classes can override this to return an object of their choice. | |
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. | |
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. | |
virtual object | ReadEnum (object reuse, EnumSchema writerSchema, Schema readerSchema, Decoder d) |
Deserializes a enum. Uses CreateEnum to construct the new enum object. | |
virtual object | CreateEnum (object reuse, EnumSchema es, string symbol) |
Used by the default implementation of ReadEnum to construct a new enum object. | |
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. | |
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[] . | |
virtual int | GetArraySize (object array) |
Returns the size of the given array object. | |
virtual void | ResizeArray (ref object array, int n) |
Resizes the array to the new value. | |
virtual void | SetArrayElement (object array, int index, object value) |
Assigns a new value to the object at the given index. | |
virtual object | GetArrayElement (object array, int index) |
Returns the element at the given index. | |
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(). | |
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>. | |
virtual void | AddMapEntry (object map, string key, object value) |
Adds an entry to the map. | |
virtual object | ReadUnion (object reuse, UnionSchema writerSchema, Schema readerSchema, Decoder d) |
Deserialized an object based on the writer's uninon schema. | |
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. | |
virtual object | CreateFixed (object reuse, FixedSchema rs) |
Returns a fixed object. | |
virtual byte[] | GetFixedBuffer (object f) |
Returns a buffer of appropriate size to read data into. | |
virtual void | Skip (Schema writerSchema, Decoder d) |
Static Protected Member Functions | |
static Schema | findBranch (UnionSchema us, Schema s) |
Properties | |
Schema | ReaderSchema [get, set] |
Schema | WriterSchema [get, set] |
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 |
---|---|
null | null reference |
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:
writerSchema | The schema used while generating the data | |
readerSchema | The schema desired by the reader |
virtual void Avro::Generic::DefaultReader::AddField | ( | object | record, | |
string | fieldName, | |||
int | fieldPos, | |||
object | fieldValue | |||
) | [inline, protected, virtual] |
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.
record | The record object to be probed into. This is guaranteed to be one that was returned by a previous call to CreateRecord. | |
fieldName | The name of the field to probe. | |
fieldValue | The value to be added for the field |
virtual void Avro::Generic::DefaultReader::AddMapEntry | ( | object | map, | |
string | key, | |||
object | value | |||
) | [inline, protected, virtual] |
Adds an entry to the map.
map | A map object, which is guaranteed to be one returned by a previous call to CreateMap(). | |
key | The key to add. | |
value | The value to add. |
virtual object Avro::Generic::DefaultReader::CreateArray | ( | object | reuse, | |
ArraySchema | rs | |||
) | [inline, protected, virtual] |
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[]
.
reuse | If appropriate use this instead of creating a new one. |
virtual object Avro::Generic::DefaultReader::CreateEnum | ( | object | reuse, | |
EnumSchema | es, | |||
string | symbol | |||
) | [inline, protected, virtual] |
Used by the default implementation of ReadEnum to construct a new enum object.
reuse | If appropriate, use this enum object instead of a new one. | |
es | The enum schema used by the reader. | |
symbol | The symbol that needs to be used. |
virtual object Avro::Generic::DefaultReader::CreateFixed | ( | object | reuse, | |
FixedSchema | rs | |||
) | [inline, protected, virtual] |
Returns a fixed object.
reuse | If appropriate, uses this object instead of creating a new one. | |
rs | The reader's FixedSchema. |
virtual object Avro::Generic::DefaultReader::CreateMap | ( | object | reuse, | |
MapSchema | ms | |||
) | [inline, protected, virtual] |
Used by the default implementation of ReadMap() to create a fresh map object. The default implementaion of this method returns a IDictionary<string, map>.
reuse | If appropriate, use this map object instead of creating a new one. |
virtual object Avro::Generic::DefaultReader::CreateRecord | ( | object | reuse, | |
RecordSchema | readerSchema | |||
) | [inline, protected, virtual] |
Creates a new record object. Derived classes can override this to return an object of their choice.
reuse | If appropriate, will reuse this object instead of constructing a new one | |
readerSchema | The schema the reader is using |
virtual object Avro::Generic::DefaultReader::GetArrayElement | ( | object | array, | |
int | index | |||
) | [inline, protected, virtual] |
Returns the element at the given index.
array | Array object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray(). | |
index | The index to look into. |
virtual int Avro::Generic::DefaultReader::GetArraySize | ( | object | array | ) | [inline, protected, virtual] |
Returns the size of the given array object.
array | Array object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray(). |
virtual byte [] Avro::Generic::DefaultReader::GetFixedBuffer | ( | object | f | ) | [inline, protected, virtual] |
Returns a buffer of appropriate size to read data into.
f | The fixed object. It is guaranteed that this is something that has been previously returned by CreateFixed |
S Avro::Generic::DefaultReader::Read< S > | ( | Schema.Type | tag, | |
Schema | readerSchema, | |||
Reader< S > | reader | |||
) | [inline, protected] |
A generic function to read primitive types.
S | The .NET type to read |
tag | The Avro type tag for the object on the stream | |
readerSchema | A schema compatible to the Avro type | |
reader | A function that can read the avro type from the stream |
T Avro::Generic::DefaultReader::Read< T > | ( | T | reuse, | |
Decoder | decoder | |||
) | [inline] |
Reads an object off the stream.
T | The 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. |
reuse | If not null, the implemenation will try to use to return the object | |
decoder | The decoder for deserialization |
virtual object Avro::Generic::DefaultReader::ReadArray | ( | object | reuse, | |
ArraySchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | d | |||
) | [inline, protected, virtual] |
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.
reuse | If appropriate, uses this instead of creating a new array object. | |
writerSchema | The schema used by the writer. | |
readerSchema | The schema that the reader uses. | |
d | The decoder for deserialization. |
Reimplemented in Avro::Specific::SpecificDefaultReader.
virtual object Avro::Generic::DefaultReader::ReadEnum | ( | object | reuse, | |
EnumSchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | d | |||
) | [inline, protected, virtual] |
Deserializes a enum. Uses CreateEnum to construct the new enum object.
reuse | If appropirate, uses this instead of creating a new enum object. | |
writerSchema | The schema the writer used while writing the enum | |
readerSchema | The schema the reader is using | |
d | The decoder for deserialization. |
Reimplemented in Avro::Specific::SpecificDefaultReader.
virtual object Avro::Generic::DefaultReader::ReadFixed | ( | object | reuse, | |
FixedSchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | d | |||
) | [inline, protected, virtual] |
Deserializes a fixed object and returns the object. The default implementation uses CreateFixed() and GetFixedBuffer() and returns what CreateFixed() returned.
reuse | If appropriate, uses this object instead of creating a new one. | |
writerSchema | The FixedSchema the writer used during serialization. | |
readerSchema | The schema that the readr uses. Must be a FixedSchema with the same size as the writerSchema. | |
d | The decoder for deserialization. |
Reimplemented in Avro::Specific::SpecificDefaultReader.
virtual object Avro::Generic::DefaultReader::ReadMap | ( | object | reuse, | |
MapSchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | d | |||
) | [inline, protected, virtual] |
Deserialized an avro map. The default implemenation creats a new map using CreateMap() and then adds elements to the map using AddMapEntry().
reuse | If appropriate, use this instead of creating a new map object. | |
writerSchema | The schema the writer used to write the map. | |
readerSchema | The schema the reader is using. | |
d | The decoder for serialization. |
Reimplemented in Avro::Specific::SpecificDefaultReader.
virtual object Avro::Generic::DefaultReader::ReadNull | ( | Schema | readerSchema, | |
Decoder | d | |||
) | [inline, protected, virtual] |
Deserializes a null from the stream.
readerSchema | Reader's schema, which should be a NullSchema | |
d | The decoder for deserialization |
virtual object Avro::Generic::DefaultReader::ReadRecord | ( | object | reuse, | |
RecordSchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | dec | |||
) | [inline, protected, virtual] |
Deserializes a record from the stream.
reuse | If not null, a record object that could be reused for returning the result | |
writerSchema | The writer's RecordSchema | |
readerSchema | The reader's schema, must be RecordSchema too. | |
dec | The decoder for deserialization |
Reimplemented in Avro::Specific::SpecificDefaultReader.
virtual object Avro::Generic::DefaultReader::ReadUnion | ( | object | reuse, | |
UnionSchema | writerSchema, | |||
Schema | readerSchema, | |||
Decoder | d | |||
) | [inline, protected, virtual] |
Deserialized an object based on the writer's uninon schema.
reuse | If appropriate, uses this object instead of creating a new one. | |
writerSchema | The UnionSchema that the writer used. | |
readerSchema | The schema the reader uses. | |
d | The decoder for serialization. |
virtual void Avro::Generic::DefaultReader::ResizeArray | ( | ref object | array, | |
int | n | |||
) | [inline, protected, virtual] |
Resizes the array to the new value.
array | Array object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray(). | |
n | The new size. |
virtual void Avro::Generic::DefaultReader::SetArrayElement | ( | object | array, | |
int | index, | |||
object | value | |||
) | [inline, protected, virtual] |
Assigns a new value to the object at the given index.
array | Array object whose size is required. This is guaranteed to be somthing returned by a previous call to CreateArray(). | |
index | The index to reassign to. | |
value | The value to assign. |
virtual bool Avro::Generic::DefaultReader::TryGetField | ( | object | record, | |
string | fieldName, | |||
int | fieldPos, | |||
out object | value | |||
) | [inline, protected, virtual] |
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.
record | The record object to be probed into. This is guaranteed to be one that was returned by a previous call to CreateRecord. | |
fieldName | The name of the field to probe. | |
value | The value of the field, if found. Null otherwise. |