feat: add cbor.toJsonOptsAlloc
This commit is contained in:
parent
a738c98f33
commit
1ce0e4f709
1 changed files with 9 additions and 0 deletions
|
@ -845,6 +845,15 @@ pub fn toJsonPrettyAlloc(a: std.mem.Allocator, cbor_buf: []const u8) CborJsonErr
|
||||||
return buf.toOwnedSlice();
|
return buf.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toJsonOptsAlloc(a: std.mem.Allocator, cbor_buf: []const u8, opts: std.json.StringifyOptions) CborJsonError![]const u8 {
|
||||||
|
var buf = std.ArrayList(u8).init(a);
|
||||||
|
defer buf.deinit();
|
||||||
|
var s = json.writeStream(buf.writer(), opts);
|
||||||
|
var iter: []const u8 = cbor_buf;
|
||||||
|
try JsonStream(@TypeOf(buf)).jsonWriteValue(&s, &iter);
|
||||||
|
return buf.toOwnedSlice();
|
||||||
|
}
|
||||||
|
|
||||||
fn writeJsonValue(writer: anytype, value: json.Value) !void {
|
fn writeJsonValue(writer: anytype, value: json.Value) !void {
|
||||||
try switch (value) {
|
try switch (value) {
|
||||||
.array => |_| unreachable,
|
.array => |_| unreachable,
|
||||||
|
|
Loading…
Add table
Reference in a new issue