go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/query/query.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 query contains the types related to the query request. 6 // See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 79) for more details. 7 package query // import "go-hep.org/x/hep/xrootd/xrdproto/query" 8 9 import ( 10 "go-hep.org/x/hep/xrootd/internal/xrdenc" 11 "go-hep.org/x/hep/xrootd/xrdfs" 12 ) 13 14 // Query parameters. 15 const ( 16 Stats = 1 // Query server statistics 17 Prepare = 2 // Query prepare status 18 Checksum = 3 // Query file checksum 19 XAttr = 4 // Query file extended attributes 20 Space = 5 // Query server logical space statistics 21 CancelChecksum = 6 // Query file checksum cancellation 22 Config = 7 // Query server configuration 23 Visa = 8 // Query file visa attributes 24 Opaque1 = 16 // Query implementation-dependent information 25 Opaque2 = 32 // Query implementation-dependent information 26 Opaque3 = 64 // Query implementation-dependent information 27 ) 28 29 // RequestID is the id of the request, it is sent as part of message. 30 // See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format. 31 const RequestID uint16 = 3001 32 33 // Request holds the query request parameters. 34 type Request struct { 35 Query uint16 36 _ [2]byte 37 Handle xrdfs.FileHandle 38 _ [8]byte 39 Args []byte 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 (*Request) ShouldSign() bool { return false } 47 48 // MarshalXrd implements xrdproto.Marshaler. 49 func (o Request) MarshalXrd(w *xrdenc.WBuffer) error { 50 w.WriteU16(o.Query) 51 w.Next(2) 52 w.WriteBytes(o.Handle[:]) 53 w.Next(8) 54 w.WriteI32(int32(len(o.Args))) 55 w.WriteBytes(o.Args) 56 return nil 57 } 58 59 // UnmarshalXrd implements xrdproto.Unmarshaler. 60 func (o *Request) UnmarshalXrd(r *xrdenc.RBuffer) error { 61 o.Query = r.ReadU16() 62 r.Skip(2) 63 r.ReadBytes(o.Handle[:]) 64 r.Skip(8) 65 n := r.ReadI32() 66 if n > 0 { 67 o.Args = make([]byte, n) 68 r.ReadBytes(o.Args) 69 } 70 return nil 71 } 72 73 // Response is the response issued by the server to a query request. 74 type Response struct { 75 Data []byte 76 } 77 78 // RespID implements xrdproto.Response.RespID. 79 func (*Response) RespID() uint16 { return RequestID } 80 81 // MarshalXrd implements xrdproto.Marshaler. 82 func (o Response) MarshalXrd(w *xrdenc.WBuffer) error { 83 w.WriteBytes(o.Data) 84 return nil 85 } 86 87 // UnmarshalXrd implements xrdproto.Unmarshaler. 88 func (o *Response) UnmarshalXrd(r *xrdenc.RBuffer) error { 89 o.Data = make([]byte, r.Len()) 90 r.ReadBytes(o.Data) 91 return nil 92 }