feat:(grpc): 修改proto文件Any类型改为string

This commit is contained in:
opensnail 2024-10-22 16:32:17 +08:00
parent 037eeb497f
commit 94a1329220
13 changed files with 202 additions and 332 deletions

View File

@ -171,13 +171,11 @@ public final class GrpcChannel {
.setUri(path)
.putAllHeaders(headersMap)
.build();
Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(body.getBytes()))
.build();
GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest
.newBuilder()
.setMetadata(metadata)
.setReqId(reqId)
.setBody(build)
.setBody(body)
.build();
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =

View File

@ -78,8 +78,7 @@ public class GrpcClientInvokeHandler<R extends Result<Object>> implements Invoca
@Override
public void onSuccess(final GrpcResult result) {
ByteBuffer byteBuffer = result.getData().getValue().asReadOnlyByteBuffer();
Object obj = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object.class);
Object obj = JsonUtil.parseObject( result.getData(), Object.class);
consumer.accept(
(R) new SnailJobRpcResult(result.getStatus(), result.getMessage(), obj, result.getReqId()));
}
@ -96,8 +95,7 @@ public class GrpcClientInvokeHandler<R extends Result<Object>> implements Invoca
try {
GrpcResult result = future.get(timeout, unit);
ByteBuffer byteBuffer = result.getData().getValue().asReadOnlyByteBuffer();
Object obj = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object.class);
Object obj = JsonUtil.parseObject(result.getData(), Object.class);
return (R) new SnailJobRpcResult(result.getStatus(), result.getMessage(), obj, result.getReqId());
} catch (ExecutionException e) {
throw e.getCause();

View File

@ -146,9 +146,7 @@ public class SnailDispatcherRequestHandler {
Class<?>[] paramTypes = endPointInfo.getMethod().getParameterTypes();
GrpcSnailJobRequest grpcSnailJobRequest = request.getSnailJobRequest();
Any body = grpcSnailJobRequest.getBody();
ByteBuffer byteBuffer = body.getValue().asReadOnlyByteBuffer();
Object[] args = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object[].class);
Object[] args = JsonUtil.parseObject(grpcSnailJobRequest.getBody(), Object[].class);
Object[] deSerialize = (Object[]) deSerialize(JsonUtil.toJsonString(args), endPointInfo.getMethod(),
httpRequest, httpResponse);

View File

@ -62,10 +62,7 @@ public class UnaryRequestHandler implements ServerCalls.UnaryMethod<GrpcSnailJob
GrpcResult grpcResult = GrpcResult.newBuilder()
.setStatus(snailJobRpcResult.getStatus())
.setMessage(Optional.ofNullable(snailJobRpcResult.getMessage()).orElse(StrUtil.EMPTY))
.setData(Any.newBuilder()
.setValue(UnsafeByteOperations.unsafeWrap(
JsonUtil.toJsonString(snailJobRpcResult.getData()).getBytes()))
.build())
.setData(JsonUtil.toJsonString(snailJobRpcResult.getData()))
.build();
streamObserver.onNext(grpcResult);

View File

@ -17,6 +17,7 @@ private static final long serialVersionUID = 0L;
}
private GrpcResult() {
message_ = "";
data_ = "";
}
@java.lang.Override
@ -39,7 +40,6 @@ private static final long serialVersionUID = 0L;
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.class, com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.Builder.class);
}
private int bitField0_;
public static final int REQID_FIELD_NUMBER = 1;
private long reqId_ = 0L;
/**
@ -102,29 +102,42 @@ private static final long serialVersionUID = 0L;
}
public static final int DATA_FIELD_NUMBER = 4;
private com.google.protobuf.Any data_;
@SuppressWarnings("serial")
private volatile java.lang.Object data_ = "";
/**
* <code>.google.protobuf.Any data = 4;</code>
* @return Whether the data field is set.
*/
@java.lang.Override
public boolean hasData() {
return ((bitField0_ & 0x00000001) != 0);
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The data.
*/
@java.lang.Override
public com.google.protobuf.Any getData() {
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
public java.lang.String getData() {
java.lang.Object ref = data_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
data_ = s;
return s;
}
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The bytes for data.
*/
@java.lang.Override
public com.google.protobuf.AnyOrBuilder getDataOrBuilder() {
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
public com.google.protobuf.ByteString
getDataBytes() {
java.lang.Object ref = data_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
data_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@ -150,8 +163,8 @@ private static final long serialVersionUID = 0L;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, message_);
}
if (((bitField0_ & 0x00000001) != 0)) {
output.writeMessage(4, getData());
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(data_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 4, data_);
}
getUnknownFields().writeTo(output);
}
@ -173,9 +186,8 @@ private static final long serialVersionUID = 0L;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, message_);
}
if (((bitField0_ & 0x00000001) != 0)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(4, getData());
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(data_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, data_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
@ -198,11 +210,8 @@ private static final long serialVersionUID = 0L;
!= other.getStatus()) return false;
if (!getMessage()
.equals(other.getMessage())) return false;
if (hasData() != other.hasData()) return false;
if (hasData()) {
if (!getData()
.equals(other.getData())) return false;
}
if (!getData()
.equals(other.getData())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -221,10 +230,8 @@ private static final long serialVersionUID = 0L;
hash = (53 * hash) + getStatus();
hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
hash = (53 * hash) + getMessage().hashCode();
if (hasData()) {
hash = (37 * hash) + DATA_FIELD_NUMBER;
hash = (53 * hash) + getData().hashCode();
}
hash = (37 * hash) + DATA_FIELD_NUMBER;
hash = (53 * hash) + getData().hashCode();
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -344,19 +351,13 @@ private static final long serialVersionUID = 0L;
// Construct using com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
getDataFieldBuilder();
}
}
@java.lang.Override
public Builder clear() {
@ -365,11 +366,7 @@ private static final long serialVersionUID = 0L;
reqId_ = 0L;
status_ = 0;
message_ = "";
data_ = null;
if (dataBuilder_ != null) {
dataBuilder_.dispose();
dataBuilder_ = null;
}
data_ = "";
return this;
}
@ -412,14 +409,9 @@ private static final long serialVersionUID = 0L;
if (((from_bitField0_ & 0x00000004) != 0)) {
result.message_ = message_;
}
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000008) != 0)) {
result.data_ = dataBuilder_ == null
? data_
: dataBuilder_.build();
to_bitField0_ |= 0x00000001;
result.data_ = data_;
}
result.bitField0_ |= to_bitField0_;
}
@java.lang.Override
@ -477,8 +469,10 @@ private static final long serialVersionUID = 0L;
bitField0_ |= 0x00000004;
onChanged();
}
if (other.hasData()) {
mergeData(other.getData());
if (!other.getData().isEmpty()) {
data_ = other.data_;
bitField0_ |= 0x00000008;
onChanged();
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
@ -522,9 +516,7 @@ private static final long serialVersionUID = 0L;
break;
} // case 26
case 34: {
input.readMessage(
getDataFieldBuilder().getBuilder(),
extensionRegistry);
data_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000008;
break;
} // case 34
@ -681,125 +673,76 @@ private static final long serialVersionUID = 0L;
return this;
}
private com.google.protobuf.Any data_;
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_;
private java.lang.Object data_ = "";
/**
* <code>.google.protobuf.Any data = 4;</code>
* @return Whether the data field is set.
*/
public boolean hasData() {
return ((bitField0_ & 0x00000008) != 0);
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The data.
*/
public com.google.protobuf.Any getData() {
if (dataBuilder_ == null) {
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
public java.lang.String getData() {
java.lang.Object ref = data_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
data_ = s;
return s;
} else {
return dataBuilder_.getMessage();
return (java.lang.String) ref;
}
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The bytes for data.
*/
public Builder setData(com.google.protobuf.Any value) {
if (dataBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
data_ = value;
public com.google.protobuf.ByteString
getDataBytes() {
java.lang.Object ref = data_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
data_ = b;
return b;
} else {
dataBuilder_.setMessage(value);
return (com.google.protobuf.ByteString) ref;
}
bitField0_ |= 0x00000008;
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @param value The data to set.
* @return This builder for chaining.
*/
public Builder setData(
com.google.protobuf.Any.Builder builderForValue) {
if (dataBuilder_ == null) {
data_ = builderForValue.build();
} else {
dataBuilder_.setMessage(builderForValue.build());
}
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
data_ = value;
bitField0_ |= 0x00000008;
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any data = 4;</code>
*/
public Builder mergeData(com.google.protobuf.Any value) {
if (dataBuilder_ == null) {
if (((bitField0_ & 0x00000008) != 0) &&
data_ != null &&
data_ != com.google.protobuf.Any.getDefaultInstance()) {
getDataBuilder().mergeFrom(value);
} else {
data_ = value;
}
} else {
dataBuilder_.mergeFrom(value);
}
if (data_ != null) {
bitField0_ |= 0x00000008;
onChanged();
}
return this;
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return This builder for chaining.
*/
public Builder clearData() {
data_ = getDefaultInstance().getData();
bitField0_ = (bitField0_ & ~0x00000008);
data_ = null;
if (dataBuilder_ != null) {
dataBuilder_.dispose();
dataBuilder_ = null;
}
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @param value The bytes for data to set.
* @return This builder for chaining.
*/
public com.google.protobuf.Any.Builder getDataBuilder() {
public Builder setDataBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
data_ = value;
bitField0_ |= 0x00000008;
onChanged();
return getDataFieldBuilder().getBuilder();
}
/**
* <code>.google.protobuf.Any data = 4;</code>
*/
public com.google.protobuf.AnyOrBuilder getDataOrBuilder() {
if (dataBuilder_ != null) {
return dataBuilder_.getMessageOrBuilder();
} else {
return data_ == null ?
com.google.protobuf.Any.getDefaultInstance() : data_;
}
}
/**
* <code>.google.protobuf.Any data = 4;</code>
*/
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>
getDataFieldBuilder() {
if (dataBuilder_ == null) {
dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>(
getData(),
getParentForChildren(),
isClean());
data_ = null;
}
return dataBuilder_;
return this;
}
@java.lang.Override
public final Builder setUnknownFields(

View File

@ -32,17 +32,14 @@ public interface GrpcResultOrBuilder extends
getMessageBytes();
/**
* <code>.google.protobuf.Any data = 4;</code>
* @return Whether the data field is set.
*/
boolean hasData();
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The data.
*/
com.google.protobuf.Any getData();
java.lang.String getData();
/**
* <code>.google.protobuf.Any data = 4;</code>
* <code>string data = 4;</code>
* @return The bytes for data.
*/
com.google.protobuf.AnyOrBuilder getDataOrBuilder();
com.google.protobuf.ByteString
getDataBytes();
}

View File

@ -16,6 +16,7 @@ private static final long serialVersionUID = 0L;
super(builder);
}
private GrpcSnailJobRequest() {
body_ = "";
}
@java.lang.Override
@ -77,29 +78,42 @@ private static final long serialVersionUID = 0L;
}
public static final int BODY_FIELD_NUMBER = 3;
private com.google.protobuf.Any body_;
@SuppressWarnings("serial")
private volatile java.lang.Object body_ = "";
/**
* <code>.google.protobuf.Any body = 3;</code>
* @return Whether the body field is set.
*/
@java.lang.Override
public boolean hasBody() {
return ((bitField0_ & 0x00000002) != 0);
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The body.
*/
@java.lang.Override
public com.google.protobuf.Any getBody() {
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
public java.lang.String getBody() {
java.lang.Object ref = body_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
body_ = s;
return s;
}
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The bytes for body.
*/
@java.lang.Override
public com.google.protobuf.AnyOrBuilder getBodyOrBuilder() {
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
public com.google.protobuf.ByteString
getBodyBytes() {
java.lang.Object ref = body_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
body_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@ -122,8 +136,8 @@ private static final long serialVersionUID = 0L;
if (((bitField0_ & 0x00000001) != 0)) {
output.writeMessage(2, getMetadata());
}
if (((bitField0_ & 0x00000002) != 0)) {
output.writeMessage(3, getBody());
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(body_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, body_);
}
getUnknownFields().writeTo(output);
}
@ -142,9 +156,8 @@ private static final long serialVersionUID = 0L;
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(2, getMetadata());
}
if (((bitField0_ & 0x00000002) != 0)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(3, getBody());
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(body_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, body_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
@ -168,11 +181,8 @@ private static final long serialVersionUID = 0L;
if (!getMetadata()
.equals(other.getMetadata())) return false;
}
if (hasBody() != other.hasBody()) return false;
if (hasBody()) {
if (!getBody()
.equals(other.getBody())) return false;
}
if (!getBody()
.equals(other.getBody())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -191,10 +201,8 @@ private static final long serialVersionUID = 0L;
hash = (37 * hash) + METADATA_FIELD_NUMBER;
hash = (53 * hash) + getMetadata().hashCode();
}
if (hasBody()) {
hash = (37 * hash) + BODY_FIELD_NUMBER;
hash = (53 * hash) + getBody().hashCode();
}
hash = (37 * hash) + BODY_FIELD_NUMBER;
hash = (53 * hash) + getBody().hashCode();
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -326,7 +334,6 @@ private static final long serialVersionUID = 0L;
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
getMetadataFieldBuilder();
getBodyFieldBuilder();
}
}
@java.lang.Override
@ -339,11 +346,7 @@ private static final long serialVersionUID = 0L;
metadataBuilder_.dispose();
metadataBuilder_ = null;
}
body_ = null;
if (bodyBuilder_ != null) {
bodyBuilder_.dispose();
bodyBuilder_ = null;
}
body_ = "";
return this;
}
@ -388,10 +391,7 @@ private static final long serialVersionUID = 0L;
to_bitField0_ |= 0x00000001;
}
if (((from_bitField0_ & 0x00000004) != 0)) {
result.body_ = bodyBuilder_ == null
? body_
: bodyBuilder_.build();
to_bitField0_ |= 0x00000002;
result.body_ = body_;
}
result.bitField0_ |= to_bitField0_;
}
@ -446,8 +446,10 @@ private static final long serialVersionUID = 0L;
if (other.hasMetadata()) {
mergeMetadata(other.getMetadata());
}
if (other.hasBody()) {
mergeBody(other.getBody());
if (!other.getBody().isEmpty()) {
body_ = other.body_;
bitField0_ |= 0x00000004;
onChanged();
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
@ -488,9 +490,7 @@ private static final long serialVersionUID = 0L;
break;
} // case 18
case 26: {
input.readMessage(
getBodyFieldBuilder().getBuilder(),
extensionRegistry);
body_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000004;
break;
} // case 26
@ -664,125 +664,76 @@ private static final long serialVersionUID = 0L;
return metadataBuilder_;
}
private com.google.protobuf.Any body_;
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> bodyBuilder_;
private java.lang.Object body_ = "";
/**
* <code>.google.protobuf.Any body = 3;</code>
* @return Whether the body field is set.
*/
public boolean hasBody() {
return ((bitField0_ & 0x00000004) != 0);
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The body.
*/
public com.google.protobuf.Any getBody() {
if (bodyBuilder_ == null) {
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
public java.lang.String getBody() {
java.lang.Object ref = body_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
body_ = s;
return s;
} else {
return bodyBuilder_.getMessage();
return (java.lang.String) ref;
}
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The bytes for body.
*/
public Builder setBody(com.google.protobuf.Any value) {
if (bodyBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
body_ = value;
public com.google.protobuf.ByteString
getBodyBytes() {
java.lang.Object ref = body_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
body_ = b;
return b;
} else {
bodyBuilder_.setMessage(value);
return (com.google.protobuf.ByteString) ref;
}
bitField0_ |= 0x00000004;
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @param value The body to set.
* @return This builder for chaining.
*/
public Builder setBody(
com.google.protobuf.Any.Builder builderForValue) {
if (bodyBuilder_ == null) {
body_ = builderForValue.build();
} else {
bodyBuilder_.setMessage(builderForValue.build());
}
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
body_ = value;
bitField0_ |= 0x00000004;
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any body = 3;</code>
*/
public Builder mergeBody(com.google.protobuf.Any value) {
if (bodyBuilder_ == null) {
if (((bitField0_ & 0x00000004) != 0) &&
body_ != null &&
body_ != com.google.protobuf.Any.getDefaultInstance()) {
getBodyBuilder().mergeFrom(value);
} else {
body_ = value;
}
} else {
bodyBuilder_.mergeFrom(value);
}
if (body_ != null) {
bitField0_ |= 0x00000004;
onChanged();
}
return this;
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return This builder for chaining.
*/
public Builder clearBody() {
body_ = getDefaultInstance().getBody();
bitField0_ = (bitField0_ & ~0x00000004);
body_ = null;
if (bodyBuilder_ != null) {
bodyBuilder_.dispose();
bodyBuilder_ = null;
}
onChanged();
return this;
}
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @param value The bytes for body to set.
* @return This builder for chaining.
*/
public com.google.protobuf.Any.Builder getBodyBuilder() {
public Builder setBodyBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
body_ = value;
bitField0_ |= 0x00000004;
onChanged();
return getBodyFieldBuilder().getBuilder();
}
/**
* <code>.google.protobuf.Any body = 3;</code>
*/
public com.google.protobuf.AnyOrBuilder getBodyOrBuilder() {
if (bodyBuilder_ != null) {
return bodyBuilder_.getMessageOrBuilder();
} else {
return body_ == null ?
com.google.protobuf.Any.getDefaultInstance() : body_;
}
}
/**
* <code>.google.protobuf.Any body = 3;</code>
*/
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>
getBodyFieldBuilder() {
if (bodyBuilder_ == null) {
bodyBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>(
getBody(),
getParentForChildren(),
isClean());
body_ = null;
}
return bodyBuilder_;
return this;
}
@java.lang.Override
public final Builder setUnknownFields(

View File

@ -29,17 +29,14 @@ public interface GrpcSnailJobRequestOrBuilder extends
com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder();
/**
* <code>.google.protobuf.Any body = 3;</code>
* @return Whether the body field is set.
*/
boolean hasBody();
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The body.
*/
com.google.protobuf.Any getBody();
java.lang.String getBody();
/**
* <code>.google.protobuf.Any body = 3;</code>
* <code>string body = 3;</code>
* @return The bytes for body.
*/
com.google.protobuf.AnyOrBuilder getBodyOrBuilder();
com.google.protobuf.ByteString
getBodyBytes();
}

View File

@ -48,13 +48,12 @@ public final class SnailJobGrpcService {
"tamp.proto\"p\n\010Metadata\022\013\n\003uri\030\003 \001(\t\022\'\n\007h" +
"eaders\030\007 \003(\0132\026.Metadata.HeadersEntry\032.\n\014" +
"HeadersEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t" +
":\0028\001\"e\n\023GrpcSnailJobRequest\022\r\n\005reqId\030\001 \001" +
"(\003\022\033\n\010metadata\030\002 \001(\0132\t.Metadata\022\"\n\004body\030" +
"\003 \001(\0132\024.google.protobuf.Any\"`\n\nGrpcResul" +
"t\022\r\n\005reqId\030\001 \001(\003\022\016\n\006status\030\002 \001(\005\022\017\n\007mess" +
"age\030\003 \001(\t\022\"\n\004data\030\004 \001(\0132\024.google.protobu" +
"f.AnyB-\n)com.aizuda.snailjob.common.core" +
".grpc.autoP\001b\006proto3"
":\0028\001\"O\n\023GrpcSnailJobRequest\022\r\n\005reqId\030\001 \001" +
"(\003\022\033\n\010metadata\030\002 \001(\0132\t.Metadata\022\014\n\004body\030" +
"\003 \001(\t\"J\n\nGrpcResult\022\r\n\005reqId\030\001 \001(\003\022\016\n\006st" +
"atus\030\002 \001(\005\022\017\n\007message\030\003 \001(\t\022\014\n\004data\030\004 \001(" +
"\tB-\n)com.aizuda.snailjob.common.core.grp" +
"c.autoP\001b\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,

View File

@ -14,12 +14,12 @@ message Metadata {
message GrpcSnailJobRequest {
int64 reqId = 1;
Metadata metadata = 2;
google.protobuf.Any body = 3;
string body = 3;
}
message GrpcResult {
int64 reqId = 1;
int32 status = 2;
string message = 3;
google.protobuf.Any data = 4;
string data = 4;
}

View File

@ -81,13 +81,11 @@ public class GrpcChannel {
.setUri(url)
.putAllHeaders(headersMap)
.build();
Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(body.getBytes()))
.build();
GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest
.newBuilder()
.setMetadata(metadata)
.setReqId(reqId)
.setBody(build)
.setBody(body)
.build();
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =

View File

@ -170,8 +170,7 @@ public class GrpcClientInvokeHandler implements InvocationHandler {
Assert.notNull(future, () -> new SnailJobServerException("completableFuture is null"));
GrpcResult grpcResult = future.get(Optional.ofNullable(executorTimeout).orElse(20),
TimeUnit.SECONDS);
ByteBuffer byteBuffer = grpcResult.getData().getValue().asReadOnlyByteBuffer();
Object obj = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object.class);
Object obj = JsonUtil.parseObject(grpcResult.getData(), Object.class);
return new Result(grpcResult.getStatus(), grpcResult.getMessage(), obj);
}

View File

@ -74,10 +74,8 @@ public class GrpcRequestHandlerActor extends AbstractActor {
SnailJobRpcResult snailJobRpcResult = null;
try {
SnailJobRequest request = new SnailJobRequest();
Any body = grpcSnailJobRequest.getBody();
ByteString byteString = body.getValue();
ByteBuffer byteBuffer = byteString.asReadOnlyByteBuffer();
Object[] objects = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object[].class);
String body = grpcSnailJobRequest.getBody();
Object[] objects = JsonUtil.parseObject(body, Object[].class);
request.setArgs(objects);
snailJobRpcResult = doProcess(uri, JsonUtil.toJsonString(request), headersMap);
if (Objects.isNull(snailJobRpcResult)) {
@ -94,10 +92,7 @@ public class GrpcRequestHandlerActor extends AbstractActor {
.setReqId(snailJobRpcResult.getReqId())
.setStatus(snailJobRpcResult.getStatus())
.setMessage(Optional.ofNullable(snailJobRpcResult.getMessage()).orElse(StrUtil.EMPTY))
.setData(Any.newBuilder()
.setValue(UnsafeByteOperations.unsafeWrap(
JsonUtil.toJsonString(snailJobRpcResult.getData()).getBytes()))
.build())
.setData(JsonUtil.toJsonString(snailJobRpcResult.getData()))
.build();
streamObserver.onNext(grpcResult);
streamObserver.onCompleted();