zellzig/src/deserialization_blocks/bytearray.zig

43 lines
1001 B
Zig

const std = @import("std");
const getty = @import("getty");
const types = @import("../types.zig");
const Vis = struct {
pub usingnamespace getty.de.Visitor(
@This(),
types.Bytearray,
.{ .visitSeq = visitSeq },
);
pub fn visitSeq(
_: @This(),
alloc: ?std.mem.Allocator,
comptime Deserializer: type,
input: anytype,
) Deserializer.Error!types.Bytearray {
var list = std.ArrayList(u8).init(alloc.?);
while (try input.nextElement(alloc, u8)) |element| {
try list.append(element);
}
return types.Bytearray{ .a = list.toOwnedSlice() };
}
};
pub fn is(comptime T: type) bool {
return T == types.Bytearray;
}
pub fn Visitor(comptime _: type) type {
return Vis;
}
pub fn deserialize(
alloc: ?std.mem.Allocator,
comptime _: type,
deserializer: anytype,
visitor: anytype,
) !@TypeOf(visitor).Value {
return try deserializer.deserializeSeq(alloc, visitor);
}