Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions crates/ladybug-contract/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ mod cogrecord_serde {
pub fn serialize<S: Serializer>(record: &CogRecord, serializer: S) -> Result<S::Ok, S::Error> {
let mut s = serializer.serialize_struct("CogRecord", 2)?;
s.serialize_field("meta", &record.meta.words.as_slice())?;
let content_words: Vec<&[u64]> =
record.content.iter().map(|c| c.words.as_slice()).collect();
s.serialize_field("content", &content_words)?;
s.serialize_field("content", &record.content.words.as_slice())?;
s.end()
}

pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<CogRecord, D::Error> {
#[derive(Deserialize)]
struct Raw {
meta: Vec<u64>,
content: Vec<Vec<u64>>,
content: Vec<u64>,
}

let raw = Raw::deserialize(deserializer)?;
Expand All @@ -60,17 +58,10 @@ mod cogrecord_serde {
meta.words[i] = w;
}

let content = raw
.content
.iter()
.map(|words| {
let mut c = Container::zero();
for (i, &w) in words.iter().take(CONTAINER_WORDS).enumerate() {
c.words[i] = w;
}
c
})
.collect();
let mut content = Container::zero();
for (i, &w) in raw.content.iter().take(CONTAINER_WORDS).enumerate() {
content.words[i] = w;
}

Ok(CogRecord { meta, content })
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ladybug-contract/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl From<&V1UnifiedStep> for CogRecord {
"reasoning": step.reasoning,
});
let bytes = serde_json::to_vec(&json).unwrap_or_default();
record.content[0] = content_from_bytes(&bytes);
record.content = content_from_bytes(&bytes);

record
}
Expand Down Expand Up @@ -281,7 +281,7 @@ impl From<&V1DataEnvelope> for CogRecord {
// serde envelope until container format is upgraded).
}
let bytes = serde_json::to_vec(&envelope.data).unwrap_or_default();
record.content[0] = content_from_bytes(&bytes);
record.content = content_from_bytes(&bytes);
record
}
}
Expand Down Expand Up @@ -337,7 +337,7 @@ impl From<&V1LadybugEnvelope> for CogRecord {
}
}
let bytes = serde_json::to_vec(&envelope.content).unwrap_or_default();
record.content[0] = content_from_bytes(&bytes);
record.content = content_from_bytes(&bytes);
record
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/ladybug-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//! | [`delegation`] | `DelegationRequest` / `DelegationResponse` |
//! | [`wire`] | Binary wire protocol: `CogPacket` (8+8/4096 command packets, no JSON) |
//! | [`legacy`] | V1 JSON backward compatibility (external wire format only) |
//! | [`schema`] | Unified 2×8192 CogRecord schema constants and field descriptors |

pub mod container;
pub mod geometry;
Expand All @@ -47,6 +48,7 @@ pub mod temporal;
pub mod delegation;
pub mod legacy;
pub mod wire;
pub mod schema;

// === Convenience re-exports ===
pub use container::{Container, CONTAINER_BITS, CONTAINER_BYTES, CONTAINER_WORDS};
Expand Down
Loading
Loading