pub struct Entry {
pub now: i64,
/* private fields */
}Expand description
A stored entry preserving bit-perfect JSON bytes.
CRITICAL INVARIANT: The original JSON string is preserved exactly as received.
This ensures correct czd computation, which hashes the exact bytes of pay.
§The Re-serialization Trap
A naive approach would parse JSON into serde_json::Value, then re-serialize
for czd computation. This breaks signatures because re-serialization can change:
- Field ordering
- Whitespace
- Number representation (e.g.,
1.0→1)
By storing Box<RawValue>, we preserve the original bytes and extract pay
from the same source, ensuring bit-perfect fidelity.
Fields§
§now: i64The now timestamp extracted from pay.now (for filtering).
Implementations§
Source§impl Entry
impl Entry
Sourcepub fn from_json(json: String) -> Result<Self, EntryError>
pub fn from_json(json: String) -> Result<Self, EntryError>
Create an entry from a raw JSON string.
This is the primary constructor for entries loaded from storage. The original bytes are preserved exactly.
§Errors
Returns EntryError::InvalidJson if the string is not valid JSON.
Returns EntryError::MissingNow if pay.now is missing or not an integer.
Sourcepub fn from_raw_value(raw: Box<RawValue>) -> Result<Self, EntryError>
pub fn from_raw_value(raw: Box<RawValue>) -> Result<Self, EntryError>
Create an entry from an owned RawValue.
Useful when deserializing from a format that already provides RawValue.
Sourcepub fn from_value(value: &Value) -> Result<Self, EntryError>
pub fn from_value(value: &Value) -> Result<Self, EntryError>
Create an entry from a serde_json::Value.
Warning: This serializes the Value, which may not preserve original byte ordering. Use only when creating new entries (e.g., during export), not when loading from storage.
Sourcepub fn raw_json(&self) -> &str
pub fn raw_json(&self) -> &str
Get the raw JSON string.
This returns the exact bytes stored, suitable for I/O operations.
Sourcepub fn as_value(&self) -> Result<Value, EntryError>
pub fn as_value(&self) -> Result<Value, EntryError>
Parse the entry as a serde_json::Value.
Use this for field access (e.g., extracting typ, key).
Do NOT use the resulting Value for czd computation - use pay_bytes() instead.
Sourcepub fn pay_bytes(&self) -> Result<Vec<u8>, EntryError>
pub fn pay_bytes(&self) -> Result<Vec<u8>, EntryError>
Extract the pay field as raw bytes, preserving exact byte sequence.
This is the critical method for czd computation. It extracts the pay
field from the original JSON, preserving exact bytes including whitespace
and field ordering.
§Implementation Note
We parse the raw JSON into a structure with RawValue for the pay field, then return those bytes. This ensures we’re extracting from the preserved original, not re-serializing.