25#include "RequestMessageFormat.h"
26#include "firebird/impl/blr.h"
31 static std::uint8_t scaleToByte(
int scale)
noexcept
33 return static_cast<std::uint8_t
>(
static_cast<unsigned>(scale) & 0xFFu);
37 RequestMessageFormat& RequestMessageFormat::addField(
DescriptorAdjustedType adjustedType,
unsigned dataLength,
38 unsigned alignment,
int scale,
unsigned charSetId,
int subType,
bool isNullable)
40 const auto alignedOffset =
static_cast<unsigned>((length + alignment - 1u) & ~(alignment - 1u));
42 Descriptor descriptor{
44 .adjustedType = adjustedType,
47 .offset = alignedOffset,
49 .isNullable = isNullable,
54 .charSetId = charSetId,
58 length = alignedOffset + dataLength;
59 blrFieldIndexes.push_back(
static_cast<unsigned>(descriptors.size()) + nullableCount);
63 descriptor.nullOffset = (length + 1u) & ~1u;
64 length = descriptor.nullOffset + 2u;
68 descriptors.push_back(std::move(descriptor));
74 if (messageNumber > 255u)
77 unsigned entryCount =
static_cast<unsigned>(descriptors.size());
78 for (
const auto& descriptor : descriptors)
80 if (descriptor.isNullable)
84 std::vector<std::byte> blr;
85 blr.reserve(3u + 64u * entryCount);
87 appendByte(blr, blr_message);
88 appendByte(blr,
static_cast<std::uint8_t
>(messageNumber));
89 appendWord(blr,
static_cast<std::uint16_t
>(entryCount));
91 for (
const auto& descriptor : descriptors)
93 appendBlrDataType(blr, descriptor);
95 if (descriptor.isNullable)
97 appendByte(blr, blr_short);
105 void RequestMessageFormat::appendBlrDataType(std::vector<std::byte>& blr,
const Descriptor& descriptor)
const
110 appendByte(blr, blr_bool);
114 appendByte(blr, blr_short);
115 appendByte(blr, scaleToByte(descriptor.
scale));
119 appendByte(blr, blr_long);
120 appendByte(blr, scaleToByte(descriptor.
scale));
124 appendByte(blr, blr_int64);
125 appendByte(blr, scaleToByte(descriptor.
scale));
129 appendByte(blr, blr_int128);
130 appendByte(blr, scaleToByte(descriptor.
scale));
134 appendByte(blr, blr_float);
138 appendByte(blr, blr_double);
142 appendByte(blr, blr_dec64);
146 appendByte(blr, blr_dec128);
150 appendByte(blr, blr_sql_date);
154 appendByte(blr, blr_sql_time);
158 appendByte(blr, blr_timestamp);
162 appendByte(blr, blr_sql_time_tz);
166 appendByte(blr, blr_timestamp_tz);
170 appendByte(blr, blr_quad);
177 appendByte(blr, blr_varying2);
178 appendWord(blr,
static_cast<std::uint16_t
>(descriptor.
charSetId));
181 appendByte(blr, blr_varying);
183 appendWord(blr,
static_cast<std::uint16_t
>(descriptor.
length -
sizeof(std::uint16_t)));
Base exception class for all fb-cpp exceptions.
fb-cpp request namespace.
DescriptorAdjustedType
Descriptor adjusted type.
@ BLOB
Binary large object.
@ TIME
Time of day without time zone.
@ DECFLOAT34
34-digit decimal floating point.
@ INT64
64-bit signed integer.
@ TIME_TZ
Time of day with time zone.
@ DECFLOAT16
16-digit decimal floating point.
@ INT16
16-bit signed integer.
@ STRING
String type (variable-length).
@ INT32
32-bit signed integer.
@ TIMESTAMP
Timestamp without time zone.
@ TIMESTAMP_TZ
Timestamp with time zone.
@ INT128
128-bit signed integer.
@ FLOAT
Single-precision floating point.
@ DOUBLE
Double-precision floating point.
DescriptorOriginalType
Descriptor original type.
Describes a parameter or column.
int scale
Decimal scale for numeric types; zero for non-numeric types.
unsigned charSetId
Character set ID for string and BLOB columns.
DescriptorAdjustedType adjustedType
Adjusted type after normalization for easier handling.
unsigned length
Length in bytes of the column or parameter data.