github.com/cyverse/go-irodsclient@v0.13.2/irods/message/query_special_collection.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 type IRODSMessageQuerySpecialCollection IRODSMessageDataObjectRequest 11 12 // GetBytes returns byte array 13 func (msg *IRODSMessageQuerySpecialCollection) GetBytes() ([]byte, error) { 14 xmlBytes, err := xml.Marshal(msg) 15 if err != nil { 16 return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err) 17 } 18 return xmlBytes, nil 19 } 20 21 // FromBytes returns struct from bytes 22 func (msg *IRODSMessageQuerySpecialCollection) FromBytes(bytes []byte) error { 23 err := xml.Unmarshal(bytes, msg) 24 if err != nil { 25 return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err) 26 } 27 return nil 28 } 29 30 // GetMessage builds a message 31 func (msg *IRODSMessageQuerySpecialCollection) GetMessage() (*IRODSMessage, error) { 32 bytes, err := msg.GetBytes() 33 if err != nil { 34 return nil, xerrors.Errorf("failed to get bytes from irods message: %w", err) 35 } 36 37 msgBody := IRODSMessageBody{ 38 Type: RODS_MESSAGE_API_REQ_TYPE, 39 Message: bytes, 40 Error: nil, 41 Bs: nil, 42 IntInfo: int32(common.QUERY_SPEC_COLL_AN), 43 } 44 45 msgHeader, err := msgBody.BuildHeader() 46 if err != nil { 47 return nil, xerrors.Errorf("failed to build header from irods message: %w", err) 48 } 49 50 return &IRODSMessage{ 51 Header: msgHeader, 52 Body: &msgBody, 53 }, nil 54 } 55 56 // FromMessage returns struct from IRODSMessage 57 func (msg *IRODSMessageQuerySpecialCollection) FromMessage(msgIn *IRODSMessage) error { 58 if msgIn.Body == nil { 59 return xerrors.Errorf("empty message body") 60 } 61 62 err := msg.FromBytes(msgIn.Body.Message) 63 if err != nil { 64 return xerrors.Errorf("failed to get irods message from message body") 65 } 66 return nil 67 }