Skip to content

Commit 0ac27f3

Browse files
committed
Add le/be float read/write methods
1 parent b3c34ae commit 0ac27f3

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

Diff for: CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to `parsenic` will be documented in this file.
44
The format is based on [Keep a Changelog], and this project adheres to
55
[Semantic Versioning].
66

7+
## [0.2.1] - 2024-11-16
8+
9+
### Added
10+
11+
- `le::Read::f32()`
12+
- `le::Read::f64()`
13+
- `le::Write::f32()`
14+
- `le::Write::f64()`
15+
- `be::Read::f32()`
16+
- `be::Read::f64()`
17+
- `be::Write::f32()`
18+
- `be::Write::f64()`
19+
720
## [0.2.0] - 2024-11-05
821

922
### Added

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "parsenic"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55
license = "Apache-2.0 OR BSL-1.0 OR MIT"
66
description = "A simple no-std/no-alloc I/O and parsing crate"

Diff for: src/be/read.rs

+10
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ pub trait Read: crate::Read {
4444
fn i128(&mut self) -> LenResult<i128> {
4545
Ok(i128::from_be_bytes(self.array()?))
4646
}
47+
48+
/// Read the next big endian `f32`
49+
fn f32(&mut self) -> LenResult<f32> {
50+
Ok(f32::from_be_bytes(self.array()?))
51+
}
52+
53+
/// Read the next big endian `f64`
54+
fn f64(&mut self) -> LenResult<f64> {
55+
Ok(f64::from_be_bytes(self.array()?))
56+
}
4757
}

Diff for: src/be/write.rs

+10
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ pub trait Write: crate::Write {
4444
fn i128(&mut self, int: i128) -> FullResult {
4545
self.bytes(int.to_be_bytes())
4646
}
47+
48+
/// Write out a big endian encoded 32-bit float.
49+
fn f32(&mut self, float: f32) -> FullResult {
50+
self.bytes(float.to_be_bytes())
51+
}
52+
53+
/// Write out a big endian encoded 64-bit float.
54+
fn f64(&mut self, float: f64) -> FullResult {
55+
self.bytes(float.to_be_bytes())
56+
}
4757
}

Diff for: src/le/read.rs

+10
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ pub trait Read: crate::Read {
4444
fn i128(&mut self) -> LenResult<i128> {
4545
Ok(i128::from_le_bytes(self.array()?))
4646
}
47+
48+
/// Read the next little endian `f32`
49+
fn f32(&mut self) -> LenResult<f32> {
50+
Ok(f32::from_le_bytes(self.array()?))
51+
}
52+
53+
/// Read the next little endian `f64`
54+
fn f64(&mut self) -> LenResult<f64> {
55+
Ok(f64::from_le_bytes(self.array()?))
56+
}
4757
}

Diff for: src/le/write.rs

+10
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ pub trait Write: crate::Write {
4444
fn i128(&mut self, int: i128) -> FullResult {
4545
self.bytes(int.to_le_bytes())
4646
}
47+
48+
/// Write out a little endian encoded 32-bit float.
49+
fn f32(&mut self, float: f32) -> FullResult {
50+
self.bytes(float.to_le_bytes())
51+
}
52+
53+
/// Write out a little endian encoded 64-bit float.
54+
fn f64(&mut self, float: f64) -> FullResult {
55+
self.bytes(float.to_le_bytes())
56+
}
4757
}

0 commit comments

Comments
 (0)