-
Notifications
You must be signed in to change notification settings - Fork 6
/
operation_complete_request.go
64 lines (53 loc) · 1.66 KB
/
operation_complete_request.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
60
61
62
63
64
package message
import (
"encoding/xml"
"github.com/cyverse/go-irodsclient/irods/common"
"golang.org/x/xerrors"
)
// IRODSMessageOperationCompleteRequest stores operation complete request
type IRODSMessageOperationCompleteRequest IRODSMessageInt
// NewIRODSMessageOperationCompleteRequest creates a IRODSMessageOperationCompleteRequest message
func NewIRODSMessageOperationCompleteRequest(value int) *IRODSMessageOperationCompleteRequest {
request := &IRODSMessageOperationCompleteRequest{
Value: value,
}
return request
}
// GetBytes returns byte array
func (msg *IRODSMessageOperationCompleteRequest) GetBytes() ([]byte, error) {
xmlBytes, err := xml.Marshal(msg)
if err != nil {
return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err)
}
return xmlBytes, nil
}
// FromBytes returns struct from bytes
func (msg *IRODSMessageOperationCompleteRequest) FromBytes(bytes []byte) error {
err := xml.Unmarshal(bytes, msg)
if err != nil {
return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err)
}
return nil
}
// GetMessage builds a message
func (msg *IRODSMessageOperationCompleteRequest) GetMessage() (*IRODSMessage, error) {
bytes, err := msg.GetBytes()
if err != nil {
return nil, xerrors.Errorf("failed to get bytes from irods message: %w", err)
}
msgBody := IRODSMessageBody{
Type: RODS_MESSAGE_API_REQ_TYPE,
Message: bytes,
Error: nil,
Bs: nil,
IntInfo: int32(common.OPR_COMPLETE_AN),
}
msgHeader, err := msgBody.BuildHeader()
if err != nil {
return nil, xerrors.Errorf("failed to build header from irods message: %w", err)
}
return &IRODSMessage{
Header: msgHeader,
Body: &msgBody,
}, nil
}