-
Notifications
You must be signed in to change notification settings - Fork 46
/
core_type.go
120 lines (92 loc) · 1.61 KB
/
core_type.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
package schema
import (
"bytes"
"encoding/json"
)
type CoreType int
const (
T_Unknown CoreType = iota
T_Null
T_Any
T_Byte
T_Bool
T_Uint
T_Uint8
T_Uint16
T_Uint32
T_Uint64
T_Int
T_Int8
T_Int16
T_Int32
T_Int64
T_Float32
T_Float64
T_String
T_Timestamp
T_List
T_Map
T_Struct // aka, a reference to our own webrpc struct type
)
var CoreTypeToString = map[CoreType]string{
T_Null: "null",
T_Any: "any",
T_Byte: "byte",
T_Bool: "bool",
T_Uint: "uint",
T_Uint8: "uint8",
T_Uint16: "uint16",
T_Uint32: "uint32",
T_Uint64: "uint64",
T_Int: "int",
T_Int8: "int8",
T_Int16: "int16",
T_Int32: "int32",
T_Int64: "int64",
T_Float32: "float32",
T_Float64: "float64",
T_String: "string",
T_Timestamp: "timestamp",
T_Map: "map",
T_List: "[]",
}
var CoreTypeFromString = map[string]CoreType{
"null": T_Null,
"any": T_Any,
"byte": T_Byte,
"bool": T_Bool,
"uint": T_Uint,
"uint8": T_Uint8,
"uint16": T_Uint16,
"uint32": T_Uint32,
"uint64": T_Uint64,
"int": T_Int,
"int8": T_Int8,
"int16": T_Int16,
"int32": T_Int32,
"int64": T_Int64,
"float32": T_Float32,
"float64": T_Float64,
"string": T_String,
"timestamp": T_Timestamp,
"map": T_Map,
"[]": T_List,
}
func (t CoreType) String() string {
return CoreTypeToString[t]
}
func (t CoreType) MarshalJSON() ([]byte, error) {
buf := bytes.NewBufferString(`"`)
buf.WriteString(CoreTypeToString[t])
buf.WriteString(`"`)
return buf.Bytes(), nil
}
func (t *CoreType) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
*t = CoreTypeFromString[j]
return nil
}