tiny.peer.Address
Defined in tiny.peer.
API (9)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/peer/src/address.zig:74
zig
pub const Address = union(enum) { ip4: Ip4, ip6: Ip6, relay: Relay, pub const FormatError: type = error{OutputTooSmall}; pub const ParseError: type = AddressParseError; pub fn fromRelay(host_name: []const u8, port: u16) Relay.InitError!Address { return .{ .relay = try Relay.init(host_name, port) }; } pub fn format(self: Address, output: []u8) FormatError![]const u8 { var writer = std.Io.Writer.fixed(output); switch (self) { .ip4 => |value| writer.print( "{d}.{d}.{d}.{d}:{d}", .{ value.addr[0], value.addr[1], value.addr[2], value.addr[3], value.port }, ) catch return error.OutputTooSmall, .ip6 => |value| { const address = std.Io.net.Ip6Address{ .bytes = value.addr, .port = value.port, }; address.format(&writer) catch return error.OutputTooSmall; }, .relay => |value| writer.print( "relay:{s}:{d}", .{ value.host(), value.port }, ) catch return error.OutputTooSmall, } return writer.buffered(); } pub fn parse(source: []const u8) ParseError!Address { if (std.mem.startsWith(u8, source, "relay:")) return parseRelay(source); if (source.len != 0 and source[0] == '[') return parseIp6(source); return parseIp4(source); } pub fn eql(self: Address, other: Address) bool { if (std.meta.activeTag(self) != std.meta.activeTag(other)) return false; return switch (self) { .ip4 => |left| switch (other) { .ip4 => |right| left.port == right.port and std.mem.eql(u8, &left.addr, &right.addr), else => unreachable, }, .ip6 => |left| switch (other) { .ip6 => |right| left.port == right.port and std.mem.eql(u8, &left.addr, &right.addr), else => unreachable, }, .relay => |left| switch (other) { .relay => |right| left.eql(&right), else => unreachable, }, }; }};Source: lib/peer/src/root.zig:22
zig
pub const Address = address.Address;Audit
| Definitions | 7 |
|---|---|
| Public names | 7 |
| Members | 4 |
| Version | 26.7.0 |
| Revision | daab053ee433 |