Skip to content

Commit

Permalink
feat(transcoding): removed unnecessary encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Apr 20, 2024
1 parent e762697 commit 914ae38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.grpc.common.*;
import io.vertx.grpc.common.impl.GrpcMessageImpl;
import io.vertx.grpc.common.impl.Utils;
import io.vertx.grpc.server.GrpcServerResponse;

Expand Down Expand Up @@ -154,6 +153,11 @@ private Future<Void> writeMessage(GrpcMessage message, boolean end) {
throw new IllegalStateException();
}

Buffer encoded = encode(message);
if (encoded == null) {
throw new IllegalStateException("The message is null");
}

boolean trailersOnly = status != GrpcStatus.OK && !headersSent && end;

MultiMap responseHeaders = httpResponse.headers();
Expand All @@ -165,6 +169,7 @@ private Future<Void> writeMessage(GrpcMessage message, boolean end) {
}
}
responseHeaders.set("content-type", "application/json");
responseHeaders.set("content-length", String.valueOf(encoded.length()));
}

if (end) {
Expand Down Expand Up @@ -195,16 +200,11 @@ private Future<Void> writeMessage(GrpcMessage message, boolean end) {
responseTrailers.remove("grpc-message");
}
if (message != null) {
return httpResponse.end(encode(message));
return httpResponse.end(encoded);
} else {
return httpResponse.end();
}
} else {
Buffer encoded = encode(message);
// Write Content-Length header
if (encoded != null) {
responseHeaders.set("content-length", String.valueOf(encoded.length()));
}
return httpResponse.write(encoded);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.quarkus.grpc.runtime.transcoding;

import io.grpc.Decompressor;
import java.io.ByteArrayInputStream;

import io.grpc.MethodDescriptor;
import io.vertx.grpc.common.GrpcMessage;
import io.vertx.grpc.common.GrpcMessageDecoder;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class TranscodingMessageDecoder<T> implements GrpcMessageDecoder<T> {

private MethodDescriptor.Marshaller<T> marshaller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.quarkus.grpc.runtime.transcoding;

import io.grpc.Compressor;
import io.grpc.Drainable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import io.grpc.MethodDescriptor;
import io.vertx.core.buffer.Buffer;
import io.vertx.grpc.common.GrpcMessage;
import io.vertx.grpc.common.GrpcMessageEncoder;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TranscodingMessageEncoder<T> implements GrpcMessageEncoder<T> {

private MethodDescriptor.Marshaller<T> marshaller;
Expand All @@ -24,6 +20,7 @@ public TranscodingMessageEncoder(MethodDescriptor.Marshaller<T> marshaller) {
public GrpcMessage encode(T msg) {
return new GrpcMessage() {
private Buffer encoded;

@Override
public String encoding() {
return "identity";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.grpc.runtime.transcoding;

import io.vertx.grpc.common.GrpcReadStream;
import io.vertx.grpc.common.impl.BridgeMessageDecoder;

public class TranscodingReadStreamAdapter<T> {

Expand Down Expand Up @@ -49,4 +48,4 @@ public final void request(int num) {
request += num;
}
}
}
}

0 comments on commit 914ae38

Please sign in to comment.