Encoder interface. Turn an object into a byte[].
| 53 | * Encoder interface. Turn an object into a byte[]. |
| 54 | */ |
| 55 | @FunctionalInterface |
| 56 | interface Encoder { |
| 57 | Encoder SERIALIZE = (m) -> { |
| 58 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 59 | ObjectOutputStream oos = new ObjectOutputStream(baos); |
| 60 | oos.writeUnshared(m); |
| 61 | oos.flush(); |
| 62 | return baos.toByteArray(); |
| 63 | }; |
| 64 | |
| 65 | byte[] encode(Object msg) throws IOException; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Decoder interface. Turn a single byte[] into an object. |
no test coverage detected