@@ -53,7 +53,7 @@ func decodeFromJSON<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T
53
53
For JSON payload such as:
54
54
55
55
```
56
- {"array ": [-1.3, true], "number ": 42}
56
+ {"foo ": [-1.3, true], "barz ": 42}
57
57
```
58
58
59
59
will be scanned by 'JSONScanner' into a map like:
@@ -66,29 +66,29 @@ func decodeFromJSON<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T
66
66
<TL> == NULL Marker
67
67
map: [
68
68
0: <OM>, -- object marker
69
- 1: 15 , | `- number of *map* elements in this collection
70
- 2: <SS>, | --- key 1: 'array '
69
+ 1: 17 , | `- number of *map* elements this object occupies
70
+ 2: <SS>, | --- key 1: 'foo '
71
71
3: <int_ptr>, | | |- pointer in the payload
72
- 4: 5 , | | `- length
72
+ 4: 3 , | | `- length
73
73
5: <AM>, | --- value 1: array
74
- 6: 4 , | | `- number of *map* elements in the array
74
+ 6: 6 , | | `- number of *map* elements this array occupies
75
75
7: <NM>, | | -- arr elm 1: '-1.3'
76
76
8: <int_ptr>, | | |
77
77
9: 4, | | |
78
78
10: <TL>, | | -- arr elm 2: 'true'
79
- 11: <SS>, | --- key 2: 'number '
79
+ 11: <SS>, | --- key 2: 'barz '
80
80
12: <int_ptr>, | |
81
- 13: 6 , | |
81
+ 13: 4 , | |
82
82
14: <NM> | --- value 2: '42'
83
83
15: <int_ptr>, | |
84
84
16: 2, | |
85
85
]
86
86
```
87
- To decode '<root>.number ' value:
87
+ To decode '<root>.barz ' value:
88
88
1. Index 0 indicates it's a object.
89
- 2. Parse a key string at index 2, which is not a match for "number "
90
- 3. Skip the key's value by finding it's an array, then its 'index(afterValue:)' which is 11
91
- 4. Parse a key string at index 11, matching "number "
89
+ 2. Parse a key string at index 2, which is "foo", not a match for "barz "
90
+ 3. Skip the key and the value by advancing the index by 'mapSize' of them, 3 and 6.
91
+ 4. Parse a key string at index 11, matching "barz "
92
92
5. Parse a value number at the pointer of index 15, length at index 16
93
93
*/
94
94
@@ -147,7 +147,7 @@ private struct JSONMapBuilder {
147
147
mutating func closeCollection( handle: Int ) {
148
148
// 'handle': descriptor index.
149
149
// 'handle+1': counter index.
150
- mapData [ handle + 1 ] = mapData. count - handle - 2
150
+ mapData [ handle + 1 ] = mapData. count - handle
151
151
}
152
152
153
153
func finalize( ) -> JSONMap {
@@ -381,7 +381,7 @@ private struct JSONMapValue {
381
381
case . number, . simpleString, . string:
382
382
return 3
383
383
case . array, . object:
384
- return 2 &+ data [ 1 ]
384
+ return data [ 1 ]
385
385
case nil :
386
386
fatalError ( " invalid value descriptor " )
387
387
}
0 commit comments