| 8 | // ipc messages |
| 9 | |
| 10 | std::vector<u8> SerializeMessage(Message &msg) { |
| 11 | std::vector<u8> out; |
| 12 | VectorWriter writer(out); |
| 13 | |
| 14 | if (std::holds_alternative<MonitorSizeMessage>(msg)) { |
| 15 | auto &m = std::get<MonitorSizeMessage>(msg); |
| 16 | |
| 17 | writer.write(MonitorSize); |
| 18 | writer.writeOptionalMonitor(m.monitor); |
| 19 | } |
| 20 | if (std::holds_alternative<PlayPauseMessage>(msg)) { |
| 21 | auto &m = std::get<PlayPauseMessage>(msg); |
| 22 | writer.write(PlayPause); |
| 23 | writer.writeOptionalMonitor(m.monitor); |
| 24 | writer.write(m.play ? 1 : 0); |
| 25 | } |
| 26 | if (std::holds_alternative<SetWallpaperMessage>(msg)) { |
| 27 | auto &m = std::get<SetWallpaperMessage>(msg); |
| 28 | |
| 29 | writer.write(SetWallpaper); |
| 30 | writer.writeOptionalMonitor(m.monitor); |
| 31 | writer.writeu32(m.imgPath.length()); |
| 32 | writer.writeString(m.imgPath); |
| 33 | } |
| 34 | if (std::holds_alternative<RestoreMessage>(msg)) { |
| 35 | auto &m = std::get<RestoreMessage>(msg); |
| 36 | writer.write(Restore); |
| 37 | writer.writeOptionalMonitor(m.monitor); |
| 38 | } |
| 39 | |
| 40 | return out; |
| 41 | } |
| 42 | Message DeserializeMessage(char *buf, size_t len) { |
| 43 | auto bufReader = BufReader(buf, len); |
| 44 | u8 tag = bufReader.read(); |
no test coverage detected