Skip to main content

reifydb_codec/json/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4pub mod fixture;
5pub mod from;
6pub mod to;
7pub mod types;
8pub mod wire_type;
9
10pub const NONE_MARKER: &str = "⟪none⟫";
11
12const EXCERPT_CHARS: usize = 64;
13
14pub fn excerpt(text: &str) -> String {
15	match text.char_indices().nth(EXCERPT_CHARS) {
16		Some((cut, _)) => format!("{}...", &text[..cut]),
17		None => text.to_string(),
18	}
19}
20
21fn marker_parts() -> (&'static str, &'static str) {
22	let (close_at, _) = NONE_MARKER.char_indices().last().expect("none marker is not empty");
23	NONE_MARKER.split_at(close_at)
24}
25
26pub fn none_marker(wrapped: u32) -> String {
27	if wrapped == 0 {
28		return NONE_MARKER.to_string();
29	}
30	let (open, close) = marker_parts();
31	format!("{open}:{wrapped}{close}")
32}
33
34pub fn none_marker_depth(payload: &str) -> Option<u32> {
35	if payload == NONE_MARKER {
36		return Some(0);
37	}
38	let (open, close) = marker_parts();
39	let wrapped = payload.strip_prefix(open)?.strip_suffix(close)?.strip_prefix(':')?;
40	wrapped.parse::<u32>().ok().filter(|k| *k >= 1)
41}