shorten cmph pack by 4 bytes

This commit is contained in:
2022-02-23 20:30:23 +02:00
committed by Motiejus Jakštys
parent 3498167108
commit c0afca00b0
2 changed files with 5 additions and 4 deletions

View File

@@ -6,8 +6,9 @@ const c = @cImport({
@cInclude("cmph.h");
});
// pack packs cmph hashes for the given input and returns a slice ("cmph
// userdata") for further storage. The slice must be freed by the caller.
// pack packs cmph hashes for the given input and returns a slice ("cmph pack
// minus first 4 bytes") for further storage. The slice must be freed by the
// caller.
const packErr = Allocator.Error || error{Overflow};
pub fn pack(allocator: Allocator, input: [][*:0]const u8) packErr![]const u8 {
var cvector = @ptrCast([*c][*c]u8, input.ptr);
@@ -24,7 +25,7 @@ pub fn pack(allocator: Allocator, input: [][*:0]const u8) packErr![]const u8 {
var buf = try allocator.alloc(u8, size);
c.cmph_pack(hash, &buf[0]);
c.cmph_destroy(hash);
return buf;
return buf[4..];
}
const testing = std.testing;