2 #include "BlockEvent.h"
3 #include "misc/Exception.h"
4 #include "misc/StreamAsString.h"
5 #include "misc/String.h"
10 std::string
BlockEvent::serialize() {
11 std::string serialized
= Event::serialize();
15 return Misc::StreamAsString() << Event::serialize() << std::hex
<< get_address() << ":" << get_size();
17 return Misc::StreamAsString() << Event::serialize() << std::hex
<< get_address() << ":" << get_size() << ":" << get_new_address();
19 return Misc::StreamAsString() << Event::serialize() << std::hex
<< get_address();
21 throw Misc::Exception("Asked to serialize invalid BlockEvent");
24 Misc::SmartPointer
<Event
> BlockEvent::deserialize(std::string data
) {
25 MemoryAddress address
;
26 Misc::String::to
<MemoryAddress
>(data
, address
, true);
27 /* If there's no colon, then it's a FREE_EVENT . . . */
28 if(data
.find(":") == std::string::npos
) {
29 return new BlockEvent(FREE_EVENT
, address
);
31 data
.erase(0, data
.find(":")+1);
34 Misc::String::to
<MemoryAddress
>(data
, size
, true);
35 if(data
.find(":") == std::string::npos
) {
36 return new BlockEvent(ALLOC_EVENT
, address
, size
);
39 data
.erase(0, data
.find(":")+1);
40 MemoryAddress new_address
;
41 Misc::String::to
<MemoryAddress
>(data
, new_address
, true);
43 return new BlockEvent(REALLOC_EVENT
, address
, size
, new_address
);
46 } // namespace Platform
47 } // namespace Aesalon