Exemple #1
0
        internal Encoder.WriteItem Resolve(TimestampMillisecondsSchema schema)
        {
            return((value, encoder) =>
            {
                if (!(schema.BaseTypeSchema is LongSchema))
                {
                    throw new AvroTypeMismatchException($"[TimestampMilliseconds] required to write against [long] of [Long] schema but found [{schema.BaseTypeSchema}]");
                }

                var bytesValue = (long)schema.ConvertToBaseValue(value, schema);
                encoder.WriteLong(bytesValue);
            });
        }
Exemple #2
0
        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);
        }