use of com.alipay.sofa.rpc.transport.ByteStreamWrapperByteBuf in project sofa-rpc by sofastack.
the class SofaRequestHessianSerializer method encodeObject.
@Override
public AbstractByteBuf encodeObject(SofaRequest sofaRequest, Map<String, String> context) {
try {
UnsafeByteArrayOutputStream outputStream = new UnsafeByteArrayOutputStream();
Hessian2Output output = new Hessian2Output(outputStream);
// 根据SerializeType信息决定序列化器
boolean genericSerialize = context != null && isGenericRequest(context.get(RemotingConstants.HEAD_GENERIC_TYPE));
if (genericSerialize) {
output.setSerializerFactory(genericSerializerFactory);
} else {
output.setSerializerFactory(serializerFactory);
}
output.writeObject(sofaRequest);
final Object[] args = sofaRequest.getMethodArgs();
if (args != null) {
for (Object arg : args) {
output.writeObject(arg);
}
}
output.close();
return new ByteStreamWrapperByteBuf(outputStream);
} catch (IOException e) {
throw buildSerializeError(e.getMessage(), e);
}
}
use of com.alipay.sofa.rpc.transport.ByteStreamWrapperByteBuf in project sofa-rpc by sofastack.
the class SofaHessianSerializer method encode.
@Override
public AbstractByteBuf encode(Object object, Map<String, String> context) {
CustomHessianSerializer serializer = getCustomSerializer(object);
if (serializer != null) {
return serializer.encodeObject(object, context);
} else {
UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream();
Hessian2Output output = new Hessian2Output(byteArray);
try {
output.setSerializerFactory(serializerFactory);
output.writeObject(object);
output.close();
return new ByteStreamWrapperByteBuf(byteArray);
} catch (Exception e) {
throw buildSerializeError(e.getMessage(), e);
}
}
}
use of com.alipay.sofa.rpc.transport.ByteStreamWrapperByteBuf in project sofa-rpc by sofastack.
the class SofaResponseHessianSerializer method encodeObject.
@Override
public AbstractByteBuf encodeObject(SofaResponse sofaResponse, Map<String, String> context) {
try {
UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream();
Hessian2Output output = new Hessian2Output(byteArray);
output.setSerializerFactory(serializerFactory);
output.writeObject(sofaResponse);
output.close();
return new ByteStreamWrapperByteBuf(byteArray);
} catch (IOException e) {
throw buildSerializeError(e.getMessage(), e);
}
}
Aggregations