MCPcopy Create free account
hub / github.com/bft-smart/library / toBytes

Method toBytes

src/main/java/bftsmart/demo/map/MapMessage.java:18–52  ·  view source on GitHub ↗
(MapMessage<K,V> message)

Source from the content-addressed store, hash-verified

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 {

Callers 7

appExecuteOrderedMethod · 0.95
appExecuteUnorderedMethod · 0.95
putMethod · 0.95
getMethod · 0.95
removeMethod · 0.95
sizeMethod · 0.95
keySetMethod · 0.95

Calls 6

getSizeMethod · 0.80
getKeySetMethod · 0.80
sizeMethod · 0.80
getTypeMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected