17 #ifndef AVROGENERICUTILS_HPP_
18 #define AVROGENERICUTILS_HPP_
22 #ifdef KAA_USE_CONFIGURATION
27 #include <avro/Generic.hh>
38 class AvroGenericUtils {
47 static bool isUuid(
const avro::GenericDatum &d) {
48 if (d.type() == avro::AVRO_FIXED) {
49 auto f = d.value<avro::GenericFixed>();
50 return f.schema()->name().fullname().compare(AvroGenericUtils::UUIDT) == 0;
62 static bool isFixed(
const avro::GenericDatum &d) {
63 return (d.type() == avro::AVRO_FIXED);
73 static bool isEnum(
const avro::GenericDatum &d) {
74 return (d.type() == avro::AVRO_ENUM);
84 static bool isRecord(
const avro::GenericDatum &d) {
85 return (d.type() == avro::AVRO_RECORD);
95 static bool isArray(
const avro::GenericDatum &d) {
96 return (d.type() == avro::AVRO_ARRAY);
106 static bool isNull(
const avro::GenericDatum &d) {
107 return d.type() == avro::AVRO_NULL;
117 static bool isReset(
const avro::GenericDatum &d) {
118 if (d.type() != avro::AVRO_ENUM) {
121 const avro::GenericEnum &e = d.value<avro::GenericEnum>();
122 return e.schema()->name().fullname().compare(AvroGenericUtils::RESETT) == 0;
132 static bool isUnchanged(
const avro::GenericDatum &d) {
133 if (d.type() != avro::AVRO_ENUM) {
136 const avro::GenericEnum &e = d.value<avro::GenericEnum>();
137 return e.schema()->name().fullname().compare(AvroGenericUtils::UNCHANGEDT) == 0;
146 static uuid_t getUuidFromDatum(
const avro::GenericDatum& datum) {
148 const avro::GenericFixed& uuidFixed = datum.value<avro::GenericRecord>().
149 field(
"__uuid").value<avro::GenericFixed>();
151 if (uuidFixed.value().size() != uuid.size()) {
152 throw KaaException(
"invalid uuid data");
155 std::copy(uuidFixed.value().begin(), uuidFixed.value().end(), uuid.begin());
165 static DeltaHandlerId getDeltaIDFromDatum(
const avro::GenericDatum& datum) {
167 const avro::GenericFixed& uuidFixed = datum.value<avro::GenericFixed>();
169 if (uuidFixed.value().size() != uuid.size()) {
170 throw KaaException(
"invalid uuid data");
173 std::copy(uuidFixed.value().begin(), uuidFixed.value().end(), uuid.begin());
175 DeltaHandlerId deltaId(uuid);
180 static const std::string RESETT;
181 static const std::string UNCHANGEDT;
182 static const std::string UUIDT;