github.com/cyverse/go-irodsclient@v0.13.2/irods/message/move_data_object_request.go (about) 1 package message 2 3 import ( 4 "encoding/xml" 5 6 "github.com/cyverse/go-irodsclient/irods/common" 7 "golang.org/x/xerrors" 8 ) 9 10 // IRODSMessageMoveDataObjectRequest stores data object move request 11 type IRODSMessageMoveDataObjectRequest struct { 12 XMLName xml.Name `xml:"DataObjCopyInp_PI"` 13 Paths []IRODSMessageDataObjectRequest 14 } 15 16 // NewIRODSMessageMoveDataObjectRequest creates a IRODSMessageMoveDataObjectRequest message 17 func NewIRODSMessageMoveDataObjectRequest(srcPath string, destPath string) *IRODSMessageMoveDataObjectRequest { 18 return &IRODSMessageMoveDataObjectRequest{ 19 Paths: []IRODSMessageDataObjectRequest{ 20 { 21 Path: srcPath, 22 CreateMode: 0, 23 OpenFlags: 0, 24 Offset: 0, 25 Size: 0, 26 Threads: 0, 27 OperationType: int(common.OPER_TYPE_RENAME_DATA_OBJ), 28 KeyVals: IRODSMessageSSKeyVal{ 29 Length: 0, 30 }, 31 }, 32 { 33 Path: destPath, 34 CreateMode: 0, 35 OpenFlags: 0, 36 Offset: 0, 37 Size: 0, 38 Threads: 0, 39 OperationType: int(common.OPER_TYPE_RENAME_DATA_OBJ), 40 KeyVals: IRODSMessageSSKeyVal{ 41 Length: 0, 42 }, 43 }, 44 }, 45 } 46 } 47 48 // GetBytes returns byte array 49 func (msg *IRODSMessageMoveDataObjectRequest) GetBytes() ([]byte, error) { 50 xmlBytes, err := xml.Marshal(msg) 51 if err != nil { 52 return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err) 53 } 54 return xmlBytes, nil 55 } 56 57 // FromBytes returns struct from bytes 58 func (msg *IRODSMessageMoveDataObjectRequest) FromBytes(bytes []byte) error { 59 err := xml.Unmarshal(bytes, msg) 60 if err != nil { 61 return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err) 62 } 63 return nil 64 } 65 66 // GetMessage builds a message 67 func (msg *IRODSMessageMoveDataObjectRequest) GetMessage() (*IRODSMessage, error) { 68 bytes, err := msg.GetBytes() 69 if err != nil { 70 return nil, xerrors.Errorf("failed to get bytes from irods message: %w", err) 71 } 72 73 msgBody := IRODSMessageBody{ 74 Type: RODS_MESSAGE_API_REQ_TYPE, 75 Message: bytes, 76 Error: nil, 77 Bs: nil, 78 IntInfo: int32(common.DATA_OBJ_RENAME_AN), 79 } 80 81 msgHeader, err := msgBody.BuildHeader() 82 if err != nil { 83 return nil, xerrors.Errorf("failed to build header from irods message: %w", err) 84 } 85 86 return &IRODSMessage{ 87 Header: msgHeader, 88 Body: &msgBody, 89 }, nil 90 }