/
write.go
86 lines (72 loc) · 2.42 KB
/
write.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package write contains the structures describing write request.
// See xrootd protocol specification (http://xrootd.org/doc/dev45/XRdv310.pdf, p. 124) for details.
package write // import "go-hep.org/x/hep/xrootd/xrdproto/write"
import (
"go-hep.org/x/hep/xrootd/internal/xrdenc"
"go-hep.org/x/hep/xrootd/xrdfs"
"go-hep.org/x/hep/xrootd/xrdproto"
)
// RequestID is the id of the request, it is sent as part of message.
// See xrootd protocol specification for details: http://xrootd.org/doc/dev45/XRdv310.pdf, 2.3 Client Request Format.
const RequestID uint16 = 3019
// Request holds write request parameters.
type Request struct {
Handle xrdfs.FileHandle
Offset int64
pathID xrdproto.PathID
_ [3]uint8
Data []uint8
}
// MarshalXrd implements xrdproto.Marshaler.
func (req Request) MarshalXrd(wBuffer *xrdenc.WBuffer) error {
wBuffer.WriteBytes(req.Handle[:])
wBuffer.WriteI64(req.Offset)
wBuffer.WriteU8(uint8(req.pathID))
wBuffer.Next(3)
wBuffer.WriteLen(len(req.Data))
// If we are using a non-zero path ID, then data goes to the other connection.
// Otherwise, marshal it.
if req.pathID == 0 {
wBuffer.WriteBytes(req.Data)
}
return nil
}
// UnmarshalXrd implements xrdproto.Unmarshaler.
func (req *Request) UnmarshalXrd(rBuffer *xrdenc.RBuffer) error {
rBuffer.ReadBytes(req.Handle[:])
req.Offset = rBuffer.ReadI64()
req.pathID = xrdproto.PathID(rBuffer.ReadU8())
rBuffer.Skip(3)
req.Data = make([]uint8, rBuffer.ReadLen())
rBuffer.ReadBytes(req.Data)
return nil
}
// ReqID implements xrdproto.Request.ReqID.
func (req *Request) ReqID() uint16 { return RequestID }
// ShouldSign implements xrdproto.Request.ShouldSign.
func (req *Request) ShouldSign() bool { return false }
// PathID implements xrdproto.DataRequest.PathID.
func (o *Request) PathID() xrdproto.PathID {
return o.pathID
}
// PathID implements xrdproto.DataRequest.SetPathID.
func (o *Request) SetPathID(pathID xrdproto.PathID) {
o.pathID = pathID
}
// PathID implements xrdproto.DataRequest.Direction.
func (o *Request) Direction() xrdproto.DataRequestDirection {
return xrdproto.DataRequestWrite
}
// PathID implements xrdproto.DataRequest.PathData.
func (o *Request) PathData() []byte {
if o.pathID != 0 {
return o.Data
}
return nil
}
var (
_ xrdproto.DataRequest = (*Request)(nil)
)