19 using System.Collections.Generic;
53 writer.Write(value, encoder);
136 error(schema, value);
148 if (value !=
null)
throw TypeMismatch(value,
"null",
"null");
160 if (!(value is S))
throw TypeMismatch(value, tag.ToString(), typeof(S).ToString());
175 foreach (
Field field
in schema)
205 protected virtual object GetField(
object value,
string fieldName,
int fieldPos)
239 for (
long i = 0; i < l; i++)
254 if (value ==
null || !(value is Array))
throw TypeMismatch(value,
"array",
"Array");
267 return (value as Array).Length;
281 return (value as Array).GetValue(index);
294 IDictionary<string, object> vv = (IDictionary<string, object>)value;
297 foreach (KeyValuePair<string, object> obj
in GetMapValues(vv))
300 encoder.WriteString(obj.Key);
301 Write(schema.ValueSchema, obj.Value, encoder);
303 encoder.WriteMapEnd();
313 if (value ==
null || !(value is IDictionary<string, object>))
throw TypeMismatch(value,
"map",
"IDictionary<string, object>");
325 return (value as IDictionary<string, object>).Count;
335 protected virtual IEnumerable<KeyValuePair<string, object>>
GetMapValues(
object value)
337 return value as IDictionary<string, object>;
352 Write(us[index], value, encoder);
365 for (
int i = 0; i < us.
Count; i++)
367 if (
Matches(us[i], obj))
return i;
369 throw new AvroException(
"Cannot find a match for " + obj.GetType() +
" in " + us);
391 return new AvroException(type +
" required to write against " + schemaType +
" schema but found " + (
null == obj ?
"null" : obj.GetType().ToString()) );
394 private void error(
Schema schema, Object value)
421 return obj is double;
423 return obj is
byte[];
425 return obj is string;
433 return obj is Array && !(obj is
byte[]);
435 return obj is IDictionary<string, object>;
virtual void EnsureArrayObject(object value)
Checks if the given object is an array.
virtual void WriteNull(object value, Encoder encoder)
Serializes a "null"
virtual void Write< S >(object value, Schema.Type tag, Writer< S > writer)
A generic method to serialize primitive Avro types.
Schema Schema
Field type's schema
Class for fields defined in a record
The defualt class to hold values for enum schema in GenericReader and GenericWriter.
void WriteBytes(byte[] value)
virtual void WriteUnion(UnionSchema us, object value, Encoder encoder)
Resolves the given value against the given UnionSchema and serializes the object against the resolved...
Class for enum type schemas
void WriteDouble(double value)
int Pos
Position of the field within its record.
Base class for all schema types
virtual object GetArrayElement(object value, long index)
Returns the element at the given index from the given array object.
virtual IEnumerable< KeyValuePair< string, object > > GetMapValues(object value)
Returns the contents of the given map object.
void SetItemCount(long value)
void WriteLong(long value)
readonly string Name
Name of the field.
virtual void EnsureMapObject(object value)
Checks if the given object is a map.
virtual long GetMapSize(object value)
Returns the size of the map object.
A General purpose writer for serializing objects into a Stream using Avro.
virtual void WriteEnum(EnumSchema es, object value, Encoder encoder)
Serializes an enumeration.
Type
Enum for schema types
virtual object GetField(object value, string fieldName, int fieldPos)
Extracts the field value from the given object.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
int Ordinal(string symbol)
Returns the position of the given symbol within this enum.
The default type used by GenericReader and GenericWriter for RecordSchema.
AvroException TypeMismatch(object obj, string schemaType, string type)
virtual void WriteFixed(FixedSchema es, object value, Encoder encoder)
Serialized a fixed object.
virtual void Write(Schema schema, object value, Encoder encoder)
Examines the schema and dispatches the actual work to one of the other methods of this class.
void WriteBoolean(bool value)
void WriteEnum(int value)
void WriteFixed(byte[] data)
virtual void WriteRecord(RecordSchema schema, object value, Encoder encoder)
Serialized a record using the given RecordSchema.
void WriteFloat(float value)
DefaultWriter(Schema schema)
Constructs a generic writer for the given schema.
Class for array type schemas
virtual void WriteArray(ArraySchema schema, object value, Encoder encoder)
Serialized an array.
virtual void EnsureRecordObject(RecordSchema s, object value)
void Write< T >(T value, Encoder encoder)
Schema(Type type, PropertyMap props)
Constructor for schema class
A typesafe wrapper around DefaultWriter.
void WriteUnionIndex(int value)
virtual bool Matches(Schema sc, object obj)
delegate void Writer< T >(T t)
void Write(T value, Encoder encoder)
Serializes the given object using this writer's schema.
virtual int ResolveUnion(UnionSchema us, object obj)
Finds the branch within the given UnionSchema that matches the given object.
int Count
Count of schemas in the union
GenericWriter(DefaultWriter writer)
void WriteString(string value)
Schema ItemSchema
Schema for the array 'type' attribute
virtual long GetArrayLength(object value)
Returns the length of an array.
Type Tag
Schema type property
GenericWriter(Schema schema)
The default type used by GenericReader and GenericWriter for objects for FixedSchema
virtual void WriteMap(MapSchema schema, object value, Encoder encoder)
Serialized a map.