Search in sources :

Example 1 with DelegateServerCallStreamObserver

use of build.buildfarm.common.grpc.DelegateServerCallStreamObserver in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method newChunkObserver.

ServerCallStreamObserver<ByteString> newChunkObserver(ServerCallStreamObserver<ReadResponse> responseObserver) {
    return new DelegateServerCallStreamObserver<ByteString, ReadResponse>(responseObserver) {

        @Override
        public void onNext(ByteString data) {
            while (!data.isEmpty()) {
                ByteString slice;
                if (data.size() > CHUNK_SIZE) {
                    slice = data.substring(0, CHUNK_SIZE);
                    data = data.substring(CHUNK_SIZE);
                } else {
                    slice = data;
                    data = ByteString.EMPTY;
                }
                responseObserver.onNext(ReadResponse.newBuilder().setData(slice).build());
            }
        }

        @Override
        public void onError(Throwable t) {
            responseObserver.onError(t);
        }

        @Override
        public void onCompleted() {
            responseObserver.onCompleted();
        }
    };
}
Also used : ByteString(com.google.protobuf.ByteString) UniformDelegateServerCallStreamObserver(build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver) DelegateServerCallStreamObserver(build.buildfarm.common.grpc.DelegateServerCallStreamObserver)

Aggregations

DelegateServerCallStreamObserver (build.buildfarm.common.grpc.DelegateServerCallStreamObserver)1 UniformDelegateServerCallStreamObserver (build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver)1 ByteString (com.google.protobuf.ByteString)1