Kriskras99 commented on code in PR #706:
URL: https://github.com/apache/avro-rs/pull/706#discussion_r4251830256
##########
avro/src/encode.rs:
##########
@@ -107,9 +107,12 @@ pub(crate) fn encode_internal<W: Write, S: Borrow<Schema>>(
| Value::LocalTimestampMicros(i)
| Value::LocalTimestampNanos(i)
| Value::TimeMicros(i) => encode_long(*i, writer),
- Value::Float(x) => writer
- .write(&x.to_le_bytes())
- .map_err(|e| Details::WriteBytes(e).into()),
+ Value::Float(x) => match schema {
+ // AVRO-3678: Support writing float value to field defined as
double
Review Comment:
```suggestion
// Automatically resolve float to double to match `.validate()`
implementation
```
##########
avro/tests/float_under_double_schema.rs:
##########
Review Comment:
This does not need to be a separate file. Please put it directly in
`encode.rs`.
It can also be simplified to this:
```rust
#[test]
fn avro_rs_706_encode_float_with_schema_double() -> TestResult {
let schema = Schema::Double;
let value = Value::Float(0.1);
value.validate(&schema)?;
let encoded = encode_to_vec(&value, &schema)?;
assert_eq!(encoded, &[0x0, 0x0, 0x0, 0xA0, 0x99, 0x99, 0xB9, 0x3F]);
Ok(())
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]