Skip to content

Commit

Permalink
Merge pull request #27 from nburles/fix-ATN-serialization
Browse files Browse the repository at this point in the history
Fixes ATN serialization
  • Loading branch information
mike-lischke authored Aug 1, 2016
2 parents 3705e1b + 3535830 commit f3110fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions runtime/Cpp/runtime/src/atn/ATNSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ std::vector<size_t> ATNSerializer::serialize() {
int edgeType = t->getSerializationType();
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
SetTransition *st = static_cast<SetTransition *>(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 });
}
Expand Down Expand Up @@ -383,7 +383,7 @@ std::vector<size_t> ATNSerializer::serialize() {
}

size_t value = (data.at(i) + 2) & 0xFFFF;
data.assign(i, value);
data.at(i) = value;
}

return data;
Expand Down Expand Up @@ -625,6 +625,19 @@ std::string ATNSerializer::getDecoded(ATN *atn, std::vector<std::string> &tokenN
}

void ATNSerializer::serializeUUID(std::vector<size_t> &data, Guid uuid) {
for (auto &entry : uuid)
data.push_back(entry);
unsigned int twoBytes = 0;
bool firstByte = true;
for( std::vector<unsigned char>::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)." );
}
3 changes: 3 additions & 0 deletions runtime/Cpp/runtime/src/support/guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Guid
const std::string toString() const;
std::vector<unsigned char>::const_iterator begin() { return _bytes.begin(); };
std::vector<unsigned char>::const_iterator end() { return _bytes.end(); };
std::vector<unsigned char>::const_reverse_iterator rbegin() { return _bytes.rbegin(); };
std::vector<unsigned char>::const_reverse_iterator rend() { return _bytes.rend(); };


private:

Expand Down

0 comments on commit f3110fd

Please sign in to comment.