Skip to content

Commit

Permalink
generic deserializeSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
oxlime committed Oct 4, 2024
1 parent cdbfa86 commit 2e27ca9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/network/protocol/messages/addr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const std = @import("std");
const protocol = @import("../lib.zig");
const genericChecksum = @import("lib.zig").genericChecksum;
const NetworkAddress = @import("../types/NetworkAddress.zig").NetworkAddress;
const genericDeserializeSlice = @import("lib.zig").genericDeserializeSlice;

const Endian = std.builtin.Endian;
const Sha256 = std.crypto.hash.sha2.Sha256;
Expand Down Expand Up @@ -36,6 +37,8 @@ pub const NetworkIPAddr = struct {
pub const AddrMessage = struct {
ip_addresses: []NetworkIPAddr,

const Self = @This();

pub inline fn name() *const [12]u8 {
return protocol.CommandNames.ADDR ++ [_]u8{0} ** 8;
}
Expand Down Expand Up @@ -102,9 +105,7 @@ pub const AddrMessage = struct {

/// Deserialize bytes into a `AddrMessage`
pub fn deserializeSlice(allocator: std.mem.Allocator, bytes: []const u8) !AddrMessage {
var fbs = std.io.fixedBufferStream(bytes);
const reader = fbs.reader();
return try AddrMessage.deserializeReader(allocator, reader);
return genericDeserializeSlice(Self, allocator, bytes);
}

pub fn hintSerializedLen(self: AddrMessage) usize {
Expand Down

0 comments on commit 2e27ca9

Please sign in to comment.