138
138
#include < string>
139
139
140
140
#include " binary_log_types.h" // enum_field_types
141
+ #include " my_dbug.h" // DBUG_ASSERT
141
142
#include " my_inttypes.h"
142
143
143
144
class Field_json ;
@@ -190,15 +191,70 @@ class Value
190
191
enum_type type () const { return m_type; }
191
192
// / Does this value use the large storage format?
192
193
bool large_format () const { return m_large; }
193
- const char *get_data () const ;
194
- uint32 get_data_length () const ;
195
- int64 get_int64 () const ;
196
- uint64 get_uint64 () const ;
197
- double get_double () const ;
198
- uint32 element_count () const ;
194
+
195
+ /* *
196
+ Get a pointer to the beginning of the STRING or OPAQUE data
197
+ represented by this instance.
198
+ */
199
+ const char *get_data () const
200
+ {
201
+ DBUG_ASSERT (m_type == STRING || m_type == OPAQUE);
202
+ return m_data;
203
+ }
204
+
205
+ /* *
206
+ Get the length in bytes of the STRING or OPAQUE value represented by
207
+ this instance.
208
+ */
209
+ uint32 get_data_length () const
210
+ {
211
+ DBUG_ASSERT (m_type == STRING || m_type == OPAQUE);
212
+ return m_length;
213
+ }
214
+
215
+ /* * Get the value of an INT. */
216
+ int64 get_int64 () const
217
+ {
218
+ DBUG_ASSERT (m_type == INT);
219
+ return m_int_value;
220
+ }
221
+
222
+ /* * Get the value of a UINT. */
223
+ uint64 get_uint64 () const
224
+ {
225
+ DBUG_ASSERT (m_type == UINT);
226
+ return static_cast <uint64>(m_int_value);
227
+ }
228
+
229
+ /* * Get the value of a DOUBLE. */
230
+ double get_double () const
231
+ {
232
+ DBUG_ASSERT (m_type == DOUBLE);
233
+ return m_double_value;
234
+ }
235
+
236
+ /* *
237
+ Get the number of elements in an array, or the number of members in
238
+ an object.
239
+ */
240
+ uint32 element_count () const
241
+ {
242
+ DBUG_ASSERT (m_type == ARRAY || m_type == OBJECT);
243
+ return m_element_count;
244
+ }
245
+
246
+ /* *
247
+ Get the MySQL field type of an opaque value. Identifies the type of
248
+ the value stored in the data portion of an opaque value.
249
+ */
250
+ enum_field_types field_type () const
251
+ {
252
+ DBUG_ASSERT (m_type == OPAQUE);
253
+ return m_field_type;
254
+ }
255
+
199
256
Value element (size_t pos) const ;
200
257
Value key (size_t pos) const ;
201
- enum_field_types field_type () const ;
202
258
Value lookup (const std::string &key) const ;
203
259
size_t lookup_index (const std::string &key) const ;
204
260
bool is_backed_by (const String *str) const ;
@@ -213,27 +269,50 @@ class Value
213
269
const char *original, char *destination) const ;
214
270
215
271
/* * Constructor for values that represent literals or errors. */
216
- explicit Value (enum_type t);
272
+ explicit Value (enum_type t)
273
+ : m_data(nullptr ), m_type(t)
274
+ {
275
+ DBUG_ASSERT (t == LITERAL_NULL || t == LITERAL_TRUE || t == LITERAL_FALSE ||
276
+ t == ERROR);
277
+ }
278
+
217
279
/* * Constructor for values that represent ints or uints. */
218
- explicit Value (enum_type t, int64 val);
280
+ explicit Value (enum_type t, int64 val)
281
+ : m_int_value(val), m_type(t)
282
+ {
283
+ DBUG_ASSERT (t == INT || t == UINT);
284
+ }
285
+
219
286
/* * Constructor for values that represent doubles. */
220
- explicit Value (double val);
287
+ explicit Value (double val) : m_double_value(val), m_type(DOUBLE) {}
288
+
221
289
/* * Constructor for values that represent strings. */
222
- Value (const char *data, uint32 len);
290
+ Value (const char *data, uint32 len)
291
+ : m_data(data), m_length(len), m_type(STRING)
292
+ {}
293
+
223
294
/* *
224
295
Constructor for values that represent arrays or objects.
225
296
226
297
@param t type
227
298
@param data pointer to the start of the binary representation
228
- @param element_count the number of elements or members in the value
229
299
@param bytes the number of bytes in the binary representation of the value
300
+ @param element_count the number of elements or members in the value
230
301
@param large true if the value should be stored in the large
231
302
storage format with 4 byte offsets instead of 2 byte offsets
232
303
*/
233
- Value (enum_type t, const char *data, uint32 element_count, uint32 bytes,
234
- bool large);
304
+ Value (enum_type t, const char *data, uint32 bytes, uint32 element_count,
305
+ bool large)
306
+ : m_data(data), m_element_count(element_count), m_length(bytes),
307
+ m_type (t), m_large(large)
308
+ {
309
+ DBUG_ASSERT (t == ARRAY || t == OBJECT);
310
+ }
311
+
235
312
/* * Constructor for values that represent opaque data. */
236
- Value (enum_field_types ft, const char *data, uint32 len);
313
+ Value (enum_field_types ft, const char *data, uint32 len)
314
+ : m_data(data), m_length(len), m_field_type(ft), m_type(OPAQUE)
315
+ {}
237
316
238
317
/* * Empty constructor. Produces a value that represents an error condition. */
239
318
Value () : Value(ERROR) {}
@@ -276,27 +355,32 @@ class Value
276
355
/* * The value if the type is DOUBLE. */
277
356
const double m_double_value;
278
357
};
358
+
279
359
/* *
280
360
Element count for arrays and objects. Unused for other types.
281
361
*/
282
- const uint32 m_element_count;
362
+ const uint32 m_element_count{};
363
+
283
364
/* *
284
365
The full length (in bytes) of the binary representation of an array or
285
366
object, or the length of a string or opaque value. Unused for other types.
286
367
*/
287
- const uint32 m_length;
368
+ const uint32 m_length{};
369
+
288
370
/* *
289
371
The MySQL field type of the value, in case the type of the value is
290
372
OPAQUE. Otherwise, it is unused.
291
373
*/
292
- const enum_field_types m_field_type;
374
+ const enum_field_types m_field_type{};
375
+
293
376
/* * The JSON type of the value. */
294
377
const enum_type m_type;
378
+
295
379
/* *
296
380
True if an array or an object uses the large storage format with 4
297
381
byte offsets instead of 2 byte offsets.
298
382
*/
299
- const bool m_large;
383
+ const bool m_large{} ;
300
384
301
385
size_t key_entry_offset (size_t pos) const ;
302
386
size_t value_entry_offset (size_t pos) const ;
0 commit comments