-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_req_get_info_v1.go
163 lines (126 loc) · 5.25 KB
/
datastore_req_get_info_v1.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
// Package types implements all the types used by the DataStore protocol
package types
import (
"bytes"
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
)
// DataStoreReqGetInfoV1 is a data structure used by the DataStore protocol
type DataStoreReqGetInfoV1 struct {
nex.Structure
URL string
RequestHeaders []*DataStoreKeyValue
Size uint32
RootCACert []byte
}
// ExtractFromStream extracts a DataStoreReqGetInfoV1 structure from a stream
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) ExtractFromStream(stream *nex.StreamIn) error {
var err error
dataStoreReqGetInfoV1.URL, err = stream.ReadString()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.URL. %s", err.Error())
}
requestHeaders, err := stream.ReadListStructure(NewDataStoreKeyValue())
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.RequestHeaders. %s", err.Error())
}
dataStoreReqGetInfoV1.RequestHeaders = requestHeaders.([]*DataStoreKeyValue)
dataStoreReqGetInfoV1.Size, err = stream.ReadUInt32LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.Size. %s", err.Error())
}
dataStoreReqGetInfoV1.RootCACert, err = stream.ReadBuffer()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.RootCACert. %s", err.Error())
}
return nil
}
// Bytes encodes the DataStoreReqGetInfoV1 and returns a byte array
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) Bytes(stream *nex.StreamOut) []byte {
stream.WriteString(dataStoreReqGetInfoV1.URL)
stream.WriteListStructure(dataStoreReqGetInfoV1.RequestHeaders)
stream.WriteUInt32LE(dataStoreReqGetInfoV1.Size)
stream.WriteBuffer(dataStoreReqGetInfoV1.RootCACert)
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreReqGetInfoV1
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) Copy() nex.StructureInterface {
copied := NewDataStoreReqGetInfoV1()
copied.SetStructureVersion(dataStoreReqGetInfoV1.StructureVersion())
copied.URL = dataStoreReqGetInfoV1.URL
copied.RequestHeaders = make([]*DataStoreKeyValue, len(dataStoreReqGetInfoV1.RequestHeaders))
for i := 0; i < len(dataStoreReqGetInfoV1.RequestHeaders); i++ {
copied.RequestHeaders[i] = dataStoreReqGetInfoV1.RequestHeaders[i].Copy().(*DataStoreKeyValue)
}
copied.Size = dataStoreReqGetInfoV1.Size
copied.RootCACert = make([]byte, len(dataStoreReqGetInfoV1.RootCACert))
copy(copied.RootCACert, dataStoreReqGetInfoV1.RootCACert)
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreReqGetInfoV1)
if dataStoreReqGetInfoV1.StructureVersion() != other.StructureVersion() {
return false
}
if dataStoreReqGetInfoV1.URL != other.URL {
return false
}
if len(dataStoreReqGetInfoV1.RequestHeaders) != len(other.RequestHeaders) {
return false
}
for i := 0; i < len(dataStoreReqGetInfoV1.RequestHeaders); i++ {
if dataStoreReqGetInfoV1.RequestHeaders[i] != other.RequestHeaders[i] {
return false
}
}
if dataStoreReqGetInfoV1.Size != other.Size {
return false
}
if !bytes.Equal(dataStoreReqGetInfoV1.RootCACert, other.RootCACert) {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) String() string {
return dataStoreReqGetInfoV1.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreReqGetInfoV1 *DataStoreReqGetInfoV1) 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("DataStoreReqGetInfoV1{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreReqGetInfoV1.StructureVersion()))
b.WriteString(fmt.Sprintf("%sURL: %q,\n", indentationValues, dataStoreReqGetInfoV1.URL))
if len(dataStoreReqGetInfoV1.RequestHeaders) == 0 {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [],\n", indentationValues))
} else {
b.WriteString(fmt.Sprintf("%sRequestHeaders: [\n", indentationValues))
for i := 0; i < len(dataStoreReqGetInfoV1.RequestHeaders); i++ {
str := dataStoreReqGetInfoV1.RequestHeaders[i].FormatToString(indentationLevel + 2)
if i == len(dataStoreReqGetInfoV1.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, dataStoreReqGetInfoV1.Size))
b.WriteString(fmt.Sprintf("%sRootCACert: %x\n", indentationValues, dataStoreReqGetInfoV1.RootCACert))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreReqGetInfoV1 returns a new DataStoreReqGetInfoV1
func NewDataStoreReqGetInfoV1() *DataStoreReqGetInfoV1 {
return &DataStoreReqGetInfoV1{
URL: "",
RequestHeaders: make([]*DataStoreKeyValue, 0),
Size: 0,
RootCACert: make([]byte, 0),
}
}