go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/truncate/truncate.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 truncate contains the structures describing truncate request. 6 // See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 121) for details. 7 package truncate // import "go-hep.org/x/hep/xrootd/xrdproto/truncate" 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 = 3028 18 19 // Request holds truncate request parameters. 20 // Either the Handle or the Path should be specified to identify the file. 21 type Request struct { 22 Handle xrdfs.FileHandle 23 Size int64 24 _ [4]uint8 25 Path string 26 } 27 28 // MarshalXrd implements xrdproto.Marshaler. 29 func (req Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error { 30 wBuffer.WriteBytes(req.Handle[:]) 31 wBuffer.WriteI64(req.Size) 32 wBuffer.Next(4) 33 wBuffer.WriteStr(req.Path) 34 return nil 35 } 36 37 // UnmarshalXrd implements xrdproto.Unmarshaler. 38 func (req *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error { 39 rBuffer.ReadBytes(req.Handle[:]) 40 req.Size = rBuffer.ReadI64() 41 rBuffer.Skip(4) 42 req.Path = rBuffer.ReadStr() 43 return nil 44 } 45 46 // ReqID implements xrdproto.Request.ReqID. 47 func (req *Request) ReqID() uint16 { return RequestID } 48 49 // ShouldSign implements xrdproto.Request.ShouldSign. 50 func (req *Request) ShouldSign() bool { return false } 51 52 // Opaque implements xrdproto.FilepathRequest.Opaque. 53 func (req *Request) Opaque() string { 54 return xrdproto.Opaque(req.Path) 55 } 56 57 // SetOpaque implements xrdproto.FilepathRequest.SetOpaque. 58 func (req *Request) SetOpaque(opaque string) { 59 // Opaque is only required if path was specified. 60 if len(req.Path) == 0 { 61 return 62 } 63 xrdproto.SetOpaque(&req.Path, opaque) 64 }