MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / serialize_sequence

Function serialize_sequence

std/json/src/main/serializer.rs:114–136  ·  view source on GitHub ↗
(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize)

Source from the content-addressed store, hash-verified

112}
113
114fn serialize_sequence(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize) -> Result<()> {
115 if ctx.opts.check_circular && depth >= MAX_DEPTH {
116 return Err(Error::Value("Circular reference detected".into()));
117 }
118 out.push('[');
119 let it = value.iter()?;
120 let n = it.len()?;
121 if n == 0 {
122 out.push(']');
123 return Ok(());
124 }
125 let indent_str = ctx.opts.indent.map(|n| " ".repeat(n.max(0) as usize));
126 for i in 0..n {
127 let idx = encode(Value::Int(i as i128))?;
128 let item = it.get_item(&idx)?;
129 if i > 0 { out.push_str(&ctx.opts.item_sep); }
130 write_indent(out, indent_str.as_deref(), depth + 1);
131 serialize_into(&item, out, ctx, depth + 1)?;
132 }
133 write_indent(out, indent_str.as_deref(), depth);
134 out.push(']');
135 Ok(())
136}
137
138fn serialize_object(value: &Handle, out: &mut String, ctx: &mut SerCtx, depth: usize) -> Result<()> {
139 if ctx.opts.check_circular && depth >= MAX_DEPTH {

Callers 1

serialize_intoFunction · 0.85

Calls 9

write_indentFunction · 0.85
serialize_intoFunction · 0.85
pushMethod · 0.80
ValueEnum · 0.50
encodeFunction · 0.50
iterMethod · 0.45
lenMethod · 0.45
repeatMethod · 0.45
get_itemMethod · 0.45

Tested by

no test coverage detected