go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/bind/bind.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 bind contains the structures describing bind request and response.
     6  package bind // import "go-hep.org/x/hep/xrootd/xrdproto/bind"
     7  
     8  import (
     9  	"go-hep.org/x/hep/xrootd/internal/xrdenc"
    10  	"go-hep.org/x/hep/xrootd/xrdproto"
    11  )
    12  
    13  // RequestID is the id of the request, it is sent as part of message.
    14  // See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format.
    15  const RequestID uint16 = 3024
    16  
    17  // Request holds the bind request parameters.
    18  type Request struct {
    19  	SessionID [16]byte // SessionID is the session identifier returned by login request.
    20  	_         int32
    21  }
    22  
    23  // ReqID implements xrdproto.Request.ReqID.
    24  func (req *Request) ReqID() uint16 { return RequestID }
    25  
    26  // ShouldSign implements xrdproto.Request.ShouldSign.
    27  func (req *Request) ShouldSign() bool { return false }
    28  
    29  // MarshalXrd implements xrdproto.Marshaler.
    30  func (o Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
    31  	wBuffer.WriteBytes(o.SessionID[:])
    32  	wBuffer.Next(4)
    33  	return nil
    34  }
    35  
    36  // UnmarshalXrd implements xrdproto.Unmarshaler.
    37  func (o *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
    38  	rBuffer.ReadBytes(o.SessionID[:])
    39  	rBuffer.Skip(4)
    40  	return nil
    41  }
    42  
    43  // Response is a response for the bind request, which contains the path id.
    44  type Response struct {
    45  	PathID xrdproto.PathID
    46  }
    47  
    48  // RespID implements xrdproto.Response.RespID.
    49  func (resp *Response) RespID() uint16 { return RequestID }
    50  
    51  // MarshalXrd implements xrdproto.Marshaler.
    52  func (o Response) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
    53  	wBuffer.WriteU8(uint8(o.PathID))
    54  	return nil
    55  }
    56  
    57  // UnmarshalXrd implements xrdproto.Unmarshaler.
    58  func (o *Response) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
    59  	o.PathID = xrdproto.PathID(rBuffer.ReadU8())
    60  	return nil
    61  }