138138#include < string>
139139
140140#include " binary_log_types.h" // enum_field_types
141+ #include " my_dbug.h" // DBUG_ASSERT
141142#include " my_inttypes.h"
142143
143144class Field_json ;
@@ -190,15 +191,70 @@ class Value
190191 enum_type type () const { return m_type; }
191192 // / Does this value use the large storage format?
192193 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+
199256 Value element (size_t pos) const ;
200257 Value key (size_t pos) const ;
201- enum_field_types field_type () const ;
202258 Value lookup (const std::string &key) const ;
203259 size_t lookup_index (const std::string &key) const ;
204260 bool is_backed_by (const String *str) const ;
@@ -213,27 +269,50 @@ class Value
213269 const char *original, char *destination) const ;
214270
215271 /* * 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+
217279 /* * 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+
219286 /* * Constructor for values that represent doubles. */
220- explicit Value (double val);
287+ explicit Value (double val) : m_double_value(val), m_type(DOUBLE) {}
288+
221289 /* * 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+
223294 /* *
224295 Constructor for values that represent arrays or objects.
225296
226297 @param t type
227298 @param data pointer to the start of the binary representation
228- @param element_count the number of elements or members in the value
229299 @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
230301 @param large true if the value should be stored in the large
231302 storage format with 4 byte offsets instead of 2 byte offsets
232303 */
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+
235312 /* * 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+ {}
237316
238317 /* * Empty constructor. Produces a value that represents an error condition. */
239318 Value () : Value(ERROR) {}
@@ -276,27 +355,32 @@ class Value
276355 /* * The value if the type is DOUBLE. */
277356 const double m_double_value;
278357 };
358+
279359 /* *
280360 Element count for arrays and objects. Unused for other types.
281361 */
282- const uint32 m_element_count;
362+ const uint32 m_element_count{};
363+
283364 /* *
284365 The full length (in bytes) of the binary representation of an array or
285366 object, or the length of a string or opaque value. Unused for other types.
286367 */
287- const uint32 m_length;
368+ const uint32 m_length{};
369+
288370 /* *
289371 The MySQL field type of the value, in case the type of the value is
290372 OPAQUE. Otherwise, it is unused.
291373 */
292- const enum_field_types m_field_type;
374+ const enum_field_types m_field_type{};
375+
293376 /* * The JSON type of the value. */
294377 const enum_type m_type;
378+
295379 /* *
296380 True if an array or an object uses the large storage format with 4
297381 byte offsets instead of 2 byte offsets.
298382 */
299- const bool m_large;
383+ const bool m_large{} ;
300384
301385 size_t key_entry_offset (size_t pos) const ;
302386 size_t value_entry_offset (size_t pos) const ;
0 commit comments