-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_password_info.go
115 lines (89 loc) · 3.68 KB
/
datastore_password_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
// Package types implements all the types used by the DataStore protocol
package types
import (
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
)
// DataStorePasswordInfo is a data structure used by the DataStore protocol
type DataStorePasswordInfo struct {
nex.Structure
DataID uint64
AccessPassword uint64
UpdatePassword uint64
}
// ExtractFromStream extracts a DataStorePasswordInfo structure from a stream
func (dataStorePasswordInfo *DataStorePasswordInfo) ExtractFromStream(stream *nex.StreamIn) error {
var err error
dataStorePasswordInfo.DataID, err = stream.ReadUInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStorePasswordInfo.DataID. %s", err.Error())
}
dataStorePasswordInfo.AccessPassword, err = stream.ReadUInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStorePasswordInfo.AccessPassword. %s", err.Error())
}
dataStorePasswordInfo.UpdatePassword, err = stream.ReadUInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStorePasswordInfo.UpdatePassword. %s", err.Error())
}
return nil
}
// Bytes encodes the DataStorePasswordInfo and returns a byte array
func (dataStorePasswordInfo *DataStorePasswordInfo) Bytes(stream *nex.StreamOut) []byte {
stream.WriteUInt64LE(dataStorePasswordInfo.DataID)
stream.WriteUInt64LE(dataStorePasswordInfo.AccessPassword)
stream.WriteUInt64LE(dataStorePasswordInfo.UpdatePassword)
return stream.Bytes()
}
// Copy returns a new copied instance of DataStorePasswordInfo
func (dataStorePasswordInfo *DataStorePasswordInfo) Copy() nex.StructureInterface {
copied := NewDataStorePasswordInfo()
copied.SetStructureVersion(dataStorePasswordInfo.StructureVersion())
copied.DataID = dataStorePasswordInfo.DataID
copied.AccessPassword = dataStorePasswordInfo.AccessPassword
copied.UpdatePassword = dataStorePasswordInfo.UpdatePassword
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStorePasswordInfo *DataStorePasswordInfo) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStorePasswordInfo)
if dataStorePasswordInfo.StructureVersion() != other.StructureVersion() {
return false
}
if dataStorePasswordInfo.DataID != other.DataID {
return false
}
if dataStorePasswordInfo.AccessPassword != other.AccessPassword {
return false
}
if dataStorePasswordInfo.UpdatePassword != other.UpdatePassword {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStorePasswordInfo *DataStorePasswordInfo) String() string {
return dataStorePasswordInfo.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStorePasswordInfo *DataStorePasswordInfo) FormatToString(indentationLevel int) string {
indentationValues := strings.Repeat("\t", indentationLevel+1)
indentationEnd := strings.Repeat("\t", indentationLevel)
var b strings.Builder
b.WriteString("DataStorePasswordInfo{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStorePasswordInfo.StructureVersion()))
b.WriteString(fmt.Sprintf("%sDataID: %d,\n", indentationValues, dataStorePasswordInfo.DataID))
b.WriteString(fmt.Sprintf("%sAccessPassword: %d,\n", indentationValues, dataStorePasswordInfo.AccessPassword))
b.WriteString(fmt.Sprintf("%sUpdatePassword: %d\n", indentationValues, dataStorePasswordInfo.UpdatePassword))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStorePasswordInfo returns a new DataStorePasswordInfo
func NewDataStorePasswordInfo() *DataStorePasswordInfo {
return &DataStorePasswordInfo{
DataID: 0,
AccessPassword: 0,
UpdatePassword: 0,
}
}