Skip to content

Commit

Permalink
Added serialization to MessagingTest (but this is still not properly …
Browse files Browse the repository at this point in the history
…tested)
  • Loading branch information
floooh committed Sep 28, 2015
1 parent f8b781f commit c220682
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
78 changes: 78 additions & 0 deletions code/Modules/Messaging/UnitTests/TestProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,82 @@ TestProtocol::Factory::Create(MessageIdType id) {
return jumpTable[id - Protocol::MessageId::NumMessageIds]();
};
}
int32 TestProtocol::TestMsg1::EncodedSize() const {
int32 s = Message::EncodedSize();
s += Serializer::EncodedSize<int8>(this->int8val);
s += Serializer::EncodedSize<int16>(this->int16val);
s += Serializer::EncodedSize<int32>(this->int32val);
s += Serializer::EncodedSize<int64>(this->int64val);
s += Serializer::EncodedSize<uint8>(this->uint8val);
s += Serializer::EncodedSize<uint16>(this->uint16val);
s += Serializer::EncodedSize<uint32>(this->uint32val);
s += Serializer::EncodedSize<uint64>(this->uint64val);
s += Serializer::EncodedSize<float32>(this->float32val);
s += Serializer::EncodedSize<float64>(this->float64val);
return s;
}
uint8* TestProtocol::TestMsg1::Encode(uint8* dstPtr, const uint8* maxValidPtr) const {
dstPtr = Message::Encode(dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<int8>(this->int8val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<int16>(this->int16val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<int32>(this->int32val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<int64>(this->int64val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<uint8>(this->uint8val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<uint16>(this->uint16val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<uint32>(this->uint32val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<uint64>(this->uint64val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<float32>(this->float32val, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<float64>(this->float64val, dstPtr, maxValidPtr);
return dstPtr;
}
const uint8* TestProtocol::TestMsg1::Decode(const uint8* srcPtr, const uint8* maxValidPtr) {
srcPtr = Message::Decode(srcPtr, maxValidPtr);
srcPtr = Serializer::Decode<int8>(srcPtr, maxValidPtr, this->int8val);
srcPtr = Serializer::Decode<int16>(srcPtr, maxValidPtr, this->int16val);
srcPtr = Serializer::Decode<int32>(srcPtr, maxValidPtr, this->int32val);
srcPtr = Serializer::Decode<int64>(srcPtr, maxValidPtr, this->int64val);
srcPtr = Serializer::Decode<uint8>(srcPtr, maxValidPtr, this->uint8val);
srcPtr = Serializer::Decode<uint16>(srcPtr, maxValidPtr, this->uint16val);
srcPtr = Serializer::Decode<uint32>(srcPtr, maxValidPtr, this->uint32val);
srcPtr = Serializer::Decode<uint64>(srcPtr, maxValidPtr, this->uint64val);
srcPtr = Serializer::Decode<float32>(srcPtr, maxValidPtr, this->float32val);
srcPtr = Serializer::Decode<float64>(srcPtr, maxValidPtr, this->float64val);
return srcPtr;
}
int32 TestProtocol::TestMsg2::EncodedSize() const {
int32 s = TestMsg1::EncodedSize();
s += Serializer::EncodedSize<String>(this->stringval);
s += Serializer::EncodedSize<StringAtom>(this->stringatomval);
return s;
}
uint8* TestProtocol::TestMsg2::Encode(uint8* dstPtr, const uint8* maxValidPtr) const {
dstPtr = TestMsg1::Encode(dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<String>(this->stringval, dstPtr, maxValidPtr);
dstPtr = Serializer::Encode<StringAtom>(this->stringatomval, dstPtr, maxValidPtr);
return dstPtr;
}
const uint8* TestProtocol::TestMsg2::Decode(const uint8* srcPtr, const uint8* maxValidPtr) {
srcPtr = TestMsg1::Decode(srcPtr, maxValidPtr);
srcPtr = Serializer::Decode<String>(srcPtr, maxValidPtr, this->stringval);
srcPtr = Serializer::Decode<StringAtom>(srcPtr, maxValidPtr, this->stringatomval);
return srcPtr;
}
int32 TestProtocol::TestArrayMsg::EncodedSize() const {
int32 s = Message::EncodedSize();
s += Serializer::EncodedArraySize<int32>(this->int32arrayval);
s += Serializer::EncodedArraySize<String>(this->stringarrayval);
return s;
}
uint8* TestProtocol::TestArrayMsg::Encode(uint8* dstPtr, const uint8* maxValidPtr) const {
dstPtr = Message::Encode(dstPtr, maxValidPtr);
dstPtr = Serializer::EncodeArray<int32>(this->int32arrayval, dstPtr, maxValidPtr);
dstPtr = Serializer::EncodeArray<String>(this->stringarrayval, dstPtr, maxValidPtr);
return dstPtr;
}
const uint8* TestProtocol::TestArrayMsg::Decode(const uint8* srcPtr, const uint8* maxValidPtr) {
srcPtr = Message::Decode(srcPtr, maxValidPtr);
srcPtr = Serializer::DecodeArray<int32>(srcPtr, maxValidPtr, this->int32arrayval);
srcPtr = Serializer::DecodeArray<String>(srcPtr, maxValidPtr, this->stringarrayval);
return srcPtr;
}
}
9 changes: 9 additions & 0 deletions code/Modules/Messaging/UnitTests/TestProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class TestProtocol {
if (protId == 'TSTP') return true;
else return Message::IsMemberOf(protId);
};
virtual int32 EncodedSize() const override;
virtual uint8* Encode(uint8* dstPtr, const uint8* maxValidPtr) const override;
virtual const uint8* Decode(const uint8* srcPtr, const uint8* maxValidPtr) override;
void SetInt8Val(int8 val) {
this->int8val = val;
};
Expand Down Expand Up @@ -163,6 +166,9 @@ class TestProtocol {
if (protId == 'TSTP') return true;
else return TestMsg1::IsMemberOf(protId);
};
virtual int32 EncodedSize() const override;
virtual uint8* Encode(uint8* dstPtr, const uint8* maxValidPtr) const override;
virtual const uint8* Decode(const uint8* srcPtr, const uint8* maxValidPtr) override;
void SetStringVal(const String& val) {
this->stringval = val;
};
Expand Down Expand Up @@ -196,6 +202,9 @@ class TestProtocol {
if (protId == 'TSTP') return true;
else return Message::IsMemberOf(protId);
};
virtual int32 EncodedSize() const override;
virtual uint8* Encode(uint8* dstPtr, const uint8* maxValidPtr) const override;
virtual const uint8* Decode(const uint8* srcPtr, const uint8* maxValidPtr) override;
void SetInt32ArrayVal(const Array<int32>& val) {
this->int32arrayval = val;
};
Expand Down
3 changes: 3 additions & 0 deletions code/Modules/Messaging/UnitTests/TestProtocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ headers:
- 'Core/Containers/Array.h'
messages:
- name: TestMsg1
serialize: true
attrs:
- { name: Int8Val, type: int8 }
- { name: Int16Val, type: int16, default: '-1' }
Expand All @@ -21,10 +22,12 @@ messages:
- { name: Float64Val, type: float64, default: '12.0' }
- name: TestMsg2
parent: TestMsg1
serialize: true
attrs:
- { name: StringVal, type: 'String', default: '"Test"' }
- { name: StringAtomVal, type: 'StringAtom' }
- name: TestArrayMsg
serialize: true
attrs:
- { name: Int32ArrayVal, type: Array<int32> }
- { name: StringArrayVal, type: Array<String> }
Expand Down

0 comments on commit c220682

Please sign in to comment.