go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/locate/locate.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 locate contains the types related to the locate request.
     6  // See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 51) for more details.
     7  package locate // import "go-hep.org/x/hep/xrootd/xrdproto/locate"
     8  
     9  import (
    10  	"go-hep.org/x/hep/xrootd/internal/xrdenc"
    11  )
    12  
    13  // locate options.
    14  const (
    15  	AddPeers   = 1 << 0  // AddPeers adds eligible peers to the location output
    16  	Refresh    = 1 << 7  // Refresh updates cached information on the file’s location
    17  	PreferName = 1 << 8  // PreferName indicates a hostname response is preferred
    18  	NoWait     = 1 << 13 // NoWait provides informations as soon as possible
    19  )
    20  
    21  // RequestID is the id of the request, it is sent as part of message.
    22  // See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format.
    23  const RequestID uint16 = 3027
    24  
    25  // Request holds the locate request parameters.
    26  type Request struct {
    27  	Options uint16 // Options to apply when Path is opened
    28  	_       [14]byte
    29  	Path    string // Path of the file to locate
    30  }
    31  
    32  // ReqID implements xrdproto.Request.ReqID.
    33  func (req *Request) ReqID() uint16 { return RequestID }
    34  
    35  // ShouldSign implements xrdproto.Request.ShouldSign.
    36  func (*Request) ShouldSign() bool { return false }
    37  
    38  // MarshalXrd implements xrdproto.Marshaler.
    39  func (o Request) MarshalXrd(w *xrdenc.WBuffer) error {
    40  	w.WriteU16(o.Options)
    41  	w.Next(14)
    42  	w.WriteStr(o.Path)
    43  	return nil
    44  }
    45  
    46  // UnmarshalXrd implements xrdproto.Unmarshaler.
    47  func (o *Request) UnmarshalXrd(r *xrdenc.RBuffer) error {
    48  	o.Options = r.ReadU16()
    49  	r.Skip(14)
    50  	o.Path = r.ReadStr()
    51  	return nil
    52  }
    53  
    54  // Response is the response issued by the server to a locate request.
    55  type Response struct {
    56  	Data []byte
    57  }
    58  
    59  // RespID implements xrdproto.Response.RespID.
    60  func (*Response) RespID() uint16 { return RequestID }
    61  
    62  // MarshalXrd implements xrdproto.Marshaler.
    63  func (o Response) MarshalXrd(w *xrdenc.WBuffer) error {
    64  	w.WriteBytes(o.Data)
    65  	return nil
    66  }
    67  
    68  // UnmarshalXrd implements xrdproto.Unmarshaler.
    69  func (o *Response) UnmarshalXrd(r *xrdenc.RBuffer) error {
    70  	o.Data = make([]byte, r.Len())
    71  	r.ReadBytes(o.Data)
    72  	return nil
    73  }