18 using System.Collections;
52 return new SpecificArrayAccess(readerSchema);
57 return new SpecificEnumAccess();
62 return new SpecificMapAccess(readerSchema);
67 if (readerSchema.
Name ==
null)
72 return new SpecificRecordAccess(readerSchema);
77 return new SpecificFixedAccess(readerSchema);
83 return creator.
GetConstructor(name, schemaType, creator.GetType(name, schemaType));
86 private class SpecificEnumAccess : EnumAccess
88 public object CreateEnum(
object reuse,
int ordinal)
94 private class SpecificRecordAccess : RecordAccess
96 private ObjectCreator.CtorDelegate objCreator;
98 public SpecificRecordAccess(RecordSchema readerSchema)
100 objCreator = GetConstructor(readerSchema.Fullname, Schema.Type.Record);
103 public object CreateRecord(
object reuse)
105 return reuse ?? objCreator();
108 public object GetField(
object record,
string fieldName,
int fieldPos)
110 return ((ISpecificRecord)record).Get(fieldPos);
113 public void AddField(
object record,
string fieldName,
int fieldPos,
object fieldValue)
115 ((ISpecificRecord)record).Put(fieldPos, fieldValue);
119 private class SpecificFixedAccess : FixedAccess
121 private ObjectCreator.CtorDelegate objCreator;
123 public SpecificFixedAccess(FixedSchema readerSchema)
125 objCreator = GetConstructor(readerSchema.Fullname, Schema.Type.Fixed);
128 public object CreateFixed(
object reuse)
130 return reuse ?? objCreator();
133 public byte[] GetFixedBuffer(
object rec)
135 return ((SpecificFixed) rec).Value;
139 private class SpecificArrayAccess : ArrayAccess
141 private ObjectCreator.CtorDelegate objCreator;
143 public SpecificArrayAccess(ArraySchema readerSchema)
146 string type =
Avro.
CodeGen.getType(readerSchema,
false, ref nEnum);
147 type = type.Remove(0, 6);
148 type = type.Remove(type.Length - 1);
150 objCreator = GetConstructor(type, Schema.Type.Array);
153 public object Create(
object reuse)
159 array = reuse as IList;
161 throw new AvroException(
"array object does not implement non-generic IList" );
167 array = objCreator() as IList;
171 public
void EnsureSize(ref
object array,
int targetSize)
176 public void Resize(ref
object array,
int targetSize)
181 public void AddElements(
object array,
int elements,
int index,
ReadItem itemReader,
Decoder decoder,
bool reuse )
183 var list = (IList)array;
184 for (
int i=0; i < elements; i++)
186 list.Add( itemReader(
null, decoder ) );
191 private class SpecificMapAccess : MapAccess
193 private ObjectCreator.CtorDelegate objCreator;
195 public SpecificMapAccess(MapSchema readerSchema)
198 string type =
Avro.
CodeGen.getType(readerSchema,
false, ref nEnum);
199 type = type.Remove(0, 19);
200 type = type.Remove(type.Length - 1);
202 objCreator = GetConstructor(type, Schema.Type.Map);
205 public object Create(
object reuse)
210 map = reuse as IDictionary;
212 throw new AvroException(
"map object does not implement non-generic IList");
217 map = objCreator() as System.Collections.IDictionary;
221 public
void AddElements(
object mapObj,
int elements,
ReadItem itemReader,
Decoder decoder,
bool reuse)
223 var map = ((IDictionary)mapObj);
224 for (
int i = 0; i < elements; i++)
226 var key = decoder.ReadString();
227 map[key] = itemReader(
null, decoder);
CtorDelegate GetConstructor(string name, Schema.Type schemaType, Type type)
Gets the default constructor for the specified type
PreresolvingDatumReader for reading data to GenericRecord classes or primitives.
Class for enum type schemas
Base class for all schema types
SpecificDatumReader(Schema writerSchema, Schema readerSchema)
override string Name
Name of the schema
Type
Enum for schema types
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
A general purpose reader of data from avro streams.
PreresolvingDatumReader for reading data to ISpecificRecord classes.
Decoder is used to decode Avro data on a stream.
override RecordAccess GetRecordAccess(RecordSchema readerSchema)
delegate object CtorDelegate()
Class for array type schemas
override bool IsReusable(Schema.Type tag)
Indicates if it's possible to reuse an object of the specified type.
override FixedAccess GetFixedAccess(FixedSchema readerSchema)
override MapAccess GetMapAccess(MapSchema readerSchema)
static ObjectCreator Instance
delegate object ReadItem(object reuse, Decoder dec)
override ArrayAccess GetArrayAccess(ArraySchema readerSchema)
override EnumAccess GetEnumAccess(EnumSchema readerSchema)