go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/statx/statx.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 statx contains the structures describing request and response for statx request. 6 // See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 113) for details. 7 // Note that only a limited number of flags is meaningful such as StatIsExecutable, StatIsDir, StatIsOther, StatIsOffline. 8 package statx // import "go-hep.org/x/hep/xrootd/xrdproto/statx" 9 10 import ( 11 "strings" 12 13 "go-hep.org/x/hep/xrootd/internal/xrdenc" 14 "go-hep.org/x/hep/xrootd/xrdfs" 15 ) 16 17 // RequestID is the id of the request, it is sent as part of message. 18 // See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format. 19 const RequestID uint16 = 3022 20 21 // Response is a response for the statx request which contains the information about every requested path. 22 // Note that only limited number of flags is meaningful such as StatIsExecutable, StatIsDir, StatIsOther, StatIsOffline. 23 type Response struct { 24 StatFlags []xrdfs.StatFlags 25 } 26 27 // RespID implements xrdproto.Response.RespID. 28 func (resp *Response) RespID() uint16 { return RequestID } 29 30 // MarshalXrd implements xrdproto.Marshaler. 31 func (o Response) MarshalXrd(wBuffer *xrdenc.WBuffer) error { 32 for _, x := range o.StatFlags { 33 wBuffer.WriteU8(uint8(x)) 34 } 35 return nil 36 } 37 38 // UnmarshalXrd implements xrdproto.Unmarshaler. 39 func (o *Response) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error { 40 o.StatFlags = make([]xrdfs.StatFlags, rBuffer.Len()) 41 for i := range o.StatFlags { 42 o.StatFlags[i] = xrdfs.StatFlags(rBuffer.ReadU8()) 43 } 44 return nil 45 } 46 47 // Request holds open request parameters. 48 type Request struct { 49 _ [16]uint8 50 Paths string // Paths is the new-line separated path list. 51 } 52 53 // NewRequest forms a Request according to provided paths. 54 func NewRequest(paths []string) *Request { 55 return &Request{Paths: strings.Join(paths, "\n")} 56 } 57 58 // MarshalXrd implements xrdproto.Marshaler. 59 func (o Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error { 60 wBuffer.Next(16) 61 wBuffer.WriteStr(o.Paths) 62 return nil 63 } 64 65 // UnmarshalXrd implements xrdproto.Unmarshaler. 66 func (o *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error { 67 rBuffer.Skip(16) 68 o.Paths = rBuffer.ReadStr() 69 return nil 70 } 71 72 // ReqID implements xrdproto.Request.ReqID. 73 func (req *Request) ReqID() uint16 { return RequestID } 74 75 // ShouldSign implements xrdproto.Request.ShouldSign. 76 func (req *Request) ShouldSign() bool { return false }