/** * @file SerialArrayListAdapter.h * @brief This file defines the SerialArrayListAdapter class. * @date 22.07.2014 * @author baetz */ #ifndef SERIALARRAYLISTADAPTER_H_ #define SERIALARRAYLISTADAPTER_H_ #include #include #include template class SerialArrayListAdapter : public SerializeIF { public: SerialArrayListAdapter(ArrayList *adaptee) : adaptee(adaptee) { } virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { return serialize(adaptee, buffer, size, max_size, bigEndian); } static ReturnValue_t serialize(const ArrayList* list, uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::serialize(&list->size, buffer, size, max_size, bigEndian); count_t i = 0; while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { result = SerializeAdapter::serialize(&list->entries[i], buffer, size, max_size, bigEndian); ++i; } return result; } virtual uint32_t getSerializedSize() const { return getSerializedSize(adaptee); } static uint32_t getSerializedSize(const ArrayList* list) { uint32_t printSize = sizeof(count_t); count_t i = 0; for (i = 0; i < list->size; ++i) { printSize += SerializeAdapter::getSerializedSize(&list->entries[i]); } return printSize; } virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { return deSerialize(adaptee, buffer, size, bigEndian); } static ReturnValue_t deSerialize(ArrayList* list, const uint8_t** buffer, int32_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&list->size, buffer, size, bigEndian); if (list->size > list->maxSize()) { return SerializeIF::TOO_MANY_ELEMENTS; } count_t i = 0; while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { result = SerializeAdapter::deSerialize( &list->front()[i], buffer, size, bigEndian); ++i; } return result; } private: ArrayList *adaptee; }; #endif /* SERIALARRAYLISTADAPTER_H_ */