-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathother.go
More file actions
26 lines (21 loc) · 712 Bytes
/
Copy pathother.go
File metadata and controls
26 lines (21 loc) · 712 Bytes
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
package jrm1
import (
"bytes"
"encoding/json"
)
// ParseParameters parses JSON bytes into an object representing parameters of
// called RPC method (function, procedure). This function must be called at the
// beginning of each RPC function to get parameters. Unfortunately, Go language
// can not do it automatically due to its technical limits.
func ParseParameters(params *json.RawMessage, dst any) (re *RpcError) {
if params == nil {
return NewRpcErrorFast(RpcErrorCode_InvalidParameters)
}
decoder := json.NewDecoder(bytes.NewReader(*params))
decoder.DisallowUnknownFields()
err := decoder.Decode(dst)
if err != nil {
return NewRpcErrorFast(RpcErrorCode_InvalidParameters)
}
return nil
}