Skip to content

Commit

Permalink
Fix f32 and f64 encoding/decoding (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Cloud authored Apr 1, 2020
1 parent 0bcb437 commit 3336bd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub fn decode<R: Read>(schema: &Schema, reader: &mut R) -> Result<Value, Error>
Schema::Int => decode_int(reader),
Schema::Long => decode_long(reader),
Schema::Float => {
let mut buf = [0u8; 4];
let mut buf = [0u8; std::mem::size_of::<f32>()];
reader.read_exact(&mut buf[..])?;
Ok(Value::Float(f32::from_ne_bytes(buf)))
Ok(Value::Float(f32::from_le_bytes(buf)))
}
Schema::Double => {
let mut buf = [0u8; 8];
let mut buf = [0u8; std::mem::size_of::<f64>()];
reader.read_exact(&mut buf[..])?;
Ok(Value::Double(f64::from_ne_bytes(buf)))
Ok(Value::Double(f64::from_le_bytes(buf)))
}
Schema::Bytes => {
let len = decode_len(reader)?;
Expand Down
4 changes: 2 additions & 2 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn encode_ref(value: &Value, schema: &Schema, buffer: &mut Vec<u8>) {
Value::Boolean(b) => buffer.push(if *b { 1u8 } else { 0u8 }),
Value::Int(i) => encode_int(*i, buffer),
Value::Long(i) => encode_long(*i, buffer),
Value::Float(x) => buffer.extend_from_slice(&x.to_ne_bytes()),
Value::Double(x) => buffer.extend_from_slice(&x.to_ne_bytes()),
Value::Float(x) => buffer.extend_from_slice(&x.to_le_bytes()),
Value::Double(x) => buffer.extend_from_slice(&x.to_le_bytes()),
Value::Bytes(bytes) => encode_bytes(bytes, buffer),
Value::String(s) => match *schema {
Schema::String => {
Expand Down

0 comments on commit 3336bd1

Please sign in to comment.