Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions crates/formats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tlsn-core = { workspace = true }

bytes = { workspace = true }
spansy = { workspace = true, features = ["serde"] }
rangeset = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
Expand Down
23 changes: 15 additions & 8 deletions crates/formats/src/json/commit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::error::Error;

use spansy::{json::KeyValue, Spanned};
use rangeset::{ RangeSet, Intersection, Difference, ToRangeSet };
use tlsn_core::transcript::{Direction, TranscriptCommitConfigBuilder};

use crate::json::{Array, Bool, JsonValue, Null, Number, Object, String as JsonString};
Expand Down Expand Up @@ -150,15 +151,21 @@ pub trait JsonCommit {
.map_err(|e| JsonCommitError::new_with_source("failed to commit array", e))?;

if !array.elems.is_empty() {
builder
.commit(&array.without_values(), direction)
.map_err(|e| {
JsonCommitError::new_with_source("failed to commit array excluding values", e)
})?;
}
let array_range: RangeSet<usize> = array.to_range_set();
let elem_ranges: Vec<RangeSet<usize>> = array.elems.iter().map(|e| e.to_range_set()).collect();
let elem_ranges = elem_ranges.iter()
.fold(array_range.clone(), |acc, range| acc.intersection(range));

// Commit to the parts of the array that are not elements.
let difference = array_range.difference(&elem_ranges);
for range in difference.iter_ranges() {
builder.commit(&range, direction).map_err(|e| JsonCommitError::new_with_source("failed to commit array element", e))?;
}

// TODO: Commit each value separately, but we need a strategy for handling
// separators.
for elem in &array.elems {
self.commit_value(builder, elem, direction)?;
}
}

Ok(())
}
Expand Down
Loading