Serializer.java
905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.onlab.netty;
import java.nio.ByteBuffer;
/**
* Interface for encoding/decoding message payloads.
*/
public interface Serializer {
/**
* Decodes the specified byte array to a POJO.
*
* @param data byte array.
* @return POJO
*/
public <T> T decode(byte[] data);
/**
* Encodes the specified POJO into a byte array.
*
* @param data POJO to be encoded
* @return byte array.
*/
public byte[] encode(Object data);
/**
* Encodes the specified POJO into a byte buffer.
*
* @param data POJO to be encoded
* @param buffer to write serialized bytes
*/
public void encode(final Object data, ByteBuffer buffer);
/**
* Decodes the specified byte buffer to a POJO.
*
* @param buffer bytes to be decoded
* @return POJO
*/
public <T> T decode(final ByteBuffer buffer);
}