-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
executable file
·58 lines (47 loc) · 1.28 KB
/
common.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
// AUTOGENERATED - DO NOT EDIT
package tdlib
import (
"strconv"
"strings"
)
type tdCommon struct {
Type string `json:"@type"`
Extra string `json:"@extra"`
}
// TdMessage is the interface for all messages send and received to/from tdlib
type TdMessage interface {
MessageType() string
}
// RequestError represents an error returned from tdlib.
type RequestError struct {
Code int
Message string
}
func (re RequestError) Error() string {
return "error! code: " + strconv.FormatInt(int64(re.Code), 10) + " msg: " + re.Message
}
// JSONInt64 alias for int64, in order to deal with json big number problem
type JSONInt64 int64
// UpdateData alias for use in UpdateMsg
type UpdateData map[string]interface{}
// UpdateMsg is used to unmarshal received json strings into
type UpdateMsg struct {
Data UpdateData
Raw []byte
}
// MarshalJSON marshals to json
func (jsonInt *JSONInt64) MarshalJSON() ([]byte, error) {
intStr := strconv.FormatInt(int64(*jsonInt), 10)
return []byte(intStr), nil
}
// UnmarshalJSON unmarshals from json
func (jsonInt *JSONInt64) UnmarshalJSON(b []byte) error {
intStr := string(b)
intStr = strings.Replace(intStr, "\"", "", 2)
jsonBigInt, err := strconv.ParseInt(intStr, 10, 64)
if err != nil {
return err
}
*jsonInt = JSONInt64(jsonBigInt)
return nil
}