mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 08:14:50 +00:00
This commit is contained in:
@@ -76,6 +76,10 @@ pub const ZeroCopyMessage = packed struct {
|
||||
length: u16,
|
||||
bytes: void = {},
|
||||
|
||||
pub fn init(allocator: Allocator, payload_len: u16) !*Self {
|
||||
const bytes = try allocator.alignedAlloc(u8, @alignOf(Self), @sizeOf(Self) + payload_len);
|
||||
}
|
||||
|
||||
fn getRelay(self: *Self) *align(1) Relay {
|
||||
return std.mem.bytesAsValue(Relay, &self.bytes);
|
||||
}
|
||||
@@ -137,11 +141,11 @@ pub const ZeroCopyMessage = packed struct {
|
||||
test "testing variable length zero copy struct" {
|
||||
const gpa = std.testing.allocator;
|
||||
const payload_len = 48;
|
||||
const bytes = try gpa.alignedAlloc(u8, @alignOf(ZeroCopyMessage), @sizeOf(ZeroCopyMessage) + payload_len);
|
||||
defer gpa.free(bytes);
|
||||
|
||||
// Create a view of the byte slice as a ZeroCopyMessage
|
||||
const zcm: *ZeroCopyMessage = .fromBytesUnchecked(bytes);
|
||||
defer zcm.deinit(gpa);
|
||||
|
||||
{
|
||||
// Set the message values
|
||||
|
||||
Reference in New Issue
Block a user