Skip to content

Commit

Permalink
Serialization in ServiceResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
neocoretechs committed Dec 15, 2020
1 parent 1acc930 commit 99755e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void handleRequest(T request, ByteBuffer responseBuffer) throws ServiceE
private void handleSuccess(final ChannelHandlerContext ctx, ServiceServerResponse response, ByteBuffer responseBuffer) {
response.setErrorCode(1);
response.setMessageLength(responseBuffer.limit());
response.setMessage(responseBuffer);
response.setMessageBytes(responseBuffer.array());
ByteBuffer resbuf = messageBufferPool.acquire();
Utility.serialize(response, resbuf);
try {
Expand All @@ -65,6 +65,7 @@ private void handleError(final ChannelHandlerContext ctx, ServiceServerResponse
ByteBuffer encodedMessage = Charset.forName("US-ASCII").encode(message);
response.setMessageLength(encodedMessage.limit());
response.setMessage(encodedMessage);
response.setMessageBytes(encodedMessage.array());
Utility.serialize(response, responseBuffer);
try {
ctx.write(responseBuffer.array());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
class ServiceServerResponse implements Serializable {
private static final long serialVersionUID = -5429450419100506243L;
private ByteBuffer message;
private transient ByteBuffer message;
private int errorCode;
private int messageLength;
private byte[] messageBytes;

public ServiceServerResponse() {}

Expand All @@ -43,4 +44,9 @@ public void setMessageLength(int messageLength) {
public int getMessageLength() {
return messageLength;
}

public byte[] getMessageBytes() { return messageBytes; }

public void setMessageBytes(byte[] b) { messageBytes = b; }

}

0 comments on commit 99755e2

Please sign in to comment.