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) .setUri(path)
.putAllHeaders(headersMap) .putAllHeaders(headersMap)
.build(); .build();
Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(body.getBytes()))
.build();
GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest
.newBuilder() .newBuilder()
.setMetadata(metadata) .setMetadata(metadata)
.setReqId(reqId) .setReqId(reqId)
.setBody(build) .setBody(body)
.build(); .build();
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor = MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,17 +29,14 @@ public interface GrpcSnailJobRequestOrBuilder extends
com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder(); com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder();
/** /**
* <code>.google.protobuf.Any body = 3;</code> * <code>string body = 3;</code>
* @return Whether the body field is set.
*/
boolean hasBody();
/**
* <code>.google.protobuf.Any body = 3;</code>
* @return The body. * @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" + "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" + "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" + "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" + ":\0028\001\"O\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\022\033\n\010metadata\030\002 \001(\0132\t.Metadata\022\014\n\004body\030" +
"\003 \001(\0132\024.google.protobuf.Any\"`\n\nGrpcResul" + "\003 \001(\t\"J\n\nGrpcResult\022\r\n\005reqId\030\001 \001(\003\022\016\n\006st" +
"t\022\r\n\005reqId\030\001 \001(\003\022\016\n\006status\030\002 \001(\005\022\017\n\007mess" + "atus\030\002 \001(\005\022\017\n\007message\030\003 \001(\t\022\014\n\004data\030\004 \001(" +
"age\030\003 \001(\t\022\"\n\004data\030\004 \001(\0132\024.google.protobu" + "\tB-\n)com.aizuda.snailjob.common.core.grp" +
"f.AnyB-\n)com.aizuda.snailjob.common.core" + "c.autoP\001b\006proto3"
".grpc.autoP\001b\006proto3"
}; };
descriptor = com.google.protobuf.Descriptors.FileDescriptor descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData, .internalBuildGeneratedFileFrom(descriptorData,

View File

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

View File

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

View File

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

View File

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