(MapMessage<K,V> message)
| 16 | } |
| 17 | |
| 18 | public static <K,V> byte[] toBytes(MapMessage<K,V> message) throws IOException { |
| 19 | ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); |
| 20 | ObjectOutputStream objOut = new ObjectOutputStream(byteOut); |
| 21 | boolean hasType = message.getType() != null; |
| 22 | objOut.writeBoolean(hasType); |
| 23 | if(hasType) { |
| 24 | objOut.writeObject(message.getType()); |
| 25 | } |
| 26 | boolean hasKey = message.getKey() != null; |
| 27 | objOut.writeBoolean(hasKey); |
| 28 | if(hasKey) { |
| 29 | objOut.writeObject(message.getKey()); |
| 30 | } |
| 31 | boolean hasValue = message.getValue() != null; |
| 32 | objOut.writeBoolean(hasValue); |
| 33 | if(hasValue) { |
| 34 | objOut.writeObject(message.getValue()); |
| 35 | } |
| 36 | objOut.writeInt(message.getSize()); |
| 37 | boolean hasKeySet = message.getKeySet() != null; |
| 38 | objOut.writeBoolean(hasKeySet); |
| 39 | if(message.getKeySet() != null) { |
| 40 | Set<K> keySet = message.getKeySet(); |
| 41 | int size = keySet.size(); |
| 42 | objOut.writeInt(size); |
| 43 | for (K key : keySet) |
| 44 | objOut.writeObject(key); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | objOut.flush(); |
| 49 | byteOut.flush(); |
| 50 | |
| 51 | return byteOut.toByteArray(); |
| 52 | } |
| 53 | |
| 54 | @SuppressWarnings("unchecked") |
| 55 | public static <K,V> MapMessage<K,V> fromBytes(byte[] rep) throws IOException, ClassNotFoundException { |
no test coverage detected