-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_complete_update_param.go
151 lines (117 loc) · 4.81 KB
/
datastore_complete_update_param.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
// Package types implements all the types used by the DataStore protocol
package types
import (
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
)
// DataStoreCompleteUpdateParam is a data structure used by the DataStore protocol
type DataStoreCompleteUpdateParam struct {
nex.Structure
DataID uint64
Version uint32
IsSuccess bool
}
// ExtractFromStream extracts a DataStoreCompleteUpdateParam structure from a stream
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) ExtractFromStream(stream *nex.StreamIn) error {
datastoreVersion := stream.Server.DataStoreProtocolVersion()
var err error
if datastoreVersion.GreaterOrEqual("3.0.0") {
dataID, err := stream.ReadUInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error())
}
dataStoreCompleteUpdateParam.DataID = dataID
} else {
dataID, err := stream.ReadUInt32LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error())
}
dataStoreCompleteUpdateParam.DataID = uint64(dataID)
}
if datastoreVersion.GreaterOrEqual("3.0.0") {
version, err := stream.ReadUInt32LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.Version. %s", err.Error())
}
dataStoreCompleteUpdateParam.Version = version
} else {
version, err := stream.ReadUInt16LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.Version. %s", err.Error())
}
dataStoreCompleteUpdateParam.Version = uint32(version)
}
dataStoreCompleteUpdateParam.IsSuccess, err = stream.ReadBool()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.IsSuccess. %s", err.Error())
}
return nil
}
// Bytes encodes the DataStoreCompleteUpdateParam and returns a byte array
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) Bytes(stream *nex.StreamOut) []byte {
datastoreVersion := stream.Server.DataStoreProtocolVersion()
if datastoreVersion.GreaterOrEqual("3.0.0") {
stream.WriteUInt64LE(dataStoreCompleteUpdateParam.DataID)
} else {
stream.WriteUInt32LE(uint32(dataStoreCompleteUpdateParam.DataID))
}
if datastoreVersion.GreaterOrEqual("3.0.0") {
stream.WriteUInt32LE(dataStoreCompleteUpdateParam.Version)
} else {
stream.WriteUInt16LE(uint16(dataStoreCompleteUpdateParam.Version))
}
stream.WriteBool(dataStoreCompleteUpdateParam.IsSuccess)
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreCompleteUpdateParam
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) Copy() nex.StructureInterface {
copied := NewDataStoreCompleteUpdateParam()
copied.SetStructureVersion(dataStoreCompleteUpdateParam.StructureVersion())
copied.DataID = dataStoreCompleteUpdateParam.DataID
copied.Version = dataStoreCompleteUpdateParam.Version
copied.IsSuccess = dataStoreCompleteUpdateParam.IsSuccess
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreCompleteUpdateParam)
if dataStoreCompleteUpdateParam.StructureVersion() != other.StructureVersion() {
return false
}
if dataStoreCompleteUpdateParam.DataID != other.DataID {
return false
}
if dataStoreCompleteUpdateParam.Version != other.Version {
return false
}
if dataStoreCompleteUpdateParam.IsSuccess != other.IsSuccess {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) String() string {
return dataStoreCompleteUpdateParam.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam) FormatToString(indentationLevel int) string {
indentationValues := strings.Repeat("\t", indentationLevel+1)
indentationEnd := strings.Repeat("\t", indentationLevel)
var b strings.Builder
b.WriteString("DataStoreCompleteUpdateParam{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreCompleteUpdateParam.StructureVersion()))
b.WriteString(fmt.Sprintf("%sDataID: %d,\n", indentationValues, dataStoreCompleteUpdateParam.DataID))
b.WriteString(fmt.Sprintf("%sVersion: %d,\n", indentationValues, dataStoreCompleteUpdateParam.Version))
b.WriteString(fmt.Sprintf("%sIsSuccess: %t\n", indentationValues, dataStoreCompleteUpdateParam.IsSuccess))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreCompleteUpdateParam returns a new DataStoreCompleteUpdateParam
func NewDataStoreCompleteUpdateParam() *DataStoreCompleteUpdateParam {
return &DataStoreCompleteUpdateParam{
DataID: 0,
Version: 0,
IsSuccess: false,
}
}