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