brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #include "aos/common/queue.h" |
| 2 | |
| 3 | #include "aos/common/byteorder.h" |
| 4 | #include "aos/common/inttypes.h" |
| 5 | |
| 6 | namespace aos { |
| 7 | |
| 8 | void Message::Zero() { |
| 9 | sent_time.set_sec(0); |
| 10 | sent_time.set_nsec(0); |
| 11 | } |
| 12 | |
| 13 | size_t Message::Deserialize(const char *buffer) { |
| 14 | int32_t sec; |
| 15 | int32_t nsec; |
| 16 | to_host(&buffer[0], &sec); |
| 17 | to_host(&buffer[4], &nsec); |
| 18 | sent_time.set_sec(sec); |
| 19 | sent_time.set_nsec(nsec); |
| 20 | return Size(); |
| 21 | } |
| 22 | // Serializes the common fields into the buffer. |
| 23 | size_t Message::Serialize(char *buffer) const { |
| 24 | // TODO(aschuh): to_network shouldn't need a pointer. |
| 25 | int32_t sec = sent_time.sec(); |
| 26 | int32_t nsec = sent_time.nsec(); |
| 27 | to_network(&sec, &buffer[0]); |
| 28 | to_network(&nsec, &buffer[4]); |
| 29 | return Size(); |
| 30 | } |
| 31 | |
| 32 | size_t Message::Print(char *buffer, int length) const { |
| 33 | return snprintf(buffer, length, "%"PRId32".%09"PRId32"s", |
| 34 | sent_time.sec(), sent_time.nsec()); |
| 35 | } |
| 36 | |
| 37 | } // namespace aos |