DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
The MAXREFDES155# is an internet-of-things (IoT) embedded-security reference design, built to authenticate and control a sensing node using elliptic-curve-based public-key cryptography with control and notification from a web server.
The hardware includes an ARM® mbed™ shield and attached sensor endpoint. The shield contains a DS2476 DeepCover® ECDSA/SHA-2 coprocessor, Wifi communication, LCD push-button controls, and status LEDs. The sensor endpoint is attached to the shield using a 300mm cable and contains a DS28C36 DeepCover ECDSA/SHA-2 authenticator, IR-thermal sensor, and aiming laser for the IR sensor. The MAXREFDES155# is equipped with a standard Arduino® form-factor shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The combination of these two devices represent an IoT device. Communication to the web server is accomplished with the shield Wifi circuitry. Communication from the shield to the attached sensor module is accomplished over I2C . The sensor module represents an IoT endpoint that generates small data with a requirement for message authenticity/integrity and secure on/off operational control.
The design is hierarchical with each mbed platform and shield communicating data from the sensor node to a web server that maintains a centralized log and dispatches notifications as necessary. The simplicity of this design enables rapid integration into any star-topology IoT network to provide security with the low overhead and cost provided by the ECDSA-P256 asymmetric-key and SHA-256 symmetric-key algorithms.
More information about the MAXREFDES155# is available on the Maxim Integrated website.
xternal/rapidjson/internal/itoa.h@18:c2631e985780, 2019-12-03 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Tue Dec 03 12:56:25 2019 -0600
- Revision:
- 18:c2631e985780
- Parent:
- 16:a004191a79ab
Updated MaximInterface to version 2.1.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 0:33d4e66780c0 | 1 | // Tencent is pleased to support the open source community by making RapidJSON available. |
IanBenzMaxim | 0:33d4e66780c0 | 2 | // |
IanBenzMaxim | 0:33d4e66780c0 | 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. |
IanBenzMaxim | 0:33d4e66780c0 | 4 | // |
IanBenzMaxim | 0:33d4e66780c0 | 5 | // Licensed under the MIT License (the "License"); you may not use this file except |
IanBenzMaxim | 0:33d4e66780c0 | 6 | // in compliance with the License. You may obtain a copy of the License at |
IanBenzMaxim | 0:33d4e66780c0 | 7 | // |
IanBenzMaxim | 0:33d4e66780c0 | 8 | // http://opensource.org/licenses/MIT |
IanBenzMaxim | 0:33d4e66780c0 | 9 | // |
IanBenzMaxim | 0:33d4e66780c0 | 10 | // Unless required by applicable law or agreed to in writing, software distributed |
IanBenzMaxim | 0:33d4e66780c0 | 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
IanBenzMaxim | 0:33d4e66780c0 | 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
IanBenzMaxim | 0:33d4e66780c0 | 13 | // specific language governing permissions and limitations under the License. |
IanBenzMaxim | 0:33d4e66780c0 | 14 | |
IanBenzMaxim | 0:33d4e66780c0 | 15 | #ifndef RAPIDJSON_ITOA_ |
IanBenzMaxim | 0:33d4e66780c0 | 16 | #define RAPIDJSON_ITOA_ |
IanBenzMaxim | 0:33d4e66780c0 | 17 | |
IanBenzMaxim | 0:33d4e66780c0 | 18 | #include "../rapidjson.h" |
IanBenzMaxim | 0:33d4e66780c0 | 19 | |
IanBenzMaxim | 0:33d4e66780c0 | 20 | RAPIDJSON_NAMESPACE_BEGIN |
IanBenzMaxim | 0:33d4e66780c0 | 21 | namespace internal { |
IanBenzMaxim | 0:33d4e66780c0 | 22 | |
IanBenzMaxim | 0:33d4e66780c0 | 23 | inline const char* GetDigitsLut() { |
IanBenzMaxim | 0:33d4e66780c0 | 24 | static const char cDigitsLut[200] = { |
IanBenzMaxim | 0:33d4e66780c0 | 25 | '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9', |
IanBenzMaxim | 0:33d4e66780c0 | 26 | '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9', |
IanBenzMaxim | 0:33d4e66780c0 | 27 | '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9', |
IanBenzMaxim | 0:33d4e66780c0 | 28 | '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9', |
IanBenzMaxim | 0:33d4e66780c0 | 29 | '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9', |
IanBenzMaxim | 0:33d4e66780c0 | 30 | '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9', |
IanBenzMaxim | 0:33d4e66780c0 | 31 | '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9', |
IanBenzMaxim | 0:33d4e66780c0 | 32 | '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9', |
IanBenzMaxim | 0:33d4e66780c0 | 33 | '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9', |
IanBenzMaxim | 0:33d4e66780c0 | 34 | '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9' |
IanBenzMaxim | 0:33d4e66780c0 | 35 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 36 | return cDigitsLut; |
IanBenzMaxim | 0:33d4e66780c0 | 37 | } |
IanBenzMaxim | 0:33d4e66780c0 | 38 | |
IanBenzMaxim | 0:33d4e66780c0 | 39 | inline char* u32toa(uint32_t value, char* buffer) { |
IanBenzMaxim | 0:33d4e66780c0 | 40 | const char* cDigitsLut = GetDigitsLut(); |
IanBenzMaxim | 0:33d4e66780c0 | 41 | |
IanBenzMaxim | 0:33d4e66780c0 | 42 | if (value < 10000) { |
IanBenzMaxim | 0:33d4e66780c0 | 43 | const uint32_t d1 = (value / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 44 | const uint32_t d2 = (value % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 45 | |
IanBenzMaxim | 0:33d4e66780c0 | 46 | if (value >= 1000) |
IanBenzMaxim | 0:33d4e66780c0 | 47 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 48 | if (value >= 100) |
IanBenzMaxim | 0:33d4e66780c0 | 49 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 50 | if (value >= 10) |
IanBenzMaxim | 0:33d4e66780c0 | 51 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 52 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 53 | } |
IanBenzMaxim | 0:33d4e66780c0 | 54 | else if (value < 100000000) { |
IanBenzMaxim | 0:33d4e66780c0 | 55 | // value = bbbbcccc |
IanBenzMaxim | 0:33d4e66780c0 | 56 | const uint32_t b = value / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 57 | const uint32_t c = value % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 58 | |
IanBenzMaxim | 0:33d4e66780c0 | 59 | const uint32_t d1 = (b / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 60 | const uint32_t d2 = (b % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 61 | |
IanBenzMaxim | 0:33d4e66780c0 | 62 | const uint32_t d3 = (c / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 63 | const uint32_t d4 = (c % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 64 | |
IanBenzMaxim | 0:33d4e66780c0 | 65 | if (value >= 10000000) |
IanBenzMaxim | 0:33d4e66780c0 | 66 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 67 | if (value >= 1000000) |
IanBenzMaxim | 0:33d4e66780c0 | 68 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 69 | if (value >= 100000) |
IanBenzMaxim | 0:33d4e66780c0 | 70 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 71 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 72 | |
IanBenzMaxim | 0:33d4e66780c0 | 73 | *buffer++ = cDigitsLut[d3]; |
IanBenzMaxim | 0:33d4e66780c0 | 74 | *buffer++ = cDigitsLut[d3 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 75 | *buffer++ = cDigitsLut[d4]; |
IanBenzMaxim | 0:33d4e66780c0 | 76 | *buffer++ = cDigitsLut[d4 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 77 | } |
IanBenzMaxim | 0:33d4e66780c0 | 78 | else { |
IanBenzMaxim | 0:33d4e66780c0 | 79 | // value = aabbbbcccc in decimal |
IanBenzMaxim | 0:33d4e66780c0 | 80 | |
IanBenzMaxim | 0:33d4e66780c0 | 81 | const uint32_t a = value / 100000000; // 1 to 42 |
IanBenzMaxim | 0:33d4e66780c0 | 82 | value %= 100000000; |
IanBenzMaxim | 0:33d4e66780c0 | 83 | |
IanBenzMaxim | 0:33d4e66780c0 | 84 | if (a >= 10) { |
IanBenzMaxim | 0:33d4e66780c0 | 85 | const unsigned i = a << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 86 | *buffer++ = cDigitsLut[i]; |
IanBenzMaxim | 0:33d4e66780c0 | 87 | *buffer++ = cDigitsLut[i + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 88 | } |
IanBenzMaxim | 0:33d4e66780c0 | 89 | else |
IanBenzMaxim | 0:33d4e66780c0 | 90 | *buffer++ = static_cast<char>('0' + static_cast<char>(a)); |
IanBenzMaxim | 0:33d4e66780c0 | 91 | |
IanBenzMaxim | 0:33d4e66780c0 | 92 | const uint32_t b = value / 10000; // 0 to 9999 |
IanBenzMaxim | 0:33d4e66780c0 | 93 | const uint32_t c = value % 10000; // 0 to 9999 |
IanBenzMaxim | 0:33d4e66780c0 | 94 | |
IanBenzMaxim | 0:33d4e66780c0 | 95 | const uint32_t d1 = (b / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 96 | const uint32_t d2 = (b % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 97 | |
IanBenzMaxim | 0:33d4e66780c0 | 98 | const uint32_t d3 = (c / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 99 | const uint32_t d4 = (c % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 100 | |
IanBenzMaxim | 0:33d4e66780c0 | 101 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 102 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 103 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 104 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 105 | *buffer++ = cDigitsLut[d3]; |
IanBenzMaxim | 0:33d4e66780c0 | 106 | *buffer++ = cDigitsLut[d3 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 107 | *buffer++ = cDigitsLut[d4]; |
IanBenzMaxim | 0:33d4e66780c0 | 108 | *buffer++ = cDigitsLut[d4 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 109 | } |
IanBenzMaxim | 0:33d4e66780c0 | 110 | return buffer; |
IanBenzMaxim | 0:33d4e66780c0 | 111 | } |
IanBenzMaxim | 0:33d4e66780c0 | 112 | |
IanBenzMaxim | 0:33d4e66780c0 | 113 | inline char* i32toa(int32_t value, char* buffer) { |
IanBenzMaxim | 0:33d4e66780c0 | 114 | uint32_t u = static_cast<uint32_t>(value); |
IanBenzMaxim | 0:33d4e66780c0 | 115 | if (value < 0) { |
IanBenzMaxim | 0:33d4e66780c0 | 116 | *buffer++ = '-'; |
IanBenzMaxim | 0:33d4e66780c0 | 117 | u = ~u + 1; |
IanBenzMaxim | 0:33d4e66780c0 | 118 | } |
IanBenzMaxim | 0:33d4e66780c0 | 119 | |
IanBenzMaxim | 0:33d4e66780c0 | 120 | return u32toa(u, buffer); |
IanBenzMaxim | 0:33d4e66780c0 | 121 | } |
IanBenzMaxim | 0:33d4e66780c0 | 122 | |
IanBenzMaxim | 0:33d4e66780c0 | 123 | inline char* u64toa(uint64_t value, char* buffer) { |
IanBenzMaxim | 0:33d4e66780c0 | 124 | const char* cDigitsLut = GetDigitsLut(); |
IanBenzMaxim | 0:33d4e66780c0 | 125 | const uint64_t kTen8 = 100000000; |
IanBenzMaxim | 0:33d4e66780c0 | 126 | const uint64_t kTen9 = kTen8 * 10; |
IanBenzMaxim | 0:33d4e66780c0 | 127 | const uint64_t kTen10 = kTen8 * 100; |
IanBenzMaxim | 0:33d4e66780c0 | 128 | const uint64_t kTen11 = kTen8 * 1000; |
IanBenzMaxim | 0:33d4e66780c0 | 129 | const uint64_t kTen12 = kTen8 * 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 130 | const uint64_t kTen13 = kTen8 * 100000; |
IanBenzMaxim | 0:33d4e66780c0 | 131 | const uint64_t kTen14 = kTen8 * 1000000; |
IanBenzMaxim | 0:33d4e66780c0 | 132 | const uint64_t kTen15 = kTen8 * 10000000; |
IanBenzMaxim | 0:33d4e66780c0 | 133 | const uint64_t kTen16 = kTen8 * kTen8; |
IanBenzMaxim | 0:33d4e66780c0 | 134 | |
IanBenzMaxim | 0:33d4e66780c0 | 135 | if (value < kTen8) { |
IanBenzMaxim | 0:33d4e66780c0 | 136 | uint32_t v = static_cast<uint32_t>(value); |
IanBenzMaxim | 0:33d4e66780c0 | 137 | if (v < 10000) { |
IanBenzMaxim | 0:33d4e66780c0 | 138 | const uint32_t d1 = (v / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 139 | const uint32_t d2 = (v % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 140 | |
IanBenzMaxim | 0:33d4e66780c0 | 141 | if (v >= 1000) |
IanBenzMaxim | 0:33d4e66780c0 | 142 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 143 | if (v >= 100) |
IanBenzMaxim | 0:33d4e66780c0 | 144 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 145 | if (v >= 10) |
IanBenzMaxim | 0:33d4e66780c0 | 146 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 147 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 148 | } |
IanBenzMaxim | 0:33d4e66780c0 | 149 | else { |
IanBenzMaxim | 0:33d4e66780c0 | 150 | // value = bbbbcccc |
IanBenzMaxim | 0:33d4e66780c0 | 151 | const uint32_t b = v / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 152 | const uint32_t c = v % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 153 | |
IanBenzMaxim | 0:33d4e66780c0 | 154 | const uint32_t d1 = (b / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 155 | const uint32_t d2 = (b % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 156 | |
IanBenzMaxim | 0:33d4e66780c0 | 157 | const uint32_t d3 = (c / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 158 | const uint32_t d4 = (c % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 159 | |
IanBenzMaxim | 0:33d4e66780c0 | 160 | if (value >= 10000000) |
IanBenzMaxim | 0:33d4e66780c0 | 161 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 162 | if (value >= 1000000) |
IanBenzMaxim | 0:33d4e66780c0 | 163 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 164 | if (value >= 100000) |
IanBenzMaxim | 0:33d4e66780c0 | 165 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 166 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 167 | |
IanBenzMaxim | 0:33d4e66780c0 | 168 | *buffer++ = cDigitsLut[d3]; |
IanBenzMaxim | 0:33d4e66780c0 | 169 | *buffer++ = cDigitsLut[d3 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 170 | *buffer++ = cDigitsLut[d4]; |
IanBenzMaxim | 0:33d4e66780c0 | 171 | *buffer++ = cDigitsLut[d4 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 172 | } |
IanBenzMaxim | 0:33d4e66780c0 | 173 | } |
IanBenzMaxim | 0:33d4e66780c0 | 174 | else if (value < kTen16) { |
IanBenzMaxim | 0:33d4e66780c0 | 175 | const uint32_t v0 = static_cast<uint32_t>(value / kTen8); |
IanBenzMaxim | 0:33d4e66780c0 | 176 | const uint32_t v1 = static_cast<uint32_t>(value % kTen8); |
IanBenzMaxim | 0:33d4e66780c0 | 177 | |
IanBenzMaxim | 0:33d4e66780c0 | 178 | const uint32_t b0 = v0 / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 179 | const uint32_t c0 = v0 % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 180 | |
IanBenzMaxim | 0:33d4e66780c0 | 181 | const uint32_t d1 = (b0 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 182 | const uint32_t d2 = (b0 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 183 | |
IanBenzMaxim | 0:33d4e66780c0 | 184 | const uint32_t d3 = (c0 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 185 | const uint32_t d4 = (c0 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 186 | |
IanBenzMaxim | 0:33d4e66780c0 | 187 | const uint32_t b1 = v1 / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 188 | const uint32_t c1 = v1 % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 189 | |
IanBenzMaxim | 0:33d4e66780c0 | 190 | const uint32_t d5 = (b1 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 191 | const uint32_t d6 = (b1 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 192 | |
IanBenzMaxim | 0:33d4e66780c0 | 193 | const uint32_t d7 = (c1 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 194 | const uint32_t d8 = (c1 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 195 | |
IanBenzMaxim | 0:33d4e66780c0 | 196 | if (value >= kTen15) |
IanBenzMaxim | 0:33d4e66780c0 | 197 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 198 | if (value >= kTen14) |
IanBenzMaxim | 0:33d4e66780c0 | 199 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 200 | if (value >= kTen13) |
IanBenzMaxim | 0:33d4e66780c0 | 201 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 202 | if (value >= kTen12) |
IanBenzMaxim | 0:33d4e66780c0 | 203 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 204 | if (value >= kTen11) |
IanBenzMaxim | 0:33d4e66780c0 | 205 | *buffer++ = cDigitsLut[d3]; |
IanBenzMaxim | 0:33d4e66780c0 | 206 | if (value >= kTen10) |
IanBenzMaxim | 0:33d4e66780c0 | 207 | *buffer++ = cDigitsLut[d3 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 208 | if (value >= kTen9) |
IanBenzMaxim | 0:33d4e66780c0 | 209 | *buffer++ = cDigitsLut[d4]; |
IanBenzMaxim | 0:33d4e66780c0 | 210 | if (value >= kTen8) |
IanBenzMaxim | 0:33d4e66780c0 | 211 | *buffer++ = cDigitsLut[d4 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 212 | |
IanBenzMaxim | 0:33d4e66780c0 | 213 | *buffer++ = cDigitsLut[d5]; |
IanBenzMaxim | 0:33d4e66780c0 | 214 | *buffer++ = cDigitsLut[d5 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 215 | *buffer++ = cDigitsLut[d6]; |
IanBenzMaxim | 0:33d4e66780c0 | 216 | *buffer++ = cDigitsLut[d6 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 217 | *buffer++ = cDigitsLut[d7]; |
IanBenzMaxim | 0:33d4e66780c0 | 218 | *buffer++ = cDigitsLut[d7 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 219 | *buffer++ = cDigitsLut[d8]; |
IanBenzMaxim | 0:33d4e66780c0 | 220 | *buffer++ = cDigitsLut[d8 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 221 | } |
IanBenzMaxim | 0:33d4e66780c0 | 222 | else { |
IanBenzMaxim | 0:33d4e66780c0 | 223 | const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844 |
IanBenzMaxim | 0:33d4e66780c0 | 224 | value %= kTen16; |
IanBenzMaxim | 0:33d4e66780c0 | 225 | |
IanBenzMaxim | 0:33d4e66780c0 | 226 | if (a < 10) |
IanBenzMaxim | 0:33d4e66780c0 | 227 | *buffer++ = static_cast<char>('0' + static_cast<char>(a)); |
IanBenzMaxim | 0:33d4e66780c0 | 228 | else if (a < 100) { |
IanBenzMaxim | 0:33d4e66780c0 | 229 | const uint32_t i = a << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 230 | *buffer++ = cDigitsLut[i]; |
IanBenzMaxim | 0:33d4e66780c0 | 231 | *buffer++ = cDigitsLut[i + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 232 | } |
IanBenzMaxim | 0:33d4e66780c0 | 233 | else if (a < 1000) { |
IanBenzMaxim | 0:33d4e66780c0 | 234 | *buffer++ = static_cast<char>('0' + static_cast<char>(a / 100)); |
IanBenzMaxim | 0:33d4e66780c0 | 235 | |
IanBenzMaxim | 0:33d4e66780c0 | 236 | const uint32_t i = (a % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 237 | *buffer++ = cDigitsLut[i]; |
IanBenzMaxim | 0:33d4e66780c0 | 238 | *buffer++ = cDigitsLut[i + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 239 | } |
IanBenzMaxim | 0:33d4e66780c0 | 240 | else { |
IanBenzMaxim | 0:33d4e66780c0 | 241 | const uint32_t i = (a / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 242 | const uint32_t j = (a % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 243 | *buffer++ = cDigitsLut[i]; |
IanBenzMaxim | 0:33d4e66780c0 | 244 | *buffer++ = cDigitsLut[i + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 245 | *buffer++ = cDigitsLut[j]; |
IanBenzMaxim | 0:33d4e66780c0 | 246 | *buffer++ = cDigitsLut[j + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 247 | } |
IanBenzMaxim | 0:33d4e66780c0 | 248 | |
IanBenzMaxim | 0:33d4e66780c0 | 249 | const uint32_t v0 = static_cast<uint32_t>(value / kTen8); |
IanBenzMaxim | 0:33d4e66780c0 | 250 | const uint32_t v1 = static_cast<uint32_t>(value % kTen8); |
IanBenzMaxim | 0:33d4e66780c0 | 251 | |
IanBenzMaxim | 0:33d4e66780c0 | 252 | const uint32_t b0 = v0 / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 253 | const uint32_t c0 = v0 % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 254 | |
IanBenzMaxim | 0:33d4e66780c0 | 255 | const uint32_t d1 = (b0 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 256 | const uint32_t d2 = (b0 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 257 | |
IanBenzMaxim | 0:33d4e66780c0 | 258 | const uint32_t d3 = (c0 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 259 | const uint32_t d4 = (c0 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 260 | |
IanBenzMaxim | 0:33d4e66780c0 | 261 | const uint32_t b1 = v1 / 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 262 | const uint32_t c1 = v1 % 10000; |
IanBenzMaxim | 0:33d4e66780c0 | 263 | |
IanBenzMaxim | 0:33d4e66780c0 | 264 | const uint32_t d5 = (b1 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 265 | const uint32_t d6 = (b1 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 266 | |
IanBenzMaxim | 0:33d4e66780c0 | 267 | const uint32_t d7 = (c1 / 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 268 | const uint32_t d8 = (c1 % 100) << 1; |
IanBenzMaxim | 0:33d4e66780c0 | 269 | |
IanBenzMaxim | 0:33d4e66780c0 | 270 | *buffer++ = cDigitsLut[d1]; |
IanBenzMaxim | 0:33d4e66780c0 | 271 | *buffer++ = cDigitsLut[d1 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 272 | *buffer++ = cDigitsLut[d2]; |
IanBenzMaxim | 0:33d4e66780c0 | 273 | *buffer++ = cDigitsLut[d2 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 274 | *buffer++ = cDigitsLut[d3]; |
IanBenzMaxim | 0:33d4e66780c0 | 275 | *buffer++ = cDigitsLut[d3 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 276 | *buffer++ = cDigitsLut[d4]; |
IanBenzMaxim | 0:33d4e66780c0 | 277 | *buffer++ = cDigitsLut[d4 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 278 | *buffer++ = cDigitsLut[d5]; |
IanBenzMaxim | 0:33d4e66780c0 | 279 | *buffer++ = cDigitsLut[d5 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 280 | *buffer++ = cDigitsLut[d6]; |
IanBenzMaxim | 0:33d4e66780c0 | 281 | *buffer++ = cDigitsLut[d6 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 282 | *buffer++ = cDigitsLut[d7]; |
IanBenzMaxim | 0:33d4e66780c0 | 283 | *buffer++ = cDigitsLut[d7 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 284 | *buffer++ = cDigitsLut[d8]; |
IanBenzMaxim | 0:33d4e66780c0 | 285 | *buffer++ = cDigitsLut[d8 + 1]; |
IanBenzMaxim | 0:33d4e66780c0 | 286 | } |
IanBenzMaxim | 0:33d4e66780c0 | 287 | |
IanBenzMaxim | 0:33d4e66780c0 | 288 | return buffer; |
IanBenzMaxim | 0:33d4e66780c0 | 289 | } |
IanBenzMaxim | 0:33d4e66780c0 | 290 | |
IanBenzMaxim | 0:33d4e66780c0 | 291 | inline char* i64toa(int64_t value, char* buffer) { |
IanBenzMaxim | 0:33d4e66780c0 | 292 | uint64_t u = static_cast<uint64_t>(value); |
IanBenzMaxim | 0:33d4e66780c0 | 293 | if (value < 0) { |
IanBenzMaxim | 0:33d4e66780c0 | 294 | *buffer++ = '-'; |
IanBenzMaxim | 0:33d4e66780c0 | 295 | u = ~u + 1; |
IanBenzMaxim | 0:33d4e66780c0 | 296 | } |
IanBenzMaxim | 0:33d4e66780c0 | 297 | |
IanBenzMaxim | 0:33d4e66780c0 | 298 | return u64toa(u, buffer); |
IanBenzMaxim | 0:33d4e66780c0 | 299 | } |
IanBenzMaxim | 0:33d4e66780c0 | 300 | |
IanBenzMaxim | 0:33d4e66780c0 | 301 | } // namespace internal |
IanBenzMaxim | 0:33d4e66780c0 | 302 | RAPIDJSON_NAMESPACE_END |
IanBenzMaxim | 0:33d4e66780c0 | 303 | |
IanBenzMaxim | 0:33d4e66780c0 | 304 | #endif // RAPIDJSON_ITOA_ |