use of cn.taketoday.protobuf.Msg in project today-infrastructure by TAKETODAY.
the class ProtobufDecoderTests method decodeSplitMessageSize.
// SPR-17429
@Test
public void decodeSplitMessageSize() {
this.decoder.setMaxMessageSize(100009);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 10000; i++) {
builder.append("azertyuiop");
}
Msg bigMessage = Msg.newBuilder().setFoo(builder.toString()).setBlah(secondMsg2).build();
Flux<DataBuffer> input = Flux.just(bigMessage, bigMessage).flatMap(msg -> Mono.defer(() -> {
DataBuffer buffer = this.bufferFactory.allocateBuffer();
try {
msg.writeDelimitedTo(buffer.asOutputStream());
return Mono.just(buffer);
} catch (IOException e) {
release(buffer);
return Mono.error(e);
}
})).flatMap(buffer -> {
int len = 2;
Flux<DataBuffer> result = Flux.just(DataBufferUtils.retain(buffer.slice(0, len)), DataBufferUtils.retain(buffer.slice(len, buffer.readableByteCount() - len)));
release(buffer);
return result;
});
testDecode(input, Msg.class, step -> step.expectNext(bigMessage).expectNext(bigMessage).verifyComplete());
}
use of cn.taketoday.protobuf.Msg in project today-infrastructure by TAKETODAY.
the class CancelWithoutDemandCodecTests method cancelWithProtobufDecoder.
// gh-22731
@Test
public void cancelWithProtobufDecoder() throws InterruptedException {
ProtobufDecoder decoder = new ProtobufDecoder();
Mono<DataBuffer> input = Mono.fromCallable(() -> {
Msg msg = Msg.newBuilder().setFoo("Foo").build();
byte[] bytes = msg.toByteArray();
DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length);
buffer.write(bytes);
return buffer;
});
Flux<Message> messages = decoder.decode(input, ResolvableType.fromType(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
ZeroDemandMessageSubscriber subscriber = new ZeroDemandMessageSubscriber();
messages.subscribe(subscriber);
subscriber.cancel();
}
use of cn.taketoday.protobuf.Msg in project today-infrastructure by TAKETODAY.
the class CancelWithoutDemandCodecTests method cancelWithProtobufEncoder.
// gh-22543
@Test
public void cancelWithProtobufEncoder() {
ProtobufEncoder encoder = new ProtobufEncoder();
Msg msg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
Flux<DataBuffer> flux = encoder.encode(Mono.just(msg), this.bufferFactory, ResolvableType.fromClass(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
// Assume sync execution (e.g. encoding with Flux.just)..
flux.subscribe(subscriber);
subscriber.cancel();
}
use of cn.taketoday.protobuf.Msg in project today-framework by TAKETODAY.
the class CancelWithoutDemandCodecTests method cancelWithProtobufDecoder.
// gh-22731
@Test
public void cancelWithProtobufDecoder() throws InterruptedException {
ProtobufDecoder decoder = new ProtobufDecoder();
Mono<DataBuffer> input = Mono.fromCallable(() -> {
Msg msg = Msg.newBuilder().setFoo("Foo").build();
byte[] bytes = msg.toByteArray();
DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length);
buffer.write(bytes);
return buffer;
});
Flux<Message> messages = decoder.decode(input, ResolvableType.fromType(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
ZeroDemandMessageSubscriber subscriber = new ZeroDemandMessageSubscriber();
messages.subscribe(subscriber);
subscriber.cancel();
}
use of cn.taketoday.protobuf.Msg in project today-framework by TAKETODAY.
the class CancelWithoutDemandCodecTests method cancelWithProtobufEncoder.
// gh-22543
@Test
public void cancelWithProtobufEncoder() {
ProtobufEncoder encoder = new ProtobufEncoder();
Msg msg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
Flux<DataBuffer> flux = encoder.encode(Mono.just(msg), this.bufferFactory, ResolvableType.fromClass(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
// Assume sync execution (e.g. encoding with Flux.just)..
flux.subscribe(subscriber);
subscriber.cancel();
}
Aggregations