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>
52 m_eventHeaderType(static_cast<
EventHeaderType>(header->header_value_type)),
53 m_eventHeaderStaticValue({0})
55 switch (m_eventHeaderType)
57 case EventHeaderType::BOOL_TRUE:
58 case EventHeaderType::BOOL_FALSE:
59 m_eventHeaderStaticValue.boolValue = aws_event_stream_header_value_as_bool(header) != 0;
61 case EventHeaderType::BYTE:
62 m_eventHeaderStaticValue.byteValue = aws_event_stream_header_value_as_byte(header);
64 case EventHeaderType::INT16:
65 m_eventHeaderStaticValue.int16Value = aws_event_stream_header_value_as_int16(header);
67 case EventHeaderType::INT32:
68 m_eventHeaderStaticValue.int32Value = aws_event_stream_header_value_as_int32(header);
70 case EventHeaderType::INT64:
71 m_eventHeaderStaticValue.int64Value = aws_event_stream_header_value_as_int64(header);
73 case EventHeaderType::BYTE_BUF:
74 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_bytebuf(header).buffer), header->header_value_len);
76 case EventHeaderType::STRING:
77 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_string(header).buffer), header->header_value_len);
79 case EventHeaderType::TIMESTAMP:
80 m_eventHeaderStaticValue.timestampValue = aws_event_stream_header_value_as_timestamp(header);
82 case EventHeaderType::UUID:
83 assert(header->header_value_len == 16u);
84 m_eventHeaderVariableLengthValue =
ByteBuffer(
static_cast<uint8_t*
>(aws_event_stream_header_value_as_uuid(header).buffer), header->header_value_len);
87 AWS_LOG_ERROR(CLASS_TAG,
"Encountered unknown type of header.");
94 m_eventHeaderVariableLengthValue(reinterpret_cast<const uint8_t*>(s.data()), s.length()),
95 m_eventHeaderStaticValue({0})
101 m_eventHeaderVariableLengthValue(bb),
102 m_eventHeaderStaticValue({0})
108 m_eventHeaderVariableLengthValue(std::move(bb)),
109 m_eventHeaderStaticValue({0})
116 m_eventHeaderStaticValue({0})
118 m_eventHeaderStaticValue.byteValue = byte;
123 m_eventHeaderStaticValue({0})
125 m_eventHeaderStaticValue.boolValue = b;
130 m_eventHeaderStaticValue({0})
132 m_eventHeaderStaticValue.int16Value = n;
137 m_eventHeaderStaticValue({0})
139 m_eventHeaderStaticValue.int32Value = n;
143 m_eventHeaderType(type),
144 m_eventHeaderStaticValue({0})
146 if (type == EventHeaderType::TIMESTAMP)
148 m_eventHeaderStaticValue.timestampValue = n;
152 m_eventHeaderStaticValue.int64Value = n;
168 assert(m_eventHeaderType == EventHeaderType::BOOL_TRUE || m_eventHeaderType == EventHeaderType::BOOL_FALSE);
169 if (m_eventHeaderType != EventHeaderType::BOOL_TRUE && m_eventHeaderType != EventHeaderType::BOOL_FALSE)
171 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is TRUE or FALSE, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
174 return m_eventHeaderStaticValue.boolValue;
183 assert(m_eventHeaderType == EventHeaderType::BYTE);
184 if (m_eventHeaderType != EventHeaderType::BYTE)
186 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is BYTE, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
187 return static_cast<uint8_t
>(0);
189 return m_eventHeaderStaticValue.byteValue;
198 assert(m_eventHeaderType == EventHeaderType::INT16);
199 if (m_eventHeaderType != EventHeaderType::INT16)
201 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT16, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
202 return static_cast<int16_t
>(0);
204 return m_eventHeaderStaticValue.int16Value;
213 assert(m_eventHeaderType == EventHeaderType::INT32);
214 if (m_eventHeaderType != EventHeaderType::INT32)
216 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT32, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
217 return static_cast<int32_t
>(0);
219 return m_eventHeaderStaticValue.int32Value;
228 assert(m_eventHeaderType == EventHeaderType::INT64);
229 if (m_eventHeaderType != EventHeaderType::INT64)
231 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is INT64, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
232 return static_cast<uint64_t
>(0);
234 return m_eventHeaderStaticValue.int64Value;
243 assert(m_eventHeaderType == EventHeaderType::BYTE_BUF);
244 if (m_eventHeaderType != EventHeaderType::BYTE_BUF)
246 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is BYTE_BUF, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
249 return m_eventHeaderVariableLengthValue;
258 assert(m_eventHeaderType == EventHeaderType::STRING);
259 if (m_eventHeaderType != EventHeaderType::STRING)
261 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is STRING, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
264 return Aws::String(
reinterpret_cast<char*
>(m_eventHeaderVariableLengthValue.GetUnderlyingData()), m_eventHeaderVariableLengthValue.GetLength());
273 assert(m_eventHeaderType == EventHeaderType::TIMESTAMP);
274 if (m_eventHeaderType != EventHeaderType::TIMESTAMP)
276 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is TIMESTAMP, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
277 return static_cast<int64_t
>(0);
279 return m_eventHeaderStaticValue.timestampValue;
288 assert(m_eventHeaderType == EventHeaderType::UUID);
289 assert(m_eventHeaderVariableLengthValue.GetLength() == 16u);
290 if (m_eventHeaderType != EventHeaderType::UUID)
292 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Expected event header type is UUID, but encountered " << GetNameForEventHeaderType(m_eventHeaderType));
296 return Aws::Utils::UUID(m_eventHeaderVariableLengthValue.GetUnderlyingData());
301 return m_eventHeaderVariableLengthValue;
306 switch (m_eventHeaderType)
308 case EventHeaderType::BOOL_TRUE:
309 case EventHeaderType::BOOL_FALSE:
310 return Utils::StringUtils::to_string(GetEventHeaderValueAsBoolean());
311 case EventHeaderType::BYTE:
312 return Utils::StringUtils::to_string(GetEventHeaderValueAsByte());
313 case EventHeaderType::INT16:
314 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt16());
315 case EventHeaderType::INT32:
316 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt32());
317 case EventHeaderType::INT64:
318 return Utils::StringUtils::to_string(GetEventHeaderValueAsInt64());
319 case EventHeaderType::BYTE_BUF:
320 return Aws::String(
reinterpret_cast<char*
>(GetEventHeaderValueAsBytebuf().GetUnderlyingData()), GetEventHeaderValueAsBytebuf().GetLength());
321 case EventHeaderType::STRING:
322 return GetEventHeaderValueAsString();
323 case EventHeaderType::TIMESTAMP:
325 case EventHeaderType::UUID:
326 return GetEventHeaderValueAsUuid();
327 case EventHeaderType::UNKNOWN:
329 AWS_LOGSTREAM_ERROR(
CLASS_TAG,
"Cannot transform EventHeader value to string: type is unknown");
335 EventHeaderType m_eventHeaderType;
345 } m_eventHeaderStaticValue;
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