-
Notifications
You must be signed in to change notification settings - Fork 129
/
messages.go
59 lines (48 loc) · 1.42 KB
/
messages.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
57
58
59
package xgress_common
import (
"github.com/openziti/channel/v2"
"github.com/openziti/channel/v2/protobufs"
"github.com/openziti/ziti/common/pb/edge_ctrl_pb"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)
const (
PayloadFlagsHeader uint8 = 0x10
)
func GetResultOrFailure(msg *channel.Message, err error, result protobufs.TypedMessage) error {
if err != nil {
return err
}
if msg.ContentType == int32(edge_ctrl_pb.ContentType_ErrorType) {
msg := string(msg.Body)
if msg == "" {
msg = "error state returned from controller with no message"
}
return errors.New(msg)
}
if msg.ContentType != result.GetContentType() {
return errors.Errorf("unexpected response type %v to request. expected %v", msg.ContentType, result.GetContentType())
}
return proto.Unmarshal(msg.Body, result)
}
func CheckForFailureResult(msg *channel.Message, err error, successType edge_ctrl_pb.ContentType) error {
if err != nil {
return err
}
if msg.ContentType == int32(edge_ctrl_pb.ContentType_ErrorType) {
msg := string(msg.Body)
if msg == "" {
msg = "error state returned from controller with no message"
}
return errors.New(msg)
}
if msg.ContentType != int32(successType) {
return errors.Errorf("unexpected response type %v to request. expected %v", msg.ContentType, successType)
}
return nil
}
func GetFinHeaders() map[uint8][]byte {
return map[uint8][]byte{
PayloadFlagsHeader: {0x1, 0, 0, 0},
}
}