Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions s2s.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ fn serializeRecursive(stream: anytype, comptime T: type, value: T) @TypeOf(strea
}
},
.pointer => |ptr| {
if (ptr.sentinel != null) @compileError("Sentinels are not supported yet!");
if (ptr.sentinel() != null) @compileError("Sentinels are not supported yet!");
switch (ptr.size) {
.One => try serializeRecursive(stream, ptr.child, value.*),
.Slice => {
.one => try serializeRecursive(stream, ptr.child, value.*),
.slice => {
try stream.writeInt(u64, value.len, .little);
if (ptr.child == u8) {
try stream.writeAll(value);
Expand All @@ -92,8 +92,8 @@ fn serializeRecursive(stream: anytype, comptime T: type, value: T) @TypeOf(strea
}
}
},
.C => unreachable,
.Many => unreachable,
.c => unreachable,
.many => unreachable,
}
},
.array => |arr| {
Expand All @@ -104,7 +104,7 @@ fn serializeRecursive(stream: anytype, comptime T: type, value: T) @TypeOf(strea
try serializeRecursive(stream, arr.child, item);
}
}
if (arr.sentinel != null) @compileError("Sentinels are not supported yet!");
if (arr.sentinel() != null) @compileError("Sentinels are not supported yet!");
},
.@"struct" => |str| {
// we can safely ignore the struct layout here as we will serialize the data by field order,
Expand Down Expand Up @@ -228,17 +228,17 @@ fn recursiveDeserialize(
@truncate(try stream.readInt(AlignedInt(T), .little)),

.pointer => |ptr| {
if (ptr.sentinel != null) @compileError("Sentinels are not supported yet!");
if (ptr.sentinel() != null) @compileError("Sentinels are not supported yet!");
switch (ptr.size) {
.One => {
.one => {
const pointer = try allocator.?.create(ptr.child);
errdefer allocator.?.destroy(pointer);

try recursiveDeserialize(stream, ptr.child, allocator, pointer);

target.* = pointer;
},
.Slice => {
.slice => {
const length = std.math.cast(usize, try stream.readInt(u64, .little)) orelse return error.UnexpectedData;

const slice = try allocator.?.alloc(ptr.child, length);
Expand All @@ -254,8 +254,8 @@ fn recursiveDeserialize(

target.* = slice;
},
.C => unreachable,
.Many => unreachable,
.c => unreachable,
.many => unreachable,
}
},
.array => |arr| {
Expand Down Expand Up @@ -544,22 +544,22 @@ fn computeTypeHashInternal(hasher: *TypeHashFn, comptime T: type) void {
},
.pointer => |ptr| {
if (ptr.is_volatile) @compileError("Serializing volatile pointers is most likely a mistake.");
if (ptr.sentinel != null) @compileError("Sentinels are not supported yet!");
if (ptr.sentinel() != null) @compileError("Sentinels are not supported yet!");
switch (ptr.size) {
.One => {
.one => {
hasher.update("pointer");
computeTypeHashInternal(hasher, ptr.child);
},
.Slice => {
.slice => {
hasher.update("slice");
computeTypeHashInternal(hasher, ptr.child);
},
.C => @compileError("C-pointers are not supported"),
.Many => @compileError("Many-pointers are not supported"),
.c => @compileError("C-pointers are not supported"),
.many => @compileError("Many-pointers are not supported"),
}
},
.array => |arr| {
if (arr.sentinel != null) @compileError("Sentinels are not supported yet!");
if (arr.sentinel() != null) @compileError("Sentinels are not supported yet!");
hasher.update(&intToLittleEndianBytes(@as(u64, arr.len)));
computeTypeHashInternal(hasher, arr.child);
},
Expand Down