internal Encoder.WriteItem Resolve(UuidSchema schema) { return((value, encoder) => { if (!(value is Guid)) { throw new AvroTypeMismatchException($"[Uuid] required to write against [Guid] of [string] schema but found [{value.GetType()}]"); } encoder.WriteString(((Guid)value).ToString()); }); }
private TypeSchema ParseLogicalType(JObject token, NamedSchema parent, Dictionary <string, NamedSchema> namedSchemas, string logicalType) { TypeSchema result; switch (logicalType) { case LogicalTypeSchema.LogicalTypeEnum.Uuid: result = new UuidSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.Decimal: var scale = token.OptionalProperty <int>(nameof(DecimalSchema.Scale).ToLower()); var precision = token.RequiredProperty <int>(nameof(DecimalSchema.Precision).ToLower()); result = new DecimalSchema(typeof(decimal), precision, scale); break; case LogicalTypeSchema.LogicalTypeEnum.Duration: result = new DurationSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.TimestampMilliseconds: result = new TimestampMillisecondsSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.TimestampMicroseconds: result = new TimestampMicrosecondsSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.TimeMilliseconds: result = new TimeMillisecondsSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.TimeMicrosecond: result = new TimeMicrosecondsSchema(); break; case LogicalTypeSchema.LogicalTypeEnum.Date: result = new DateSchema(); break; default: throw new SerializationException( string.Format(CultureInfo.InvariantCulture, "Unknown LogicalType schema :'{0}'.", logicalType)); } return(result); }
private static AvroSchema ParseUuidSchema(JToken jToken, IDictionary <string, NamedSchema> namedTypes, Stack <string> enclosingNamespace) { var keys = new HashSet <string>() { "logicalType", "type" }; JsonUtil.AssertKeys(jToken, keys, null, out var tags); JsonUtil.AssertValue(jToken, "logicalType", "uuid"); var type = JsonUtil.GetValue <JToken>(jToken, "type"); var underlyingType = ParseSchema(type, namedTypes, enclosingNamespace); var uuidSchema = new UuidSchema(underlyingType); uuidSchema.AddTags(tags); return(uuidSchema); }