/
access.go
47 lines (40 loc) · 1.41 KB
/
access.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
package bifrost_rpc_access
import (
bifrost_rpc "github.com/aperturerobotics/bifrost/rpc"
b58 "github.com/mr-tron/base58/base58"
)
// NewLookupRpcServiceRequest constructs a new LookupRpcServiceRequest.
func NewLookupRpcServiceRequest(serviceID, serverID string) *LookupRpcServiceRequest {
return &LookupRpcServiceRequest{
ServerId: serverID,
ServiceId: serviceID,
}
}
// RequestFromDirective converts a LookupRpcService directive to a request.
func RequestFromDirective(dir bifrost_rpc.LookupRpcService) *LookupRpcServiceRequest {
return NewLookupRpcServiceRequest(dir.LookupRpcServiceID(), dir.LookupRpcServerID())
}
// Validate validates the LookupRpcServiceRequest.
func (r *LookupRpcServiceRequest) Validate() error {
return r.ToDirective().Validate()
}
// ToDirective converts the request to a directive.
func (r *LookupRpcServiceRequest) ToDirective() bifrost_rpc.LookupRpcService {
return bifrost_rpc.NewLookupRpcService(r.GetServiceId(), r.GetServerId())
}
// MarshalComponentID marshals the b58 component ID.
func (r *LookupRpcServiceRequest) MarshalComponentID() (string, error) {
data, err := r.MarshalVT()
if err != nil {
return "", err
}
return b58.Encode(data), nil
}
// UnmarshalComponentID unmarshals the component ID.
func (r *LookupRpcServiceRequest) UnmarshalComponentID(componentID string) error {
data, err := b58.Decode(componentID)
if err != nil {
return err
}
return r.UnmarshalVT(data)
}