Avro C#

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 different 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:

## 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 implementation maps Avro types to .NET types as follows: More...
T | Read< T > (T reuse, Decoder decoder)
| Reads an object off the stream. More...
object | Read (object reuse, Schema writerSchema, Schema readerSchema, Decoder d)
| Reads an object off the stream. More...

## Protected Member Functions
virtual object | ReadNull (Schema readerSchema, Decoder d)
| Deserializes a null from the stream. More...
T | Read< T > (Schema.Type tag, Schema readerSchema, Reader< T > 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 implementation creates 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 implementation 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 union schema. More...
virtual object | ReadLogical (object reuse, LogicalSchema writerSchema, Schema readerSchema, Decoder d)
| Deserializes an object based on the writer's logical schema. Uses the underlying logical type to convert the value to the logical type. 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)
| Skip an instance of a schema. More...

## Static Protected Member Functions
static Schema | findBranch (UnionSchema us, Schema s)
| Finds the branch of the union schema associated with the given schema. More...

## Properties
Schema | ReaderSchema`[get]`
| Schema to use when reading data with this reader. More...
Schema | WriterSchema`[get]`
| Schema used to write data that we are reading with this reader. More...

## 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 different 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

## Constructor & Destructor Documentation

## ◆ DefaultReader()

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 implementation maps Avro types to .NET types as follows:

Parameters

  writerSchema | The schema used while generating the data
  readerSchema | The schema desired by the reader

## Member Function Documentation

## ◆ AddField()

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.

Parameters

  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.
  fieldPos | Position of the field in the schema - not used in the base implementation.
  fieldValue | The value to be added for the field

## ◆ AddMapEntry()

virtual void Avro.Generic.DefaultReader.AddMapEntry | ( | object | map,
|  | string | key,
|  | object | value
| ) |  |
| inline protected virtual

Adds an entry to the map.

Parameters

  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.

## ◆ CreateArray()

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[]`.

Parameters

  reuse | If appropriate use this instead of creating a new one.
  rs | Array schema, not used in base implementation

Returns
  An object suitable to deserialize an avro array

## ◆ CreateEnum()

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.

Parameters

  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.

Returns
  The default implementation returns a GenericEnum.

## ◆ CreateFixed()

virtual object Avro.Generic.DefaultReader.CreateFixed | ( | object | reuse,
|  | FixedSchema | rs
| ) |  |
| inline protected virtual

Returns a fixed object.

Parameters

  reuse | If appropriate, uses this object instead of creating a new one.
  rs | The reader's FixedSchema.

Returns
  A fixed object with an appropriate buffer.

## ◆ CreateMap()

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 implementation of this method returns a IDictionary<string, map>.

Parameters

  reuse | If appropriate, use this map object instead of creating a new one.
  ms | Map schema to use when creating the object.

Returns
  An empty map object.

## ◆ CreateRecord()

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.

Parameters

  reuse | If appropriate, will reuse this object instead of constructing a new one
  readerSchema | The schema the reader is using

Returns

## ◆ findBranch()

static Schema Avro.Generic.DefaultReader.findBranch | ( | UnionSchema | us,
|  | Schema | s
| ) |  |
| inline static protected

Finds the branch of the union schema associated with the given schema.

Parameters

  us | Union schema.
  s | Schema to find in the union schema.

Returns
  Schema branch in the union schema.

## ◆ GetArrayElement()

virtual object Avro.Generic.DefaultReader.GetArrayElement | ( | object | array,
|  | int | index
| ) |  |
| inline protected virtual

Returns the element at the given index.

Parameters

  array | Array object whose size is required. This is guaranteed to be something returned by a previous call to CreateArray().
  index | The index to look into.

Returns
  The object the given index. Null if no object has been assigned to that index.

## ◆ GetArraySize()

virtual int Avro.Generic.DefaultReader.GetArraySize | ( | object | array | ) |
| inline protected virtual

Returns the size of the given array object.

Parameters

  array | Array object whose size is required. This is guaranteed to be something returned by a previous call to CreateArray().

Returns
  The size of the array

## ◆ GetFixedBuffer()

virtual byte [] Avro.Generic.DefaultReader.GetFixedBuffer | ( | object | f | ) |
| inline protected virtual

Returns a buffer of appropriate size to read data into.

Parameters

  f | The fixed object. It is guaranteed that this is something that has been previously returned by CreateFixed

Returns
  A byte buffer of fixed's size.

## ◆ Read()

object Avro.Generic.DefaultReader.Read | ( | object | reuse,
|  | Schema | writerSchema,
|  | Schema | readerSchema,
|  | Decoder | d
| ) |  |
| inline

Reads an object off the stream.

Parameters

  reuse | If not null, the implementation will try to use to return the object.
  writerSchema | Schema used to write the data.
  readerSchema | Schema to use when reading the data.
  d | Decoder to read from.

Returns
  Object read from the decoder.

## ◆ Read< T >() [1/2]

T Avro.Generic.DefaultReader.Read< T > | ( | Schema.Type | tag,
|  | Schema | readerSchema,
|  | Reader< T > | reader
| ) |  |
| inline protected

A generic function to read primitive types

Template Parameters

  T | The .NET type to read

Parameters

  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

Returns
  The primitive type just read

## ◆ Read< T >() [2/2]

T Avro.Generic.DefaultReader.Read< T > | ( | T | reuse,
|  | Decoder | decoder
| ) |  |
| inline

Reads an object off the stream.

Template Parameters

  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.

Parameters

  reuse | If not null, the implementation will try to use to return the object
  decoder | The decoder for deserialization

Returns
  Object read from the decoder.

## ◆ ReadArray()

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.

Parameters

  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.

Returns
  The deserialized array object.

Reimplemented in Avro.Reflect.ReflectDefaultReader, and Avro.Specific.SpecificDefaultReader.

## ◆ ReadEnum()

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.

Parameters

  reuse | If appropriate, 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.

Returns
  An enum object.

Reimplemented in Avro.Specific.SpecificDefaultReader, and Avro.Reflect.ReflectDefaultReader.

## ◆ ReadFixed()

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.

Parameters

  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 reader uses. Must be a FixedSchema with the same size as the writerSchema.
  d | The decoder for deserialization.

Returns
  The deserialized object.

Reimplemented in Avro.Reflect.ReflectDefaultReader, and Avro.Specific.SpecificDefaultReader.

## ◆ ReadLogical()

virtual object Avro.Generic.DefaultReader.ReadLogical | ( | object | reuse,
|  | LogicalSchema | writerSchema,
|  | Schema | readerSchema,
|  | Decoder | d
| ) |  |
| inline protected virtual

Deserializes an object based on the writer's logical schema. Uses the underlying logical type to convert the value to the logical type.

Parameters

  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.

Returns
  The deserialized object.

## ◆ ReadMap()

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

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

Parameters

  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.

Returns
  The deserialized map object.

Reimplemented in Avro.Reflect.ReflectDefaultReader, and Avro.Specific.SpecificDefaultReader.

## ◆ ReadNull()

virtual object Avro.Generic.DefaultReader.ReadNull | ( | Schema | readerSchema,
|  | Decoder | d
| ) |  |
| inline protected virtual

Deserializes a null from the stream.

Parameters

  readerSchema | Reader's schema, which should be a NullSchema
  d | The decoder for deserialization

Returns

## ◆ ReadRecord()

virtual object Avro.Generic.DefaultReader.ReadRecord | ( | object | reuse,
|  | RecordSchema | writerSchema,
|  | Schema | readerSchema,
|  | Decoder | dec
| ) |  |
| inline protected virtual

Deserializes a record from the stream.

Parameters

  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

Returns
  The record object just read

Reimplemented in Avro.Reflect.ReflectDefaultReader, and Avro.Specific.SpecificDefaultReader.

## ◆ ReadUnion()

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 union schema.

Parameters

  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.

Returns
  The deserialized object.

## ◆ ResizeArray()

virtual void Avro.Generic.DefaultReader.ResizeArray | ( | ref object | array,
|  | int | n
| ) |  |
| inline protected virtual

Resizes the array to the new value.

Parameters

  array | Array object whose size is required. This is guaranteed to be something returned by a previous call to CreateArray().
  n | The new size.

## ◆ SetArrayElement()

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

Parameters

  array | Array object whose size is required. This is guaranteed to be something returned by a previous call to CreateArray().
  index | The index to reassign to.
  value | The value to assign.

## ◆ Skip()

virtual void Avro.Generic.DefaultReader.Skip | ( | Schema | writerSchema,
|  | Decoder | d
| ) |  |
| inline protected virtual

Skip an instance of a schema.

Parameters

  writerSchema | Schema to skip.
  d | Decoder we're reading from.

## ◆ TryGetField()

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.

Parameters

  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.
  fieldPos | Position of the field in the schema - not used in the base implementation.
  value | The value of the field, if found. Null otherwise.

Returns
  True if and only if a field with the given name is found.

## Property Documentation

## ◆ ReaderSchema

Schema Avro.Generic.DefaultReader.ReaderSchema
| get

Schema to use when reading data with this reader.

## ◆ WriterSchema

Schema Avro.Generic.DefaultReader.WriterSchema
| get

Schema used to write data that we are reading with this reader.

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

- src/apache/main/Generic/GenericReader.cs