go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/chmod/chmod.go (about)

     1  // Copyright ©2018 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package chmod contains the structures describing chmod request.
     6  // See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 106) for details.
     7  package chmod // import "go-hep.org/x/hep/xrootd/xrdproto/chmod"
     8  
     9  import (
    10  	"go-hep.org/x/hep/xrootd/internal/xrdenc"
    11  	"go-hep.org/x/hep/xrootd/xrdfs"
    12  	"go-hep.org/x/hep/xrootd/xrdproto"
    13  )
    14  
    15  // RequestID is the id of the request, it is sent as part of message.
    16  // See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format.
    17  const RequestID uint16 = 3002
    18  
    19  // Request holds chmod request parameters, such as the directory path and the mode to be applied.
    20  type Request struct {
    21  	_    [14]byte
    22  	Mode xrdfs.OpenMode
    23  	Path string
    24  }
    25  
    26  // MarshalXrd implements xrdproto.Marshaler.
    27  func (o Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
    28  	wBuffer.Next(14)
    29  	wBuffer.WriteU16(uint16(o.Mode))
    30  	wBuffer.WriteStr(o.Path)
    31  	return nil
    32  }
    33  
    34  // UnmarshalXrd implements xrdproto.Unmarshaler.
    35  func (o *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
    36  	rBuffer.Skip(14)
    37  	o.Mode = xrdfs.OpenMode(rBuffer.ReadU16())
    38  	o.Path = rBuffer.ReadStr()
    39  	return nil
    40  }
    41  
    42  // ReqID implements xrdproto.Request.ReqID.
    43  func (req *Request) ReqID() uint16 { return RequestID }
    44  
    45  // ShouldSign implements xrdproto.Request.ShouldSign.
    46  func (req *Request) ShouldSign() bool { return false }
    47  
    48  // Opaque implements xrdproto.FilepathRequest.Opaque.
    49  func (req *Request) Opaque() string {
    50  	return xrdproto.Opaque(req.Path)
    51  }
    52  
    53  // SetOpaque implements xrdproto.FilepathRequest.SetOpaque.
    54  func (req *Request) SetOpaque(opaque string) {
    55  	xrdproto.SetOpaque(&req.Path, opaque)
    56  }