-
Notifications
You must be signed in to change notification settings - Fork 0
/
wire.go
56 lines (40 loc) · 1.08 KB
/
wire.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package kareless
type Route struct {
Medium int
Address string // Medium-specific address
}
type Router interface {
Resolve(addr string) Route
}
type RouterFunc func(addr string) Route
func (f RouterFunc) Resolve(addr string) Route {
return f(addr)
}
type Marshaler interface {
Marshal(payload any) []byte
}
type MarshalerFunc func(payload any) []byte
func (f MarshalerFunc) Marshal(payload any) []byte {
return f(payload)
}
type Unmarshaler interface {
Unmarshal(data []byte, v any) error
}
type UnmarshalerFunc func(data []byte, v any) error
func (f UnmarshalerFunc) Unmarshal(data []byte, v any) error {
return f(data, v)
}
type Encapsulator[M any] interface {
Encapsulate(route Route, data []byte) M
}
type EncapsulatorFunc[M any] func(route Route, data []byte) M
func (f EncapsulatorFunc[M]) Encapsulate(route Route, data []byte) M {
return f(route, data)
}
type Decapsulator[M any] interface {
Decapsulate(msg M) ([]byte, error)
}
type DecapsulatorFunc[M any] func(msg M) ([]byte, error)
func (f DecapsulatorFunc[M]) Decapsulate(msg M) ([]byte, error) {
return f(msg)
}