-
Notifications
You must be signed in to change notification settings - Fork 12
/
datastore_req_post_info.go
166 lines (130 loc) · 5.44 KB
/
datastore_req_post_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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Package types implements all the types used by the DataStore protocol
package types
import (
"bytes"
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
)
// DataStoreReqPostInfo is sent in the PreparePostObject method
type DataStoreReqPostInfo struct {
nex.Structure
DataID uint64
URL string
RequestHeaders []*DataStoreKeyValue
FormFields []*DataStoreKeyValue
RootCACert []byte
}
// Bytes encodes the DataStoreReqPostInfo and returns a byte array
func (dataStoreReqPostInfo *DataStoreReqPostInfo) Bytes(stream *nex.StreamOut) []byte {
stream.WriteUInt64LE(dataStoreReqPostInfo.DataID)
stream.WriteString(dataStoreReqPostInfo.URL)
stream.WriteListStructure(dataStoreReqPostInfo.RequestHeaders)
stream.WriteListStructure(dataStoreReqPostInfo.FormFields)
stream.WriteBuffer(dataStoreReqPostInfo.RootCACert)
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreReqPostInfo
func (dataStoreReqPostInfo *DataStoreReqPostInfo) Copy() nex.StructureInterface {
copied := NewDataStoreReqPostInfo()
copied.SetStructureVersion(dataStoreReqPostInfo.StructureVersion())
copied.DataID = dataStoreReqPostInfo.DataID
copied.URL = dataStoreReqPostInfo.URL
copied.RequestHeaders = make([]*DataStoreKeyValue, len(dataStoreReqPostInfo.RequestHeaders))
for i := 0; i < len(dataStoreReqPostInfo.RequestHeaders); i++ {
copied.RequestHeaders[i] = dataStoreReqPostInfo.RequestHeaders[i].Copy().(*DataStoreKeyValue)
}
copied.FormFields = make([]*DataStoreKeyValue, len(dataStoreReqPostInfo.FormFields))
for i := 0; i < len(dataStoreReqPostInfo.FormFields); i++ {
copied.FormFields[i] = dataStoreReqPostInfo.FormFields[i].Copy().(*DataStoreKeyValue)
}
copied.RootCACert = make([]byte, len(dataStoreReqPostInfo.RootCACert))
copy(copied.RootCACert, dataStoreReqPostInfo.RootCACert)
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreReqPostInfo *DataStoreReqPostInfo) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreReqPostInfo)
if dataStoreReqPostInfo.StructureVersion() != other.StructureVersion() {
return false
}
if dataStoreReqPostInfo.DataID != other.DataID {
return false
}
if dataStoreReqPostInfo.URL != other.URL {
return false
}
if len(dataStoreReqPostInfo.RequestHeaders) != len(other.RequestHeaders) {
return false
}
for i := 0; i < len(dataStoreReqPostInfo.RequestHeaders); i++ {
if dataStoreReqPostInfo.RequestHeaders[i] != other.RequestHeaders[i] {
return false
}
}
if len(dataStoreReqPostInfo.FormFields) != len(other.FormFields) {
return false
}
for i := 0; i < len(dataStoreReqPostInfo.FormFields); i++ {
if dataStoreReqPostInfo.FormFields[i] != other.FormFields[i] {
return false
}
}
return bytes.Equal(dataStoreReqPostInfo.RootCACert, other.RootCACert)
}
// String returns a string representation of the struct
func (dataStoreReqPostInfo *DataStoreReqPostInfo) String() string {
return dataStoreReqPostInfo.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreReqPostInfo *DataStoreReqPostInfo) 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("DataStoreReqPostInfo{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreReqPostInfo.StructureVersion()))
b.WriteString(fmt.Sprintf("%sDataID: %d,\n", indentationValues, dataStoreReqPostInfo.DataID))
b.WriteString(fmt.Sprintf("%sURL: %q,\n", indentationValues, dataStoreReqPostInfo.URL))
if len(dataStoreReqPostInfo.RequestHeaders) == 0 {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [],\n", indentationValues))
} else {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [\n", indentationValues))
for i := 0; i < len(dataStoreReqPostInfo.RequestHeaders); i++ {
str := dataStoreReqPostInfo.RequestHeaders[i].FormatToString(indentationLevel + 2)
if i == len(dataStoreReqPostInfo.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))
}
if len(dataStoreReqPostInfo.FormFields) == 0 {
b.WriteString(fmt.Sprintf("%sFormFields: [],\n", indentationValues))
} else {
b.WriteString(fmt.Sprintf("%sFormFields: [\n", indentationValues))
for i := 0; i < len(dataStoreReqPostInfo.FormFields); i++ {
str := dataStoreReqPostInfo.FormFields[i].FormatToString(indentationLevel + 2)
if i == len(dataStoreReqPostInfo.FormFields)-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("%sRootCACert: %x\n", indentationValues, dataStoreReqPostInfo.RootCACert))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreReqPostInfo returns a new DataStoreReqPostInfo
func NewDataStoreReqPostInfo() *DataStoreReqPostInfo {
return &DataStoreReqPostInfo{
DataID: 0,
URL: "",
RequestHeaders: make([]*DataStoreKeyValue, 0),
FormFields: make([]*DataStoreKeyValue, 0),
RootCACert: make([]byte, 0),
}
}