github.com/cyverse/go-irodsclient@v0.13.2/irods/message/get_data_object_stat_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  // IRODSMessageGetDataObjectStatResponse stores file stat request
    12  type IRODSMessageGetDataObjectStatResponse struct {
    13  	XMLName                  xml.Name                       `xml:"RodsObjStat_PI"`
    14  	Size                     int64                          `xml:"objSize"`
    15  	Type                     int                            `xml:"objType"`
    16  	DataMode                 int                            `xml:"dataMode"`
    17  	DataID                   string                         `xml:"dataId"`
    18  	ChkSum                   string                         `xml:"chksum"`
    19  	Owner                    string                         `xml:"ownerName"`
    20  	Zone                     string                         `xml:"ownerZone"`
    21  	CreateTime               string                         `xml:"createTime"`
    22  	ModifyTime               string                         `xml:"modifyTime"`
    23  	SpecialCollectionPointer *IRODSMessageSpecialCollection `xml:"SpecColl_PI"`
    24  	// stores error return
    25  	Result int `xml:"-"`
    26  }
    27  
    28  // GetBytes returns byte array
    29  func (msg *IRODSMessageGetDataObjectStatResponse) GetBytes() ([]byte, error) {
    30  	xmlBytes, err := xml.Marshal(msg)
    31  	if err != nil {
    32  		return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err)
    33  	}
    34  	return xmlBytes, nil
    35  }
    36  
    37  // CheckError returns error if server returned an error
    38  func (msg *IRODSMessageGetDataObjectStatResponse) CheckError() error {
    39  	if msg.Result < 0 {
    40  		return types.NewIRODSError(common.ErrorCode(msg.Result))
    41  	}
    42  	return nil
    43  }
    44  
    45  // FromBytes returns struct from bytes
    46  func (msg *IRODSMessageGetDataObjectStatResponse) FromBytes(bytes []byte) error {
    47  	err := xml.Unmarshal(bytes, msg)
    48  	if err != nil {
    49  		return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err)
    50  	}
    51  	return nil
    52  }
    53  
    54  // FromMessage returns struct from IRODSMessage
    55  func (msg *IRODSMessageGetDataObjectStatResponse) FromMessage(msgIn *IRODSMessage) error {
    56  	if msgIn.Body == nil {
    57  		return xerrors.Errorf("empty message body")
    58  	}
    59  
    60  	err := msg.FromBytes(msgIn.Body.Message)
    61  	msg.Result = int(msgIn.Body.IntInfo)
    62  	if err != nil {
    63  		return xerrors.Errorf("failed to get irods message from message body")
    64  	}
    65  	return nil
    66  }