-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deserialization of comptime structs #22
base: master
Are you sure you want to change the base?
Conversation
if (try isFixedSizeObject(T)) { | ||
var i: usize = 0; | ||
const pitch = @sizeOf(T); | ||
while (i < out.len) : (i += pitch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that used to be inline
in the calling code. That made no sense and yet it worked.
.name = try std.testing.allocator.alloc(u8, 5), | ||
.age = 32, | ||
.company = try std.testing.allocator.alloc(u8, 8), | ||
}; | ||
@memcpy(data.name, "James"); | ||
@memcpy(data.company, "DEV Inc."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be fixed using @as(, @constCast
@@ -347,17 +366,17 @@ test "deserializes a string" { | |||
} | |||
|
|||
const Pastry = struct { | |||
name: []const u8, | |||
name: []u8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deserialization only worked because it was returning a direct pointer to the serialized payload, which is []const u8
itself.
// Taken from ssz.cr | ||
const Person = struct { | ||
name: []const u8, | ||
name: []u8, | ||
age: u8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interestingly, this also causes the same "comptime ref" issue, and so I need a more complete workaround for it.
This is probably a dead-end since I am trying to force the deserialization of a structure that is inherently
comptime
. Still, I want to keep experimenting in order to see how far I can push this boundary.The issues with this approach are that: