-
Notifications
You must be signed in to change notification settings - Fork 2
/
addr.go
39 lines (32 loc) · 740 Bytes
/
addr.go
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 p2p
import (
"bytes"
)
// ComparableAddr is an Addr which also satisfies comparable
type ComparableAddr interface {
Addr
comparable
}
type Addr interface {
// MarshalText serializes the address in a way that can be unambiguously parsed by the Swarm
// that produced this address.
MarshalText() ([]byte, error)
String() string
}
// AddrParser is the type of functions which parse []byte into Addrs
type AddrParser[A Addr] func([]byte) (A, error)
type UnwrapAddr interface {
Unwrap() Addr
Map(func(Addr) Addr) Addr
}
func CompareAddrs(a, b Addr) int {
aData, err := a.MarshalText()
if err != nil {
panic(err)
}
bData, err := b.MarshalText()
if err != nil {
panic(err)
}
return bytes.Compare(aData, bData)
}