Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Packets now use zon instead of json

IamPyu e187b9e0 7b79ffc2

+6 -6
+6 -6
src/packet.zig
··· 1 1 const std = @import("std"); 2 2 const Io = std.Io; 3 3 const net = std.net; 4 - const json = std.json; 4 + const zon = std.zon; 5 5 const mem = std.mem; 6 6 const Allocator = mem.Allocator; 7 7 ··· 35 35 36 36 /// Serialize the payload to JSON 37 37 pub fn serialize(self: *const Self) ![]u8 { 38 - const fmt = json.fmt(self.payload, .{ .whitespace = .minified }); 39 38 var writer = Io.Writer.Allocating.init(self.allocator); 40 - try fmt.format(&writer.writer); 39 + try zon.stringify.serialize(self.payload, .{ .whitespace = false }, &writer.writer); 41 40 42 41 const buf = try writer.toOwnedSlice(); 43 42 return buf; 44 43 } 45 44 46 45 /// Deserialize a serialized payload 47 - pub fn deserialize(s: []const u8, allocator: Allocator) !json.Parsed(T) { 48 - return try json.parseFromSlice(T, allocator, s, .{}); 46 + pub fn deserialize(s: []const u8, allocator: Allocator) !T { 47 + return try zon.parse.fromSlice(T, allocator, s, null, .{}); 48 + // return try json.parseFromSlice(T, allocator, s, .{}); 49 49 } 50 50 51 51 /// Send the packet to a writer ··· 99 99 defer std.testing.allocator.free(output); 100 100 101 101 try std.testing.expectEqualSlices(u8, 102 - \\{"x":3,"m":"hello"} 102 + \\.{.x=3,.m="hello"} 103 103 , output); 104 104 105 105 file.close();