19 using System.Collections.Generic;
65 return reader.Read(reuse, d);
129 switch (writerSchema.
Tag)
137 int i = Read<int>(writerSchema.
Tag, readerSchema, d.
ReadInt);
138 switch (readerSchema.
Tag)
152 long l = Read<long>(writerSchema.
Tag, readerSchema, d.
ReadLong);
153 switch (readerSchema.
Tag)
165 float f = Read<float>(writerSchema.
Tag, readerSchema, d.
ReadFloat);
166 switch (readerSchema.
Tag)
175 return Read<double>(writerSchema.
Tag, readerSchema, d.
ReadDouble);
177 return Read<string>(writerSchema.
Tag, readerSchema, d.
ReadString);
179 return Read<byte[]>(writerSchema.
Tag, readerSchema, d.
ReadBytes);
194 throw new AvroException(
"Unknown schema type: " + writerSchema);
236 foreach (
Field wf
in writerSchema)
241 if (rs.TryGetFieldAlias(wf.
Name, out rf))
256 var defaultStream =
new MemoryStream();
259 foreach (
Field rf
in rs)
261 if (writerSchema.Contains(rf.
Name))
continue;
263 defaultStream.Position = 0;
265 defaultStream.Flush();
266 defaultStream.Position = 0;
299 protected virtual bool TryGetField(
object record,
string fieldName,
int fieldPos, out
object value)
301 return (record as
GenericRecord).TryGetValue(fieldName, out value);
312 protected virtual void AddField(
object record,
string fieldName,
int fieldPos,
object fieldValue)
371 for (
int j = 0; j < n; j++, i++)
388 return (reuse !=
null && reuse is
object[]) ? (
object[])reuse :
new object[0];
399 return (array as
object[]).Length;
410 object[] o = array as
object[];
411 Array.Resize(ref o, n);
424 object[] a = array as
object[];
437 return (array as
object[])[index];
455 for (
int j = 0; j < n; j++)
472 if (reuse !=
null && reuse is IDictionary<string, object>)
474 IDictionary<string, object> result = reuse as IDictionary<string, object>;
478 return new Dictionary<string, object>();
487 protected virtual void AddMapEntry(
object map,
string key,
object value)
489 (map as IDictionary<string, object>).Add(key, value);
503 Schema ws = writerSchema[index];
511 return Read(reuse, ws, readerSchema, d);
529 throw new AvroException(
"Size mismatch between reader and writer fixed schemas. Writer: " + writerSchema +
530 ", reader: " + readerSchema);
564 switch (writerSchema.
Tag)
604 for (
long i = 0; i < n; i++)
Skip(s, d);
621 throw new AvroException(
"Unknown schema type: " + writerSchema);
628 if (index >= 0)
return us[index];
629 throw new AvroException(
"No matching schema for " + s +
" in " + us);
virtual object ReadNull(Schema readerSchema, Decoder d)
Deserializes a null from the stream.
double ReadDouble()
Reads a double Avro type
virtual void Skip(Schema writerSchema, Decoder d)
virtual object ReadMap(object reuse, MapSchema writerSchema, Schema readerSchema, Decoder d)
Deserialized an avro map.
int ReadEnum()
Reads an enum AvroType
virtual object ReadUnion(object reuse, UnionSchema writerSchema, Schema readerSchema, Decoder d)
Deserialized an object based on the writer's uninon schema.
Schema Schema
Field type's schema
Class for fields defined in a record
GenericReader(DefaultReader reader)
Constructs a generic reader by directly using the given DefaultReader
T Read(T reuse, Decoder d)
Read a datum.
The defualt class to hold values for enum schema in GenericReader and GenericWriter.
void SkipLong()
Skips a long Avro type on the stream.
virtual object CreateFixed(object reuse, FixedSchema rs)
Returns a fixed object.
GenericReader(Schema writerSchema, Schema readerSchema)
Constructs a generic reader for the given schemas using the DefaultReader.
string ReadString()
Reads a string Avro type
Class for enum type schemas
void SkipBoolean()
Skips a boolean Avro type on the stream.
DefaultReader(Schema writerSchema, Schema readerSchema)
Constructs the default reader for the given schemas using the DefaultReader.
bool ReadBoolean()
Read a boolean Avro type
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.
Schema ValueSchema
Schema for map values type
void SkipDouble()
Skips a double Avro type on the stream.
virtual void SetArrayElement(object array, int index, object value)
Assigns a new value to the object at the given index
The default implementation for the generic reader.
int Pos
Position of the field within its record.
Base class for all schema types
virtual object ReadEnum(object reuse, EnumSchema writerSchema, Schema readerSchema, Decoder d)
Deserializes a enum.
void SkipString()
Skips a string Avro type on the stream.
int ReadInt()
Reads an int Avro type.
readonly string Name
Name of the field.
virtual object CreateArray(object reuse, ArraySchema rs)
Creates a new array object.
virtual bool CanRead(Schema writerSchema)
Returns true if and only if data written using writerSchema can be read using the current schema acco...
float ReadFloat()
Reads a float Avro type
Type
Enum for schema types
long ReadLong()
Reads a long Avro type.
int Size
Fixed size for the bytes
A general purpose reader of data from avro streams.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
byte [] ReadBytes()
Reads the bytes Avro type
T Read< T >(T reuse, Decoder decoder)
Reads an object off the stream.
static Schema findBranch(UnionSchema us, Schema s)
long ReadArrayStart()
Starts reading the array Avro type.
The default type used by GenericReader and GenericWriter for RecordSchema.
virtual object GetArrayElement(object array, int index)
Returns the element at the given index.
S Read< S >(Schema.Type tag, Schema readerSchema, Reader< S > reader)
A generic function to read primitive types
long ReadArrayNext()
See ReadArrayStart().
virtual object ReadArray(object reuse, ArraySchema writerSchema, Schema readerSchema, Decoder d)
Deserializes an array and returns an array 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 ReadRecord(object reuse, RecordSchema writerSchema, Schema readerSchema, Decoder dec)
Deserializes a record from the stream.
object Read(object reuse, Schema writerSchema, Schema readerSchema, Decoder d)
Decoder is used to decode Avro data on a stream.
void SkipFloat()
Skips a float Avro type on the stream.
virtual void AddMapEntry(object map, string key, object value)
Adds an entry to the map.
virtual byte [] GetFixedBuffer(object f)
Returns a buffer of appropriate size to read data into.
int MatchingBranch(Schema s)
Returns the index of a branch that can read the data written by the given schema s.
Class for array type schemas
virtual void ResizeArray(ref object array, int n)
Resizes the array to the new value.
static void EncodeDefaultValue(Encoder enc, Schema schema, JToken jtok)
Reads the passed JToken default value field and writes it in the specified encoder
override bool Equals(object obj)
Checks equality of two enum schema
JToken DefaultValue
The default value for the field stored as JSON object, if defined.
void ReadFixed(byte[] buffer)
A convenience method for ReadFixed(buffer, 0, buffer.Length);
virtual object ReadFixed(object reuse, FixedSchema writerSchema, Schema readerSchema, Decoder d)
Deserializes a fixed object and returns the object.
int ReadUnionIndex()
Reads the index, which determines the type in an union Avro type.
Schema(Type type, PropertyMap props)
Constructor for schema class
virtual object CreateMap(object reuse, MapSchema ms)
Used by the default implementation of ReadMap() to create a fresh map object.
long ReadMapNext()
See ReadMapStart().
void SkipInt()
Skips a int Avro type on the stream.
long ReadMapStart()
Starts reading the map Avro type.
virtual object CreateRecord(object reuse, RecordSchema readerSchema)
Creates a new record object.
void SkipNull()
Skips a null Avro type on the stream.
Schema ItemSchema
Schema for the array 'type' attribute
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.
Type Tag
Schema type property
void ReadNull()
Reads a null Avro type.
virtual int GetArraySize(object array)
Returns the size of the given array object.
void SkipBytes()
Skips a bytes Avro type on the stream.
The default type used by GenericReader and GenericWriter for objects for FixedSchema
Decoder for Avro binary format