blob: 04e2254640601faa7d0c177093977102aefb4bdb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package util
import (
"fmt"
)
type IPAddress struct {
Host []byte `size:"*-2"`
Port uint16 `order:"big"`
}
func NewIPAddress(host []byte, port uint16) *IPAddress {
ip := &IPAddress{
Host: make([]byte, len(host)),
Port: port,
}
copy(ip.Host, host)
return ip
}
type Address struct {
Transport string
Options uint32 `order:"big"`
Address []byte `size:"*"`
}
func NewAddress(transport string, addr []byte) *Address {
a := &Address{
Transport: transport,
Options: 0,
Address: make([]byte, len(addr)),
}
copy(a.Address, addr)
return a
}
func (a *Address) String() string {
return fmt.Sprintf("Address{%s}", AddressString(a.Transport, a.Address))
}
|