本文整理汇总了C#中Encoder.WriteMapEnd方法的典型用法代码示例。如果您正苦于以下问题:C# Encoder.WriteMapEnd方法的具体用法?C# Encoder.WriteMapEnd怎么用?C# Encoder.WriteMapEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoder
的用法示例。
在下文中一共展示了Encoder.WriteMapEnd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncodeDefaultValue
//.........这里部分代码省略.........
enc.WriteDouble(Convert.ToDouble((int)jtok));
else if (jtok.Type == JTokenType.Float)
enc.WriteDouble(Convert.ToDouble((float)jtok));
else
throw new AvroException("Default double value " + jtok.ToString() + " is invalid, expected is json number.");
break;
case Schema.Type.Bytes:
if (jtok.Type != JTokenType.String)
throw new AvroException("Default bytes value " + jtok.ToString() + " is invalid, expected is json string.");
var en = System.Text.Encoding.GetEncoding("iso-8859-1");
enc.WriteBytes(en.GetBytes((string)jtok));
break;
case Schema.Type.Fixed:
if (jtok.Type != JTokenType.String)
throw new AvroException("Default fixed value " + jtok.ToString() + " is invalid, expected is json string.");
en = System.Text.Encoding.GetEncoding("iso-8859-1");
int len = (schema as FixedSchema).Size;
byte[] bb = en.GetBytes((string)jtok);
if (bb.Length != len)
throw new AvroException("Default fixed value " + jtok.ToString() + " is not of expected length " + len);
enc.WriteFixed(bb);
break;
case Schema.Type.String:
if (jtok.Type != JTokenType.String)
throw new AvroException("Default string value " + jtok.ToString() + " is invalid, expected is json string.");
enc.WriteString((string)jtok);
break;
case Schema.Type.Enumeration:
if (jtok.Type != JTokenType.String)
throw new AvroException("Default enum value " + jtok.ToString() + " is invalid, expected is json string.");
enc.WriteEnum((schema as EnumSchema).Ordinal((string)jtok));
break;
case Schema.Type.Null:
if (jtok.Type != JTokenType.Null)
throw new AvroException("Default null value " + jtok.ToString() + " is invalid, expected is json null.");
enc.WriteNull();
break;
case Schema.Type.Array:
if (jtok.Type != JTokenType.Array)
throw new AvroException("Default array value " + jtok.ToString() + " is invalid, expected is json array.");
JArray jarr = jtok as JArray;
enc.WriteArrayStart();
enc.SetItemCount(jarr.Count);
foreach (JToken jitem in jarr)
{
enc.StartItem();
EncodeDefaultValue(enc, (schema as ArraySchema).ItemSchema, jitem);
}
enc.WriteArrayEnd();
break;
case Schema.Type.Record:
case Schema.Type.Error:
if (jtok.Type != JTokenType.Object)
throw new AvroException("Default record value " + jtok.ToString() + " is invalid, expected is json object.");
RecordSchema rcs = schema as RecordSchema;
JObject jo = jtok as JObject;
foreach (Field field in rcs)
{
JToken val = jo[field.Name];
if (null == val)
val = field.DefaultValue;
if (null == val)
throw new AvroException("No default value for field " + field.Name);
EncodeDefaultValue(enc, field.Schema, val);
}
break;
case Schema.Type.Map:
if (jtok.Type != JTokenType.Object)
throw new AvroException("Default map value " + jtok.ToString() + " is invalid, expected is json object.");
jo = jtok as JObject;
enc.WriteMapStart();
enc.SetItemCount(jo.Count);
foreach (KeyValuePair<string, JToken> jp in jo)
{
enc.StartItem();
enc.WriteString(jp.Key);
EncodeDefaultValue(enc, (schema as MapSchema).ValueSchema, jp.Value);
}
enc.WriteMapEnd();
break;
case Schema.Type.Union:
enc.WriteUnionIndex(0);
EncodeDefaultValue(enc, (schema as UnionSchema).Schemas[0], jtok);
break;
default:
throw new AvroException("Unsupported schema type " + schema.Tag);
}
}