Skip to content

Conversation

@gballet
Copy link
Collaborator

@gballet gballet commented Jan 2, 2025

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:

  • I need an allocator for slices
  • I can not really write to const (although some test successfully does that, which is a strange behavior and probably invalid).

@gballet gballet added the enhancement New feature or request label Jan 2, 2025
if (try isFixedSizeObject(T)) {
var i: usize = 0;
const pitch = @sizeOf(T);
while (i < out.len) : (i += pitch) {
Copy link
Collaborator Author

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.

Comment on lines +154 to +159
.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.");
Copy link
Collaborator Author

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


const Pastry = struct {
name: []const u8,
name: []u8,
Copy link
Collaborator Author

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.

const Person = struct {
name: []const u8,
name: []u8,
age: u8,
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants