I just realized something . . .
[aesalon.git] / monitor / src / event / BlockEvent.cpp
blob9fdd6c64a037c104e10ac4584d4adb5da0ae37c9
1 #include <iostream>
2 #include "BlockEvent.h"
3 #include "exception/EventException.h"
4 #include "misc/StreamAsString.h"
6 namespace Event {
8 /* serialization format:
9 first bit is taken by BasicEvent
10 second and third bits are block_type
11 rest of the first byte is reserved
12 after that, depends on type . . .
14 Block *BlockEvent::serialize() {
15 Block *serialized = BasicEvent::serialize();
17 serialized->get_data()[0] |= (block_type << 1) & 0x06;
19 serialized->push_word(get_address());
21 switch(get_block_type()) {
22 case ALLOC_EVENT:
23 std::cout << "first byte of address is " << std::hex << (address & 0xff) << std::endl;
24 std::cout << "second byte of address is " << std::hex << ((address & 0xff00) >> 8) << std::endl;
25 serialized->push_word(get_size());
26 break;
27 case REALLOC_EVENT:
28 /* NOTE: the new address first makes it easier to deserialize later */
29 serialized->push_word(get_new_address());
30 serialized->push_word(get_size());
31 break;
32 case FREE_EVENT: break;
33 default:
34 throw Exception::EventException("Asked to serialize invalid Block event");
37 return serialized;
40 } // namespace Event