Skip to content

Commit 091a8a2

Browse files
committed
add free memory
1 parent 4761a09 commit 091a8a2

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/network/protocol/messages/getdata.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ const std = @import("std");
22
const CompactSizeUint = @import("bitcoin-primitives").types.CompatSizeUint;
33
const message = @import("./lib.zig");
44
const genericChecksum = @import("lib.zig").genericChecksum;
5+
const genericDeserializeSlice = @import("lib.zig").genericDeserializeSlice;
56

67
const Sha256 = std.crypto.hash.sha2.Sha256;
78

89
const protocol = @import("../lib.zig");
910

1011
pub const GetdataMessage = struct {
1112
inventory: []const protocol.InventoryItem,
13+
const Self = @This();
1214

1315
pub inline fn name() *const [12]u8 {
1416
return protocol.CommandNames.GETDATA ++ [_]u8{0} ** 5;
@@ -94,10 +96,8 @@ pub const GetdataMessage = struct {
9496
}
9597

9698
/// Deserialize bytes into a `GetdataMessage`
97-
pub fn deserializeSlice(allocator: std.mem.Allocator, bytes: []const u8) !GetdataMessage {
98-
var fbs = std.io.fixedBufferStream(bytes);
99-
const reader = fbs.reader();
100-
return try GetdataMessage.deserializeReader(allocator, reader);
99+
pub fn deserializeSlice(allocator: std.mem.Allocator, bytes: []const u8) !Self {
100+
return genericDeserializeSlice(Self, allocator, bytes);
101101
}
102102

103103

src/network/protocol/messages/inv.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ const std = @import("std");
22
const CompactSizeUint = @import("bitcoin-primitives").types.CompatSizeUint;
33
const message = @import("./lib.zig");
44
const genericChecksum = @import("lib.zig").genericChecksum;
5+
const genericDeserializeSlice = @import("lib.zig").genericDeserializeSlice;
56

67
const Sha256 = std.crypto.hash.sha2.Sha256;
78

89
const protocol = @import("../lib.zig");
910

1011
pub const InvMessage = struct {
1112
inventory: []const protocol.InventoryItem,
13+
const Self = @This();
1214

1315
pub inline fn name() *const [12]u8 {
1416
return protocol.CommandNames.INV ++ [_]u8{0} ** 5;
@@ -94,10 +96,8 @@ pub const InvMessage = struct {
9496
}
9597

9698
/// Deserialize bytes into a `InvMessage`
97-
pub fn deserializeSlice(allocator: std.mem.Allocator, bytes: []const u8) !InvMessage {
98-
var fbs = std.io.fixedBufferStream(bytes);
99-
const reader = fbs.reader();
100-
return try InvMessage.deserializeReader(allocator, reader);
99+
pub fn deserializeSlice(allocator: std.mem.Allocator, bytes: []const u8) !Self {
100+
return genericDeserializeSlice(Self, allocator, bytes);
101101
}
102102

103103

src/network/protocol/messages/lib.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub const Message = union(MessageTypes) {
103103
.getdata => |*m| m.deinit(allocator),
104104
.cmpctblock => |*m| m.deinit(allocator),
105105
.headers => |*m| m.deinit(allocator),
106+
.inv => |*m| m.deinit(allocator),
106107
else => {}
107108
}
108109
}

0 commit comments

Comments
 (0)