-
Notifications
You must be signed in to change notification settings - Fork 13
/
prepare_get_object_v1.go
47 lines (36 loc) · 1.55 KB
/
prepare_get_object_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
// Package protocol implements the DataStore protocol
package protocol
import (
"fmt"
nex "github.com/PretendoNetwork/nex-go"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
"github.com/PretendoNetwork/nex-protocols-go/globals"
)
// PrepareGetObjectV1 sets the PrepareGetObjectV1 handler function
func (protocol *Protocol) PrepareGetObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParamV1) uint32) {
protocol.prepareGetObjectV1Handler = handler
}
func (protocol *Protocol) handlePrepareGetObjectV1(packet nex.PacketInterface) {
var errorCode uint32
if protocol.prepareGetObjectV1Handler == nil {
globals.Logger.Warning("DataStore::PrepareGetObjectV1 not implemented")
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented)
return
}
request := packet.RMCRequest()
callID := request.CallID()
parameters := request.Parameters()
parametersStream := nex.NewStreamIn(parameters, protocol.Server)
param, err := parametersStream.ReadStructure(datastore_types.NewDataStorePrepareGetParamV1())
if err != nil {
errorCode = protocol.prepareGetObjectV1Handler(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
return
}
errorCode = protocol.prepareGetObjectV1Handler(nil, packet, callID, param.(*datastore_types.DataStorePrepareGetParamV1))
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
}