diff --git a/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp b/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp index defa33950..e779fa023 100755 --- a/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp @@ -135,7 +135,7 @@ std::vector ATNSerializer::serialize() { int edgeType = t->getSerializationType(); if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) { SetTransition *st = static_cast(t); - if (setIndices.find(st->set) != setIndices.end()) { + if (setIndices.find(st->set) == setIndices.end()) { sets.push_back(st->set); setIndices.insert({ st->set, (int)sets.size() - 1 }); } @@ -383,7 +383,7 @@ std::vector ATNSerializer::serialize() { } size_t value = (data.at(i) + 2) & 0xFFFF; - data.assign(i, value); + data.at(i) = value; } return data; @@ -625,6 +625,19 @@ std::string ATNSerializer::getDecoded(ATN *atn, std::vector &tokenN } void ATNSerializer::serializeUUID(std::vector &data, Guid uuid) { - for (auto &entry : uuid) - data.push_back(entry); + unsigned int twoBytes = 0; + bool firstByte = true; + for( std::vector::const_reverse_iterator rit = uuid.rbegin(); rit != uuid.rend(); ++rit ) + { + if (firstByte) { + twoBytes = *rit; + firstByte = false; + } else { + twoBytes |= (*rit << 8); + data.push_back(twoBytes); + firstByte = true; + } + } + if (!firstByte) + throw IllegalArgumentException( "The UUID provided is not valid (odd number of bytes)." ); } diff --git a/runtime/Cpp/runtime/src/support/guid.h b/runtime/Cpp/runtime/src/support/guid.h index 3520d0abb..0be26f525 100755 --- a/runtime/Cpp/runtime/src/support/guid.h +++ b/runtime/Cpp/runtime/src/support/guid.h @@ -70,6 +70,9 @@ public: const std::string toString() const; std::vector::const_iterator begin() { return _bytes.begin(); }; std::vector::const_iterator end() { return _bytes.end(); }; + std::vector::const_reverse_iterator rbegin() { return _bytes.rbegin(); }; + std::vector::const_reverse_iterator rend() { return _bytes.rend(); }; + private: