8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/utils/Array.h>
10#include <aws/core/utils/DateTime.h>
11#include <aws/core/utils/StringUtils.h>
12#include <aws/core/utils/UUID.h>
13#include <aws/core/utils/logging/LogMacros.h>
14#include <aws/core/utils/memory/stl/AWSMap.h>
15#include <aws/core/utils/memory/stl/AWSString.h>
16#include <aws/event-stream/event_stream.h>
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
22#pragma GCC diagnostic ignored "-Wuninitialized"
58 m_eventHeaderType(static_cast<
EventHeaderType>(header->header_value_type)),
59 m_eventHeaderStaticValue({0})
61 switch (m_eventHeaderType)
63 case EventHeaderType::BOOL_TRUE:
64 case EventHeaderType::BOOL_FALSE:
65 m_eventHeaderStaticValue.boolValue = aws_event_stream_header_value_as_bool(header) != 0;
67 case EventHeaderType::BYTE:
68 m_eventHeaderStaticValue.byteValue = aws_event_stream_header_value_as_byte(header);
70 case EventHeaderType::INT16:
71 m_eventHeaderStaticValue.int16Value = aws_event_stream_header_value_as_int16(header);
73 case EventHeaderType::INT32:
74 m_eventHeaderStaticValue.int32Value = aws_event_stream_header_value_as_int32(header);
76 case EventHeaderType::INT64:
77 m_eventHeaderStaticValue.int64Value = aws_event_stream_header_value_as_int64(header);
79 case EventHeaderType::BYTE_BUF:
80 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_bytebuf(header).buffer), header->header_value_len);
82 case EventHeaderType::STRING:
83 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_string(header).buffer), header->header_value_len);
85 case EventHeaderType::TIMESTAMP:
86 m_eventHeaderStaticValue.timestampValue = aws_event_stream_header_value_as_timestamp(header);
88 case EventHeaderType::UUID:
89 assert(header->header_value_len == 16u);
90 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_uuid(header).buffer), header->header_value_len);
93 AWS_LOG_ERROR(CLASS_TAG,
"Encountered unknown type of header.");
100 m_eventHeaderVariableLengthValue(reinterpret_cast<const uint8_t*>(s.data()), s.length()),
101 m_eventHeaderStaticValue({0})
107 m_eventHeaderVariableLengthValue(bb),
108 m_eventHeaderStaticValue({0})
114 m_eventHeaderVariableLengthValue(std::move(bb)),
115 m_eventHeaderStaticValue({0})
122 m_eventHeaderStaticValue({0})
124 m_eventHeaderStaticValue.byteValue = byte;
129 m_eventHeaderStaticValue({0})
131 m_eventHeaderStaticValue.boolValue = b;
136 m_eventHeaderStaticValue({0})
138 m_eventHeaderStaticValue.int16Value = n;
143 m_eventHeaderStaticValue({0})
145 m_eventHeaderStaticValue.int32Value = n;
149 m_eventHeaderType(type),
150 m_eventHeaderStaticValue({0})
152 if (type == EventHeaderType::TIMESTAMP)
154 m_eventHeaderStaticValue.timestampValue = n;
158 m_eventHeaderStaticValue.int64Value = n;
174 assert(m_eventHeaderType == EventHeaderType::BOOL_TRUE || m_eventHeaderType == EventHeaderType::BOOL_FALSE);
175 if (m_eventHeaderType != EventHeaderType::BOOL_TRUE && m_eventHeaderType != EventHeaderType::BOOL_FALSE)
177 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is TRUE or FALSE, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
180 return m_eventHeaderStaticValue.boolValue;
189 assert(m_eventHeaderType == EventHeaderType::BYTE);
190 if (m_eventHeaderType != EventHeaderType::BYTE)
192 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is BYTE, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
193 return static_cast<uint8_t
>(0);
195 return m_eventHeaderStaticValue.byteValue;
204 assert(m_eventHeaderType == EventHeaderType::INT16);
205 if (m_eventHeaderType != EventHeaderType::INT16)
207 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT16, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
208 return static_cast<int16_t
>(0);
210 return m_eventHeaderStaticValue.int16Value;
219 assert(m_eventHeaderType == EventHeaderType::INT32);
220 if (m_eventHeaderType != EventHeaderType::INT32)
222 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT32, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
223 return static_cast<int32_t
>(0);
225 return m_eventHeaderStaticValue.int32Value;
234 assert(m_eventHeaderType == EventHeaderType::INT64);
235 if (m_eventHeaderType != EventHeaderType::INT64)
237 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT64, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
238 return static_cast<uint64_t
>(0);
240 return m_eventHeaderStaticValue.int64Value;
249 assert(m_eventHeaderType == EventHeaderType::BYTE_BUF);
250 if (m_eventHeaderType != EventHeaderType::BYTE_BUF)
252 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is BYTE_BUF, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
255 return m_eventHeaderVariableLengthValue;
264 assert(m_eventHeaderType == EventHeaderType::STRING);
265 if (m_eventHeaderType != EventHeaderType::STRING)
267 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is STRING, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
270 return Aws::String(
reinterpret_cast<char*
>(m_eventHeaderVariableLengthValue.GetUnderlyingData()), m_eventHeaderVariableLengthValue.GetLength());
279 assert(m_eventHeaderType == EventHeaderType::TIMESTAMP);
280 if (m_eventHeaderType != EventHeaderType::TIMESTAMP)
282 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is TIMESTAMP, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
283 return static_cast<int64_t
>(0);
285 return m_eventHeaderStaticValue.timestampValue;
294 assert(m_eventHeaderType == EventHeaderType::UUID);
295 assert(m_eventHeaderVariableLengthValue.GetLength() == 16u);
296 if (m_eventHeaderType != EventHeaderType::UUID)
298 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is UUID, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
302 return Aws::Utils::UUID(m_eventHeaderVariableLengthValue.GetUnderlyingData());
307 return m_eventHeaderVariableLengthValue;
312 switch (m_eventHeaderType)
314 case EventHeaderType::BOOL_TRUE:
315 case EventHeaderType::BOOL_FALSE:
316 return Utils::StringUtils::to_string(GetEventHeaderValueAsBoolean());
317 case EventHeaderType::BYTE:
318 return Utils::StringUtils::to_string(GetEventHeaderValueAsByte());
319 case EventHeaderType::INT16:
320 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt16());
321 case EventHeaderType::INT32:
322 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt32());
323 case EventHeaderType::INT64:
324 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt64());
325 case EventHeaderType::BYTE_BUF:
326 return Aws::String(
reinterpret_cast<char*
>(GetEventHeaderValueAsBytebuf().GetUnderlyingData()), GetEventHeaderValueAsBytebuf().GetLength());
327 case EventHeaderType::STRING:
328 return GetEventHeaderValueAsString();
329 case EventHeaderType::TIMESTAMP:
331 case EventHeaderType::UUID:
332 return GetEventHeaderValueAsUuid();
333 case EventHeaderType::UNKNOWN:
335 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Cannot transform EventHeader value to string: type is unknown");
341 EventHeaderType m_eventHeaderType;
351 } m_eventHeaderStaticValue;
361#pragma GCC diagnostic pop
Aws::String ToGmtString(DateFormat format) const
Aws::Map< Aws::String, EventHeaderValue > EventHeaderValueCollection
std::pair< Aws::String, EventHeaderValue > EventHeaderValuePair
static const char CLASS_TAG[]
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String