feat(buffers): add support for buffer references
This commit is contained in:
parent
90b443a487
commit
4d3d91a744
2 changed files with 15 additions and 0 deletions
|
@ -292,6 +292,7 @@ pub fn build_exe(
|
|||
.root_source_file = b.path("src/buffer/Buffer.zig"),
|
||||
.imports = &.{
|
||||
.{ .name = "cbor", .module = cbor_mod },
|
||||
.{ .name = "thespian", .module = thespian_mod },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const tp = @import("thespian");
|
||||
const Buffer = @import("Buffer.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
@ -109,3 +110,16 @@ pub fn delete_all(self: *Self) void {
|
|||
}
|
||||
self.buffers.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
pub fn buffer_from_ref(self: *Self, buffer_ref: usize) ?*Buffer {
|
||||
var i = self.buffers.iterator();
|
||||
while (i.next()) |p|
|
||||
if (@intFromPtr(p.value_ptr.*) == buffer_ref)
|
||||
return p.value_ptr.*;
|
||||
tp.trace(tp.channel.debug, .{ "buffer_from_ref", "failed", buffer_ref });
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn buffer_to_ref(_: *Self, buffer: *Buffer) usize {
|
||||
return @intFromPtr(buffer);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue