Move JSON byte counting into codex-utils-string (#61465)

Export `serialized_json_bytes` from `codex-utils-string` and update core callers to use the shared helper. Preserve byte counting without retaining the serialized output.

GitOrigin-RevId: 9c75b05592d3171b9a0d54517f8f3a4281fde987
This commit is contained in:
Ruslan Nigmatullin
2026-11-14 05:00:21 +00:00
committed by copyberry
parent ecf54824c6
commit 336b19ab26
7 changed files with 26 additions and 27 deletions
-22
View File
@@ -1,22 +0,0 @@
#[derive(Default)]
struct JsonByteCounter(usize);
impl std::io::Write for JsonByteCounter {
fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
self.0 = self.0.saturating_add(bytes.len());
Ok(bytes.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
/// Counts serialized JSON bytes without retaining the serialized output.
pub(crate) fn serialized_json_bytes<T: serde::Serialize + ?Sized>(
value: &T,
) -> serde_json::Result<usize> {
let mut counter = JsonByteCounter::default();
serde_json::to_writer(&mut counter, value)?;
Ok(counter.0)
}
-1
View File
@@ -1,2 +1 @@
pub(crate) mod json;
pub mod path_utils;