-
Notifications
You must be signed in to change notification settings - Fork 13
/
datastore_attach_file_param.go
124 lines (95 loc) · 4.32 KB
/
datastore_attach_file_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
// Package types implements all the types used by the DataStore (Super Mario Maker) protocol
package types
import (
"fmt"
"strings"
"github.com/PretendoNetwork/nex-go"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
)
// DataStoreAttachFileParam holds data for the DataStore (Super Mario Maker) protocol
type DataStoreAttachFileParam struct {
nex.Structure
PostParam *datastore_types.DataStorePreparePostParam
ReferDataID uint64
ContentType string
}
// ExtractFromStream extracts a DataStoreAttachFileParam structure from a stream
func (dataStoreAttachFileParam *DataStoreAttachFileParam) ExtractFromStream(stream *nex.StreamIn) error {
var err error
postParam, err := stream.ReadStructure(datastore_types.NewDataStorePreparePostParam())
if err != nil {
return fmt.Errorf("Failed to extract DataStoreAttachFileParam.PostParam from stream. %s", err.Error())
}
dataStoreAttachFileParam.PostParam = postParam.(*datastore_types.DataStorePreparePostParam)
dataStoreAttachFileParam.ReferDataID, err = stream.ReadUInt64LE()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreAttachFileParam.ReferDataID from stream. %s", err.Error())
}
dataStoreAttachFileParam.ContentType, err = stream.ReadString()
if err != nil {
return fmt.Errorf("Failed to extract DataStoreAttachFileParam.ContentType from stream. %s", err.Error())
}
return nil
}
// Bytes encodes the DataStoreAttachFileParam and returns a byte array
func (dataStoreAttachFileParam *DataStoreAttachFileParam) Bytes(stream *nex.StreamOut) []byte {
stream.WriteStructure(dataStoreAttachFileParam.PostParam)
stream.WriteUInt64LE(dataStoreAttachFileParam.ReferDataID)
stream.WriteString(dataStoreAttachFileParam.ContentType)
return stream.Bytes()
}
// Copy returns a new copied instance of DataStoreAttachFileParam
func (dataStoreAttachFileParam *DataStoreAttachFileParam) Copy() nex.StructureInterface {
copied := NewDataStoreAttachFileParam()
copied.SetStructureVersion(dataStoreAttachFileParam.StructureVersion())
copied.PostParam = dataStoreAttachFileParam.PostParam.Copy().(*datastore_types.DataStorePreparePostParam)
copied.ReferDataID = dataStoreAttachFileParam.ReferDataID
copied.ContentType = dataStoreAttachFileParam.ContentType
return copied
}
// Equals checks if the passed Structure contains the same data as the current instance
func (dataStoreAttachFileParam *DataStoreAttachFileParam) Equals(structure nex.StructureInterface) bool {
other := structure.(*DataStoreAttachFileParam)
if dataStoreAttachFileParam.StructureVersion() != other.StructureVersion() {
return false
}
if !dataStoreAttachFileParam.PostParam.Equals(other.PostParam) {
return false
}
if dataStoreAttachFileParam.ReferDataID != other.ReferDataID {
return false
}
if dataStoreAttachFileParam.ContentType != other.ContentType {
return false
}
return true
}
// String returns a string representation of the struct
func (dataStoreAttachFileParam *DataStoreAttachFileParam) String() string {
return dataStoreAttachFileParam.FormatToString(0)
}
// FormatToString pretty-prints the struct data using the provided indentation level
func (dataStoreAttachFileParam *DataStoreAttachFileParam) FormatToString(indentationLevel int) string {
indentationValues := strings.Repeat("\t", indentationLevel+1)
indentationEnd := strings.Repeat("\t", indentationLevel)
var b strings.Builder
b.WriteString("DataStoreAttachFileParam{\n")
b.WriteString(fmt.Sprintf("%sstructureVersion: %d,\n", indentationValues, dataStoreAttachFileParam.StructureVersion()))
if dataStoreAttachFileParam.PostParam != nil {
b.WriteString(fmt.Sprintf("%sPostParam: %s\n", indentationValues, dataStoreAttachFileParam.PostParam.FormatToString(indentationLevel+1)))
} else {
b.WriteString(fmt.Sprintf("%sPostParam: nil\n", indentationValues))
}
b.WriteString(fmt.Sprintf("%sReferDataID: %d,\n", indentationValues, dataStoreAttachFileParam.ReferDataID))
b.WriteString(fmt.Sprintf("%sContentType: %q,\n", indentationValues, dataStoreAttachFileParam.ContentType))
b.WriteString(fmt.Sprintf("%s}", indentationEnd))
return b.String()
}
// NewDataStoreAttachFileParam returns a new DataStoreAttachFileParam
func NewDataStoreAttachFileParam() *DataStoreAttachFileParam {
return &DataStoreAttachFileParam{
PostParam: datastore_types.NewDataStorePreparePostParam(),
ReferDataID: 0,
ContentType: "",
}
}