File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed
src/network/protocol/messages Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ const std = @import("std");
2
2
const CompactSizeUint = @import ("bitcoin-primitives" ).types .CompatSizeUint ;
3
3
const message = @import ("./lib.zig" );
4
4
const genericChecksum = @import ("lib.zig" ).genericChecksum ;
5
+ const genericDeserializeSlice = @import ("lib.zig" ).genericDeserializeSlice ;
5
6
6
7
const Sha256 = std .crypto .hash .sha2 .Sha256 ;
7
8
8
9
const protocol = @import ("../lib.zig" );
9
10
10
11
pub const GetdataMessage = struct {
11
12
inventory : []const protocol.InventoryItem ,
13
+ const Self = @This ();
12
14
13
15
pub inline fn name () * const [12 ]u8 {
14
16
return protocol .CommandNames .GETDATA ++ [_ ]u8 {0 } ** 5 ;
@@ -94,10 +96,8 @@ pub const GetdataMessage = struct {
94
96
}
95
97
96
98
/// 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 );
101
101
}
102
102
103
103
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ const std = @import("std");
2
2
const CompactSizeUint = @import ("bitcoin-primitives" ).types .CompatSizeUint ;
3
3
const message = @import ("./lib.zig" );
4
4
const genericChecksum = @import ("lib.zig" ).genericChecksum ;
5
+ const genericDeserializeSlice = @import ("lib.zig" ).genericDeserializeSlice ;
5
6
6
7
const Sha256 = std .crypto .hash .sha2 .Sha256 ;
7
8
8
9
const protocol = @import ("../lib.zig" );
9
10
10
11
pub const InvMessage = struct {
11
12
inventory : []const protocol.InventoryItem ,
13
+ const Self = @This ();
12
14
13
15
pub inline fn name () * const [12 ]u8 {
14
16
return protocol .CommandNames .INV ++ [_ ]u8 {0 } ** 5 ;
@@ -94,10 +96,8 @@ pub const InvMessage = struct {
94
96
}
95
97
96
98
/// 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 );
101
101
}
102
102
103
103
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ pub const Message = union(MessageTypes) {
103
103
.getdata = > | * m | m .deinit (allocator ),
104
104
.cmpctblock = > | * m | m .deinit (allocator ),
105
105
.headers = > | * m | m .deinit (allocator ),
106
+ .inv = > | * m | m .deinit (allocator ),
106
107
else = > {}
107
108
}
108
109
}
You can’t perform that action at this time.
0 commit comments