use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-jraft by sofastack.
the class ProtobufSerializerTest method testEncodeDecodeResponseContent.
@Test
public void testEncodeDecodeResponseContent() throws Exception {
final PingRequest reqObject = TestUtils.createPingRequest();
final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
final ErrorResponse respObject = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null, new Status(-1, "test"));
final RpcResponseCommand response = cmdFactory.createResponse(respObject, request);
response.setResponseClass(ErrorResponse.class.getName());
assertTrue(serializer.serializeContent(response));
response.setResponseObject(null);
assertTrue(serializer.deserializeContent(response, null));
assertNotNull(response.getResponseObject());
assertEquals(respObject, response.getResponseObject());
assertNotSame(respObject, response.getResponseObject());
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-jraft by sofastack.
the class ProtobufSerializerTest method testEncodeDecodeRequestContent.
@Test
public void testEncodeDecodeRequestContent() throws Exception {
final PingRequest reqObject = TestUtils.createPingRequest();
final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
request.setRequestClass(PingRequest.class.getName());
assertTrue(serializer.serializeContent(request, null));
request.setRequestObject(null);
assertTrue(serializer.deserializeContent(request));
assertNotNull(request.getRequestObject());
assertEquals(reqObject, request.getRequestObject());
assertNotSame(reqObject, request.getRequestObject());
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-jraft by sofastack.
the class ProtobufSerializer method serializeContent.
@Override
public <T extends RequestCommand> boolean serializeContent(T request, InvokeContext invokeContext) throws SerializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final Message msg = (Message) cmd.getRequestObject();
cmd.setContent(msg.toByteArray());
return true;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-jraft by sofastack.
the class ProtobufSerializer method deserializeHeader.
@Override
public <T extends RequestCommand> boolean deserializeHeader(T request) throws DeserializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final String className = cmd.getRequestClass();
if (className.equals(RpcRequests.AppendEntriesRequest.class.getName())) {
final byte[] header = cmd.getHeader();
cmd.setRequestHeader(ProtobufMsgFactory.newMessageByJavaClassName(RpcRequests.AppendEntriesRequestHeader.class.getName(), header));
return true;
}
return false;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-jraft by sofastack.
the class ProtobufSerializer method deserializeContent.
@Override
public <T extends RequestCommand> boolean deserializeContent(T request) throws DeserializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final String className = cmd.getRequestClass();
cmd.setRequestObject(ProtobufMsgFactory.newMessageByJavaClassName(className, request.getContent()));
return true;
}
Aggregations