24#ifndef MYSQL_SERIALIZATION_PRIMITIVE_TYPE_CODEC_H
25#define MYSQL_SERIALIZATION_PRIMITIVE_TYPE_CODEC_H
49template <Field_size field_size>
61 template <
class Type,
typename Enabler = std::enable_if_t<
62 std::is_integral<std::decay_t<Type>>::value>>
64 return detail::get_size_integer_varlen<Type>(arg);
71 template <
class Type,
typename Enabler = std::enable_if_t<
72 std::is_floating_point<std::decay_t<Type>>::value>>
89template <Field_size field_size>
94 template <
class Type,
typename Enabler = std::enable_if_t<
95 std::is_integral<std::decay_t<Type>>::value>>
119 template <Field_size field_size>
128 template <Field_size field_size>
130 std::size_t stream_bytes,
Type &data);
137 template <Field_size field_size>
144template <Field_size field_size>
146 const std::string &data) {
147 if (data.length() > field_size && field_size != 0) {
151 if (data.length() == 0) {
152 return bytes_written;
154 memcpy(stream + bytes_written, data.c_str(), data.length());
155 return data.length() + bytes_written;
159template <Field_size field_size>
161 const unsigned char *stream, std::size_t stream_bytes, std::string &data) {
162 uint64_t string_length = 0;
163 std::size_t bytes_read =
165 if (bytes_read == 0 || (string_length > field_size && field_size != 0) ||
166 stream_bytes < bytes_read + string_length) {
170 data.resize(string_length);
171 }
catch (std::bad_alloc &) {
174 memcpy(data.data(), stream + bytes_read, data.length());
175 return data.length() + bytes_read;
Experimental API header Conversions between different number representations.
Functions for reading and storing in machine-independent format.
size_t write_varlen_bytes(unsigned char *stream, const std::unsigned_integral auto &data)
Writes variable-length integer to the stream.
Definition: variable_length_integers.h:123
size_t read_varlen_bytes(const unsigned char *stream, std::size_t stream_bytes, std::unsigned_integral auto &data)
Reads variable-length integer from the stream.
Definition: variable_length_integers.h:195
Type
Definition: resource_group_basic_types.h:33
static size_t count_write_bytes(const Type &, int=0)
Calculates bytes needed to encode the field, enabled for non-integer types (float/double)
Definition: primitive_type_codec.h:73
static size_t count_write_bytes(const std::string &arg)
Calculates bytes needed to encode the unbounded string.
Definition: primitive_type_codec.h:80
static size_t count_write_bytes(const Type &arg)
Calculates bytes needed to encode the field, enabled for integer.
Definition: primitive_type_codec.h:63
Structure that contains methods to count the number of bytes needed to encode a specific field.
Definition: primitive_type_codec.h:90
static size_t count_write_bytes(const Type &)
Calculates bytes needed to encode the field.
Definition: primitive_type_codec.h:96
static size_t count_write_bytes(const std::string &arg)
Calculates bytes needed to encode the bounded string field (specialization of count_write_bytes for s...
Definition: primitive_type_codec.h:104
This class is to provide functionality to encode/decode the primitive types into/out of defined strea...
Definition: primitive_type_codec.h:113
static size_t write_bytes(unsigned char *stream, const Type &data)
Writes field_size bytes stored in data into stream.
static size_t count_write_bytes(const Type &data)
Returns number of bytes required to hold information Returns field_size or size of bytes required to ...
Definition: primitive_type_codec.h:138
static size_t read_bytes(const unsigned char *stream, std::size_t stream_bytes, Type &data)
Reads field_size bytes stored in the stream into data.