-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_rating_info.go
115 lines (89 loc) · 3.53 KB
/
datastore_rating_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"
)
// DataStoreRatingInfo is a data structure used by the DataStore protocol
type DataStoreRatingInfo struct {
nex.Structure
TotalValue int64
Count uint32
InitialValue int64
}
// ExtractFromStream extracts a DataStoreRatingInfo structure from a stream
func (dataStoreRatingInfo *DataStoreRatingInfo) ExtractFromStream(stream *nex.StreamIn) error {
var err error
dataStoreRatingInfo.TotalValue, err = stream.ReadInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreRatingInfo.TotalValue. %s", err.Error())
}
dataStoreRatingInfo.Count, err = stream.ReadUInt32LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreRatingInfo.Count. %s", err.Error())
}
dataStoreRatingInfo.InitialValue, err = stream.ReadInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreRatingInfo.InitialValue. %s", err.Error())
}
return nil
}
// Bytes encodes the DataStoreRatingInfo and returns a byte array
func (dataStoreRatingInfo *DataStoreRatingInfo) Bytes(stream *nex.StreamOut) []byte {
stream.WriteUInt64LE(uint64(dataStoreRatingInfo.TotalValue))
stream.WriteUInt32LE(dataStoreRatingInfo.Count)
stream.WriteUInt64LE(uint64(dataStoreRatingInfo.InitialValue))
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreRatingInfo
func (dataStoreRatingInfo *DataStoreRatingInfo) Copy() nex.StructureInterface {
copied := NewDataStoreRatingInfo()
copied.SetStructureVersion(dataStoreRatingInfo.StructureVersion())
copied.TotalValue = dataStoreRatingInfo.TotalValue
copied.Count = dataStoreRatingInfo.Count
copied.InitialValue = dataStoreRatingInfo.InitialValue
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreRatingInfo *DataStoreRatingInfo) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreRatingInfo)
if dataStoreRatingInfo.StructureVersion() != other.StructureVersion() {
return false
}
if dataStoreRatingInfo.TotalValue != other.TotalValue {
return false
}
if dataStoreRatingInfo.Count != other.Count {
return false
}
if dataStoreRatingInfo.InitialValue != other.InitialValue {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStoreRatingInfo *DataStoreRatingInfo) String() string {
return dataStoreRatingInfo.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreRatingInfo *DataStoreRatingInfo) FormatToString(indentationLevel int) string {
indentationValues := strings.Repeat("\t", indentationLevel+1)
indentationEnd := strings.Repeat("\t", indentationLevel)
var b strings.Builder
b.WriteString("DataStoreRatingInfo{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreRatingInfo.StructureVersion()))
b.WriteString(fmt.Sprintf("%sTotalValue: %d,\n", indentationValues, dataStoreRatingInfo.TotalValue))
b.WriteString(fmt.Sprintf("%sCount: %d,\n", indentationValues, dataStoreRatingInfo.Count))
b.WriteString(fmt.Sprintf("%sInitialValue: %d\n", indentationValues, dataStoreRatingInfo.InitialValue))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreRatingInfo returns a new DataStoreRatingInfo
func NewDataStoreRatingInfo() *DataStoreRatingInfo {
return &DataStoreRatingInfo{
TotalValue: 0,
Count: 0,
InitialValue: 0,
}
}