Skip to content

Commit 9e2099e

Browse files
committed
Merge remote-tracking branch 'origin/main' into danlaine/contiguous-2
2 parents 630254d + 52f31c8 commit 9e2099e

168 files changed

Lines changed: 2831 additions & 1627 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/benchmark.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
cargo_flags: ""
5353
file_suffix: ""
5454
benchmark_name: "commonware-coding"
55+
- package: commonware-formatting
56+
cargo_flags: ""
57+
file_suffix: ""
58+
benchmark_name: "commonware-formatting"
5559
- package: commonware-utils
5660
cargo_flags: ""
5761
file_suffix: ""

.github/workflows/publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
continue-on-error: true
2626
env:
2727
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
28+
- name: Publish formatting
29+
run: cargo publish --manifest-path formatting/Cargo.toml
30+
continue-on-error: true
31+
env:
32+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2833
- name: Publish conformance-macros
2934
run: cargo publish --manifest-path conformance/macros/Cargo.toml
3035
continue-on-error: true

Cargo.lock

Lines changed: 38 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"consensus",
1010
"cryptography",
1111
"deployer",
12+
"formatting",
1213
"macros",
1314
"macros/impl",
1415
"math",
@@ -97,6 +98,7 @@ commonware-conformance-macros = { version = "2026.4.0", path = "conformance/macr
9798
commonware-consensus = { version = "2026.4.0", path = "consensus" }
9899
commonware-cryptography = { version = "2026.4.0", path = "cryptography", default-features = false }
99100
commonware-deployer = { version = "2026.4.0", path = "deployer", default-features = false }
101+
commonware-formatting = { version = "2026.4.0", path = "formatting", default-features = false }
100102
commonware-invariants = { version = "2026.4.0", path = "invariants" }
101103
commonware-macros = { version = "2026.4.0", path = "macros", default-features = false }
102104
commonware-macros-impl = { version = "2026.4.0", path = "macros/impl" }
@@ -110,6 +112,7 @@ commonware-storage = { version = "2026.4.0", path = "storage", default-features
110112
commonware-stream = { version = "2026.4.0", path = "stream" }
111113
commonware-utils = { version = "2026.4.0", path = "utils", default-features = false }
112114
console-subscriber = "0.5.0"
115+
const-hex = { version = "1.18.1", default-features = false }
113116
crc = "3.4.0"
114117
crc-fast = { version = "1.10.0", default-features = false }
115118
criterion = "0.7.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ _Sometimes, we opt to maintain software that is neither a primitive nor an examp
4848

4949
* [docs](./docs): Access information about Commonware at https://commonware.xyz.
5050
* [docker](./docker): Dockerfiles used for cross-compilation and CI.
51+
* [formatting](./formatting/README.md): Format and parse encoded data.
5152
* [invariants](./invariants/README.md): Define and exercise invariants.
5253
* [macros](./macros/README.md): Augment the development of primitives with procedural macros.
5354
* [mcp](./mcp/README.md): Interact with the Commonware Library via MCP at https://mcp.commonware.xyz.

codec/src/types/lazy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<T: Read> Lazy<T> {
106106
}
107107
} else {
108108
Self {
109-
value: T::decode_cfg(bytes.clone(), &cfg).ok(),
109+
value: T::decode_cfg(bytes.as_ref(), &cfg).ok(),
110110
pending: Some(Pending { bytes, cfg }),
111111
}
112112
}
@@ -130,7 +130,7 @@ impl<T: Read> Lazy<T> {
130130
.pending
131131
.as_ref()
132132
.expect("Lazy should have pending if value is not initialized");
133-
T::decode_cfg(bytes.clone(), cfg).ok()
133+
T::decode_cfg(bytes.as_ref(), cfg).ok()
134134
})
135135
.as_ref()
136136
} else {

conformance/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workspace = true
1414

1515
[dependencies]
1616
commonware-conformance-macros.workspace = true
17+
commonware-formatting.workspace = true
1718
commonware-macros.workspace = true
1819
futures.workspace = true
1920
serde = { workspace = true, features = ["derive"] }

conformance/src/lib.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,6 @@ impl ConformanceFile {
143143
}
144144
}
145145

146-
/// Encode bytes as a lowercase hex string.
147-
fn hex_encode(bytes: &[u8]) -> String {
148-
const HEX_CHARS: &[u8; 16] = b"0123456789abcdef";
149-
let mut result = String::with_capacity(bytes.len() * 2);
150-
for &byte in bytes {
151-
result.push(HEX_CHARS[(byte >> 4) as usize] as char);
152-
result.push(HEX_CHARS[(byte & 0x0f) as usize] as char);
153-
}
154-
result
155-
}
156-
157146
/// Acquire an exclusive lock on the conformance file.
158147
///
159148
/// Uses OS-level file locking which is automatically released when the
@@ -188,7 +177,7 @@ pub async fn compute_conformance_hash<C: Conformance>(n_cases: usize) -> String
188177
hasher.update(&committed);
189178
}
190179

191-
hex_encode(&hasher.finalize())
180+
commonware_formatting::hex(&hasher.finalize())
192181
}
193182

194183
/// Run conformance tests using the [`Conformance`] trait.
@@ -341,14 +330,6 @@ async fn regenerate_conformance<C: Conformance>(type_name: &str, n_cases: usize,
341330
mod tests {
342331
use super::*;
343332

344-
#[test]
345-
fn test_hex_encode() {
346-
assert_eq!(hex_encode(&[]), "");
347-
assert_eq!(hex_encode(&[0x00]), "00");
348-
assert_eq!(hex_encode(&[0xff]), "ff");
349-
assert_eq!(hex_encode(&[0x12, 0x34, 0xab, 0xcd]), "1234abcd");
350-
}
351-
352333
// Test conformance trait with a simple implementation
353334
struct SimpleConformance;
354335

consensus/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ commonware-broadcast.workspace = true
2121
commonware-codec.workspace = true
2222
commonware-coding.workspace = true
2323
commonware-cryptography.workspace = true
24+
commonware-formatting.workspace = true
2425
commonware-macros.workspace = true
2526
commonware-math.workspace = true
2627
commonware-parallel.workspace = true

consensus/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,13 @@ commonware_macros::stability_scope!(ALPHA {
848848

849849
impl core::fmt::Display for Commitment {
850850
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
851-
write!(f, "{}", commonware_utils::hex(self.as_ref()))
851+
write!(f, "{}", commonware_formatting::Hex(self.as_ref()))
852852
}
853853
}
854854

855855
impl core::fmt::Debug for Commitment {
856856
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
857-
write!(f, "{}", commonware_utils::hex(self.as_ref()))
857+
write!(f, "{}", commonware_formatting::Hex(self.as_ref()))
858858
}
859859
}
860860

@@ -1737,13 +1737,13 @@ mod tests {
17371737

17381738
impl core::fmt::Display for Digest {
17391739
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1740-
write!(f, "{}", commonware_utils::hex(self.as_ref()))
1740+
write!(f, "{}", commonware_formatting::Hex(self.as_ref()))
17411741
}
17421742
}
17431743

17441744
impl core::fmt::Debug for Digest {
17451745
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1746-
write!(f, "Digest({})", commonware_utils::hex(self.as_ref()))
1746+
write!(f, "Digest({})", commonware_formatting::Hex(self.as_ref()))
17471747
}
17481748
}
17491749

0 commit comments

Comments
 (0)