-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_req_get_info.go
149 lines (115 loc) · 4.61 KB
/
datastore_req_get_info.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Package types implements all the types used by the DataStore protocol
package types
import (
"bytes"
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
)
// DataStoreReqGetInfo is sent in the PrepareGetObject method
type DataStoreReqGetInfo struct {
nex.Structure
URL string
RequestHeaders []*DataStoreKeyValue
Size uint32
RootCACert []byte
DataID uint64 // NEX 3.5.0+
}
// Bytes encodes the DataStoreReqGetInfo and returns a byte array
func (dataStoreReqGetInfo *DataStoreReqGetInfo) Bytes(stream *nex.StreamOut) []byte {
datastoreVersion := stream.Server.DataStoreProtocolVersion()
stream.WriteString(dataStoreReqGetInfo.URL)
stream.WriteListStructure(dataStoreReqGetInfo.RequestHeaders)
stream.WriteUInt32LE(dataStoreReqGetInfo.Size)
stream.WriteBuffer(dataStoreReqGetInfo.RootCACert)
if datastoreVersion.GreaterOrEqual("3.5.0") {
stream.WriteUInt64LE(dataStoreReqGetInfo.DataID)
}
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreReqGetInfo
func (dataStoreReqGetInfo *DataStoreReqGetInfo) Copy() nex.StructureInterface {
copied := NewDataStoreReqGetInfo()
copied.SetStructureVersion(dataStoreReqGetInfo.StructureVersion())
copied.URL = dataStoreReqGetInfo.URL
copied.RequestHeaders = make([]*DataStoreKeyValue, len(dataStoreReqGetInfo.RequestHeaders))
for i := 0; i < len(dataStoreReqGetInfo.RequestHeaders); i++ {
copied.RequestHeaders[i] = dataStoreReqGetInfo.RequestHeaders[i].Copy().(*DataStoreKeyValue)
}
copied.Size = dataStoreReqGetInfo.Size
copied.RootCACert = make([]byte, len(dataStoreReqGetInfo.RootCACert))
copy(copied.RootCACert, dataStoreReqGetInfo.RootCACert)
copied.DataID = dataStoreReqGetInfo.DataID
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreReqGetInfo *DataStoreReqGetInfo) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreReqGetInfo)
if dataStoreReqGetInfo.StructureVersion() != other.StructureVersion() {
return false
}
if dataStoreReqGetInfo.URL != other.URL {
return false
}
if len(dataStoreReqGetInfo.RequestHeaders) != len(other.RequestHeaders) {
return false
}
for i := 0; i < len(dataStoreReqGetInfo.RequestHeaders); i++ {
if !dataStoreReqGetInfo.RequestHeaders[i].Equals(other.RequestHeaders[i]) {
return false
}
}
if dataStoreReqGetInfo.Size != other.Size {
return false
}
if !bytes.Equal(dataStoreReqGetInfo.RootCACert, other.RootCACert) {
return false
}
if dataStoreReqGetInfo.DataID != other.DataID {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStoreReqGetInfo *DataStoreReqGetInfo) String() string {
return dataStoreReqGetInfo.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreReqGetInfo *DataStoreReqGetInfo) FormatToString(indentationLevel int) string {
indentationValues := strings.Repeat("\t", indentationLevel+1)
indentationListValues := strings.Repeat("\t", indentationLevel+2)
indentationEnd := strings.Repeat("\t", indentationLevel)
var b strings.Builder
b.WriteString("DataStoreReqGetInfo{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreReqGetInfo.StructureVersion()))
b.WriteString(fmt.Sprintf("%sURL: %q,\n", indentationValues, dataStoreReqGetInfo.URL))
if len(dataStoreReqGetInfo.RequestHeaders) == 0 {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [],\n", indentationValues))
} else {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [\n", indentationValues))
for i := 0; i < len(dataStoreReqGetInfo.RequestHeaders); i++ {
str := dataStoreReqGetInfo.RequestHeaders[i].FormatToString(indentationLevel + 2)
if i == len(dataStoreReqGetInfo.RequestHeaders)-1 {
b.WriteString(fmt.Sprintf("%s%s\n", indentationListValues, str))
} else {
b.WriteString(fmt.Sprintf("%s%s,\n", indentationListValues, str))
}
}
b.WriteString(fmt.Sprintf("%s],\n", indentationValues))
}
b.WriteString(fmt.Sprintf("%sSize: %d,\n", indentationValues, dataStoreReqGetInfo.Size))
b.WriteString(fmt.Sprintf("%sRootCA: %x,\n", indentationValues, dataStoreReqGetInfo.RootCACert))
b.WriteString(fmt.Sprintf("%sDataID: %d\n", indentationValues, dataStoreReqGetInfo.DataID))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreReqGetInfo returns a new DataStoreReqGetInfo
func NewDataStoreReqGetInfo() *DataStoreReqGetInfo {
return &DataStoreReqGetInfo{
URL: "",
RequestHeaders: make([]*DataStoreKeyValue, 0),
Size: 0,
RootCACert: make([]byte, 0),
DataID: 0,
}
}