19 using System.Collections.Generic;
20 using Newtonsoft.Json.Linq;
21 using Newtonsoft.Json;
35 if (
null == jtok)
return;
40 if (jtok.Type != JTokenType.Boolean)
41 throw new AvroException(
"Default boolean value " + jtok.ToString() +
" is invalid, expected is json boolean.");
46 if (jtok.Type != JTokenType.Integer)
47 throw new AvroException(
"Default int value " + jtok.ToString() +
" is invalid, expected is json integer.");
48 enc.
WriteInt(Convert.ToInt32((
int)jtok));
52 if (jtok.Type != JTokenType.Integer)
53 throw new AvroException(
"Default long value " + jtok.ToString() +
" is invalid, expected is json integer.");
54 enc.
WriteLong(Convert.ToInt64((
long)jtok));
58 if (jtok.Type != JTokenType.Float)
59 throw new AvroException(
"Default float value " + jtok.ToString() +
" is invalid, expected is json number.");
64 if (jtok.Type == JTokenType.Integer)
66 else if (jtok.Type == JTokenType.Float)
69 throw new AvroException(
"Default double value " + jtok.ToString() +
" is invalid, expected is json number.");
74 if (jtok.Type != JTokenType.String)
75 throw new AvroException(
"Default bytes value " + jtok.ToString() +
" is invalid, expected is json string.");
76 var en = System.Text.Encoding.GetEncoding(
"iso-8859-1");
81 if (jtok.Type != JTokenType.String)
82 throw new AvroException(
"Default fixed value " + jtok.ToString() +
" is invalid, expected is json string.");
83 en = System.Text.Encoding.GetEncoding(
"iso-8859-1");
85 byte[] bb = en.GetBytes((
string)jtok);
87 throw new AvroException(
"Default fixed value " + jtok.ToString() +
" is not of expected length " + len);
92 if (jtok.Type != JTokenType.String)
93 throw new AvroException(
"Default string value " + jtok.ToString() +
" is invalid, expected is json string.");
98 if (jtok.Type != JTokenType.String)
99 throw new AvroException(
"Default enum value " + jtok.ToString() +
" is invalid, expected is json string.");
104 if (jtok.Type != JTokenType.Null)
105 throw new AvroException(
"Default null value " + jtok.ToString() +
" is invalid, expected is json null.");
110 if (jtok.Type != JTokenType.Array)
111 throw new AvroException(
"Default array value " + jtok.ToString() +
" is invalid, expected is json array.");
112 JArray jarr = jtok as JArray;
115 foreach (JToken jitem
in jarr)
125 if (jtok.Type != JTokenType.Object)
126 throw new AvroException(
"Default record value " + jtok.ToString() +
" is invalid, expected is json object.");
128 JObject jo = jtok as JObject;
129 foreach (
Field field
in rcs)
131 JToken val = jo[field.
Name];
142 if (jtok.Type != JTokenType.Object)
143 throw new AvroException(
"Default map value " + jtok.ToString() +
" is invalid, expected is json object.");
144 jo = jtok as JObject;
147 foreach (KeyValuePair<string, JToken> jp
in jo)
Schema Schema
Field type's schema
Class for fields defined in a record
void WriteBytes(byte[] value)
Class for enum type schemas
void WriteDouble(double value)
Base class for all schema types
void SetItemCount(long value)
void WriteLong(long value)
readonly string Name
Name of the field.
Type
Enum for schema types
void WriteBoolean(bool value)
void WriteEnum(int value)
void WriteFixed(byte[] data)
void WriteFloat(float value)
Class for array type schemas
static void EncodeDefaultValue(Encoder enc, Schema schema, JToken jtok)
Reads the passed JToken default value field and writes it in the specified encoder
JToken DefaultValue
The default value for the field stored as JSON object, if defined.
void WriteUnionIndex(int value)
void WriteString(string value)
Type Tag
Schema type property