github.com/cyverse/go-irodsclient@v0.13.2/irods/message/seek_data_object_response.go (about) 1 package message 2 3 import ( 4 "encoding/xml" 5 6 "github.com/cyverse/go-irodsclient/irods/common" 7 "github.com/cyverse/go-irodsclient/irods/types" 8 "golang.org/x/xerrors" 9 ) 10 11 // IRODSMessageSeekDataObjectResponse stores data object seek response 12 type IRODSMessageSeekDataObjectResponse struct { 13 XMLName xml.Name `xml:"fileLseekOut_PI"` 14 Offset int64 `xml:"offset"` 15 } 16 17 // FromBytes returns struct from bytes 18 func (msg *IRODSMessageSeekDataObjectResponse) FromBytes(bytes []byte) error { 19 err := xml.Unmarshal(bytes, msg) 20 if err != nil { 21 return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err) 22 } 23 return nil 24 } 25 26 // CheckError returns error if server returned an error 27 func (msg *IRODSMessageSeekDataObjectResponse) CheckError() error { 28 if msg.Offset < 0 { 29 return types.NewIRODSError(common.ErrorCode(msg.Offset)) 30 } 31 return nil 32 } 33 34 // FromMessage returns struct from IRODSMessage 35 func (msg *IRODSMessageSeekDataObjectResponse) FromMessage(msgIn *IRODSMessage) error { 36 if msgIn.Body == nil { 37 return xerrors.Errorf("empty message body") 38 } 39 40 err := msg.FromBytes(msgIn.Body.Message) 41 if err != nil { 42 return xerrors.Errorf("failed to get irods message from message body") 43 } 44 return nil 45 }