Skip to content

Commit

Permalink
Make bincode.write respect "BincodeSize" for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
InKryption committed Jun 13, 2024
1 parent 94f2212 commit b807264
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bincode/bincode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,17 @@ pub fn write(writer: anytype, data: anytype, params: bincode.Params) !void {
.Type, .Void, .NoReturn, .Undefined, .Null, .Fn, .Opaque, .Frame, .AnyFrame => return,
.Bool => return writer.writeByte(@intFromBool(data)),
.Enum => |_| {
comptime var SerializedSize = u32;
comptime if (@hasDecl(T, "BincodeSize")) {
SerializedSize = T.BincodeSize;
};
if (getConfig(T)) |type_config| {
if (type_config.serializer) |serialize_fcn| {
return serialize_fcn(writer, data, params);
}
}

return bincode.write(writer, @as(u32, @intFromEnum(data)), params);
return bincode.write(writer, @as(SerializedSize, @intFromEnum(data)), params);
},
.Union => |info| {
try bincode.write(writer, @as(u32, @intFromEnum(data)), params);
Expand Down

0 comments on commit b807264

Please sign in to comment.