public virtual void TestSchemaEncodeDecodeFidelity() { var schema = DateSchema.Of(); var date = DateTime.UtcNow; var bytes = schema.Encode(date); Assert.Equal(date.ToString("yyyy-MM-ddTHH:mm:ss"), schema.Decode(bytes).ToString("yyyy-MM-ddTHH:mm:ss")); }
public virtual void TestSchemaEncode() { var schema = DateSchema.Of(); var data = DateTime.Now; var ms = data.ConvertToMsTimestamp().LongToBigEndian(); var expected = BitConverter.GetBytes(ms); Assert.Equal(expected, schema.Encode(data)); }
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); }