use of com.google.protobuf.ByteString in project grpc-java by grpc.
the class AsyncClient method newRequest.
private SimpleRequest newRequest() {
ByteString body = ByteString.copyFrom(new byte[config.clientPayload]);
Payload payload = Payload.newBuilder().setType(config.payloadType).setBody(body).build();
return SimpleRequest.newBuilder().setResponseType(config.payloadType).setResponseSize(config.serverPayload).setPayload(payload).build();
}
use of com.google.protobuf.ByteString in project grpc-java by grpc.
the class TestServiceImpl method generatePayload.
/**
* Generates a payload of desired type and size. Reads compressableBuffer or
* uncompressableBuffer as a circular buffer.
*/
private ByteString generatePayload(ByteString dataBuffer, int offset, int size) {
ByteString payload = ByteString.EMPTY;
// This offset would never pass the array boundary.
int begin = offset;
int end = 0;
int bytesLeft = size;
while (bytesLeft > 0) {
end = Math.min(begin + bytesLeft, dataBuffer.size());
// ByteString.substring returns the substring from begin, inclusive, to end, exclusive.
payload = payload.concat(dataBuffer.substring(begin, end));
bytesLeft -= (end - begin);
begin = end % dataBuffer.size();
}
return payload;
}
use of com.google.protobuf.ByteString in project grpc-java by grpc.
the class TestServiceImpl method createBufferFromFile.
/**
* Creates a buffer with data read from a file.
*/
// Not concerned about suppression; expected to be exceedingly rare
@SuppressWarnings("Finally")
private ByteString createBufferFromFile(String fileClassPath) {
ByteString buffer = ByteString.EMPTY;
InputStream inputStream = getClass().getResourceAsStream(fileClassPath);
if (inputStream == null) {
throw new IllegalArgumentException("Unable to locate file on classpath: " + fileClassPath);
}
try {
buffer = ByteString.readFrom(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
inputStream.close();
} catch (IOException ignorable) {
// ignore
}
}
return buffer;
}
use of com.google.protobuf.ByteString in project grpc-java by grpc.
the class ProtoReflectionServiceTest method fileContainingExtension.
@Test
public void fileContainingExtension() throws Exception {
ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setFileContainingExtension(ExtensionRequest.newBuilder().setContainingType("grpc.reflection.testing.ThirdLevelType").setExtensionNumber(100).build()).build();
List<ByteString> goldenResponse = Arrays.asList(ReflectionTestProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoAlternateProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());
StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
StreamObserver<ServerReflectionRequest> requestObserver = stub.serverReflectionInfo(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<ByteString> response = responseObserver.firstValue().get().getFileDescriptorResponse().getFileDescriptorProtoList();
assertEquals(goldenResponse.size(), response.size());
assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
use of com.google.protobuf.ByteString in project grpc-java by grpc.
the class ProtoReflectionServiceTest method fileContainingSymbol.
@Test
public void fileContainingSymbol() throws Exception {
ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setFileContainingSymbol("grpc.reflection.testing.ReflectableService.Method").build();
List<ByteString> goldenResponse = Arrays.asList(ReflectionTestProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoAlternateProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());
StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
StreamObserver<ServerReflectionRequest> requestObserver = stub.serverReflectionInfo(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<ByteString> response = responseObserver.firstValue().get().getFileDescriptorResponse().getFileDescriptorProtoList();
assertEquals(goldenResponse.size(), response.size());
assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
Aggregations