v2 / vlib / x / json2 / types.v
54 lines · 45 sloc · 992 bytes · 8986645ee93015bf9b44e7839c3a3370aff4f51b
Raw
1module json2
2
3import time
4
5@[markused]
6const any_time_type_marker = time.Time{}
7
8// Any is a sum type that lists the possible types to be decoded and used.
9// `Any` priority order for numbers: floats -> signed integers -> unsigned integers
10// `Any` priority order for strings: string -> time.Time
11
12@[markused]
13pub type Any = []Any
14 | bool
15 | f64
16 | f32
17 | i64
18 | int
19 | i32
20 | i16
21 | i8
22 | map[string]Any
23 | string
24 | time.Time
25 | u64
26 | u32
27 | u16
28 | u8
29 | Null
30
31// Null is a simple representation of the `null` value in JSON.
32pub struct Null {}
33
34// null is an instance of the Null type, to ease comparisons with it.
35pub const null = Null{}
36
37// from_json_null implements a custom decoder for json2
38@[markused]
39pub fn (mut n Null) from_json_null() {}
40
41// to_json implements a custom encoder for json2
42pub fn (n Null) to_json() string {
43 return 'null'
44}
45
46// ValueKind enumerates the kinds of possible values of the Any sumtype.
47enum ValueKind {
48 array
49 object
50 string
51 number
52 boolean
53 null
54}
55