Prints one specific item in the array of type-safe arguments. Assumes item is valid.
| 171 | // Prints one specific item in the array of type-safe arguments. |
| 172 | // Assumes item is valid. |
| 173 | int MsgPrintHelper(BaseStream& out_stream, const safe_cell& item) |
| 174 | { |
| 175 | switch (item.type) |
| 176 | { |
| 177 | case safe_cell::at_char: |
| 178 | case safe_cell::at_uchar: // For now, treat UCHAR same as char. |
| 179 | return out_stream.write(&item.c_value, 1); |
| 180 | //case safe_cell::at_int16: |
| 181 | //case safe_cell::at_int32: |
| 182 | case safe_cell::at_int64: |
| 183 | { |
| 184 | char s[DECODE_BUF_SIZE]; |
| 185 | int n = decode(item.i_value, s); |
| 186 | return out_stream.write(s, n); |
| 187 | } |
| 188 | case safe_cell::at_uint64: |
| 189 | { |
| 190 | char s[DECODE_BUF_SIZE]; |
| 191 | int n = decode(static_cast<uint64_t>(item.i_value), s); |
| 192 | return out_stream.write(s, n); |
| 193 | } |
| 194 | case safe_cell::at_int128: |
| 195 | { |
| 196 | // Warning: useless display in real life |
| 197 | char s[DECODE_BUF_SIZE]; |
| 198 | int n = decode(item.i128_value.high, s); |
| 199 | int n2 = out_stream.write(s, n) + out_stream.write(".", 1); |
| 200 | n = decode(item.i128_value.low, s); |
| 201 | return n2 + out_stream.write(s, n); |
| 202 | } |
| 203 | case safe_cell::at_double: |
| 204 | { |
| 205 | char s[DECODE_BUF_SIZE]; |
| 206 | int n = decode(item.d_value, s); |
| 207 | return out_stream.write(s, n); |
| 208 | } |
| 209 | case safe_cell::at_str: |
| 210 | { |
| 211 | const char* s = item.st_value.s_string; |
| 212 | if (!s) |
| 213 | s = "(null)"; |
| 214 | |
| 215 | size_t n = strlen(s); |
| 216 | if (n > MAX_STRING) |
| 217 | n = MAX_STRING; |
| 218 | |
| 219 | return out_stream.write(s, static_cast<unsigned>(n)); |
| 220 | } |
| 221 | case safe_cell::at_ptr: |
| 222 | { |
| 223 | uint64_t v = reinterpret_cast<uint64_t>(item.p_value); |
| 224 | char s[DECODE_BUF_SIZE]; |
| 225 | int n = decode(v, s, 16); |
| 226 | return out_stream.write(s, n); |
| 227 | } |
| 228 | default: // safe_cell::at_none and whatever out of range. |
| 229 | return out_stream.write("(unknown)", 9); |
| 230 | } |