Skip to content

Commit 8e29374

Browse files
badicsalexclaude
andcommitted
codec: replace codec! with a Codec derive (SFT-8112)
The derive is meant for keyos IPC, so by default it prefixes structs and enum variants with their length, which lets old and new versions of a type decode each other. QuantumLink's own wire types use it frozen, which keeps the codec! layout byte for byte. Decode no longer abstracts over the byte container. The borrowed form points into a &[u8] instead, and the frame parser slices stream payloads out of the record's Bytes itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4cdc788 commit 8e29374

44 files changed

Lines changed: 2398 additions & 789 deletions

Some content is hidden

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

‎Cargo.lock‎

Lines changed: 11 additions & 0 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33
members = [
44
"btp",
55
"codec",
6+
"codec/macro",
67
"common",
78
"keyos",
89
"router",
@@ -21,7 +22,8 @@ license = "MIT OR Apache-2.0"
2122
bytes = "1.11.1"
2223

2324
# workspace crates
24-
ql-codec = { path = "codec" }
25+
ql-codec = { path = "codec", features = ["derive"] }
26+
ql-codec-macro = { path = "codec/macro" }
2527
ql-common = { path = "common" }
2628
ql-fsm = { path = "fsm" }
2729
ql-keyos = { path = "keyos" }

‎btp/src/lib.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ pub fn packet_version(data: &[u8]) -> Option<Version> {
3737
}
3838
}
3939

40-
ql_codec::codec! {
41-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42-
struct Header {
43-
sequence: u16,
44-
index: u16,
45-
tagged_record_len: u32,
46-
}
40+
#[derive(Debug, Clone, Copy, PartialEq, Eq, ql_codec::Codec)]
41+
#[codec(frozen)]
42+
struct Header {
43+
sequence: u16,
44+
index: u16,
45+
tagged_record_len: u32,
4746
}

‎codec/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ license.workspace = true
77

88
[dependencies]
99
bytes = { workspace = true }
10+
ql-codec-macro = { workspace = true, optional = true }
11+
12+
[features]
13+
derive = ["dep:ql-codec-macro"]

‎codec/macro/Cargo.toml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "ql-codec-macro"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "QuantumLink codec derive"
6+
license.workspace = true
7+
8+
[lib]
9+
proc-macro = true
10+
11+
[dependencies]
12+
proc-macro2 = "1.0.101"
13+
quote = "1.0.40"
14+
syn = { version = "2.0.106", default-features = false, features = [
15+
"clone-impls",
16+
"derive",
17+
"parsing",
18+
"printing",
19+
"proc-macro",
20+
] }
21+
22+
[dev-dependencies]
23+
ql-codec = { workspace = true, features = ["derive"] }

0 commit comments

Comments
 (0)