Finished(?) decompression stuff
This commit is contained in:
+9
-4
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const StatelessDecomp = *const fn (std.mem.Allocator, in: []u8, out: []u8) Error!usize;
|
||||
|
||||
pub const Error = error{
|
||||
OutOfMemory,
|
||||
EndOfStream,
|
||||
@@ -11,14 +13,17 @@ const Decompressor = @This();
|
||||
|
||||
alloc: std.mem.Allocator = std.heap.page_allocator,
|
||||
vtable: *struct {
|
||||
decompress: *const fn (*Decompressor, in: []u8, out: []u8) Error!usize = defaultDecompress,
|
||||
stateless: *const fn (std.mem.Allocator, in: []u8, out: []u8) Error!usize,
|
||||
decompress: *const fn (*const Decompressor, in: []u8, out: []u8) Error!usize = defaultDecompress,
|
||||
stateless: StatelessDecomp,
|
||||
},
|
||||
|
||||
pub fn decompress(self: *Decompressor, in: []u8, out: []u8) Error!usize {
|
||||
pub fn decompress(self: *const Decompressor, in: []u8, out: []u8) Error!usize {
|
||||
return self.vtable.decompress(self, in, out);
|
||||
}
|
||||
pub fn stateless(self: Decompressor, alloc: std.mem.Allocator, in: []u8, out: []u8) Error!usize {
|
||||
return self.vtable.stateless(alloc, in, out);
|
||||
}
|
||||
|
||||
fn defaultDecompress(self: *Decompressor, in: []u8, out: []u8) Error!usize {
|
||||
fn defaultDecompress(self: *const Decompressor, in: []u8, out: []u8) Error!usize {
|
||||
return self.vtable.stateless(self.alloc, in, out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user