checkValueDepth
Function parameters
Parameters
- val:anytype
- depth:usize
Type definitions in this namespace
Types
- ContainerOptions
- Options for manual serialization of container types.
- ValueOptions
- Options for serialization of an individual value.
- EmitCodepointLiterals
- Determines when to emit Unicode code point literals as opposed to integer literals.
- MultilineStringOptions
- Options for formatting multiline strings.
- Tuple
- Writes ZON tuples field by field.
- Struct
- Writes ZON structs field by field.
Serialize a value, similar to `serialize`.
Functions
- value
- Serialize a value, similar to `serialize`.
- valueMaxDepth
- Serialize a value, similar to `serializeMaxDepth`.
- valueArbitraryDepth
- Serialize a value, similar to `serializeArbitraryDepth`.
- int
- Serialize an integer.
- float
- Serialize a float.
- ident
- Serialize `name` as an identifier prefixed with `.`.
- codePoint
- Serialize `val` as a Unicode codepoint.
- tuple
- Like `value`, but always serializes `val` as a tuple.
- tupleMaxDepth
- Like `tuple`, but recursive types are allowed.
- tupleArbitraryDepth
- Like `tuple`, but recursive types are allowed.
- string
- Like `value`, but always serializes `val` as a string.
- multilineString
- Like `value`, but always serializes to a multiline string literal.
- beginStruct
- Create a `Struct` for writing ZON structs field by field.
- beginTuple
- Creates a `Tuple` for writing ZON tuples field by field.
Error sets in this namespace
Error Sets
Source
Implementation
fn checkValueDepth(val: anytype, depth: usize) error{ExceededMaxDepth}!void {
if (depth == 0) return error.ExceededMaxDepth;
const child_depth = depth - 1;
switch (@typeInfo(@TypeOf(val))) {
.pointer => |pointer| switch (pointer.size) {
.one => try checkValueDepth(val.*, child_depth),
.slice => for (val) |item| {
try checkValueDepth(item, child_depth);
},
.c, .many => {},
},
.array => for (val) |item| {
try checkValueDepth(item, child_depth);
},
.@"struct" => |@"struct"| inline for (@"struct".fields) |field_info| {
try checkValueDepth(@field(val, field_info.name), child_depth);
},
.@"union" => |@"union"| if (@"union".tag_type == null) {
return;
} else switch (val) {
inline else => |payload| {
return checkValueDepth(payload, child_depth);
},
},
.optional => if (val) |inner| try checkValueDepth(inner, child_depth),
else => {},
}
}