go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/handshake/handshake.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 handshake contains the structures describing request and response
     6  // for handshake request (see XRootD specification).
     7  package handshake // import "go-hep.org/x/hep/xrootd/xrdproto/handshake"
     8  
     9  import (
    10  	"go-hep.org/x/hep/xrootd/internal/xrdenc"
    11  	"go-hep.org/x/hep/xrootd/xrdproto"
    12  )
    13  
    14  // Response is a response for the handshake request,
    15  // which contains protocol version and server type.
    16  type Response struct {
    17  	ProtocolVersion int32
    18  	ServerType      xrdproto.ServerType
    19  }
    20  
    21  // MarshalXrd implements xrdproto.Marshaler
    22  func (o Response) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
    23  	wBuffer.WriteI32(o.ProtocolVersion)
    24  	wBuffer.WriteI32(int32(o.ServerType))
    25  	return nil
    26  }
    27  
    28  // UnmarshalXrd implements xrdproto.Unmarshaler
    29  func (o *Response) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
    30  	o.ProtocolVersion = rBuffer.ReadI32()
    31  	o.ServerType = xrdproto.ServerType(rBuffer.ReadI32())
    32  	return nil
    33  }
    34  
    35  // RequestLength is the length of the Request in bytes.
    36  const RequestLength = 20
    37  
    38  // Request holds the handshake request parameters.
    39  type Request [5]int32
    40  
    41  // NewRequest forms a Request that complies with the XRootD protocol v3.1.0.
    42  func NewRequest() Request {
    43  	return Request{0, 0, 0, 4, 2012}
    44  }
    45  
    46  // MarshalXrd implements xrdproto.Marshaler
    47  func (o Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
    48  	wBuffer.WriteI32(o[0])
    49  	wBuffer.WriteI32(o[1])
    50  	wBuffer.WriteI32(o[2])
    51  	wBuffer.WriteI32(o[3])
    52  	wBuffer.WriteI32(o[4])
    53  	return nil
    54  }
    55  
    56  // UnmarshalXrd implements xrdproto.Unmarshaler
    57  func (o *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
    58  	o[0] = rBuffer.ReadI32()
    59  	o[1] = rBuffer.ReadI32()
    60  	o[2] = rBuffer.ReadI32()
    61  	o[3] = rBuffer.ReadI32()
    62  	o[4] = rBuffer.ReadI32()
    63  	return nil
    64  }