List of usage examples for io.netty.buffer ByteBufAllocator DEFAULT
ByteBufAllocator DEFAULT
To view the source code for io.netty.buffer ByteBufAllocator DEFAULT.
Click Source Link
From source file:com.uber.tchannel.codecs.ErrorCodecTest.java
License:Open Source License
@Test public void testEncodeDecode() throws Exception { ErrorFrame errorFrame = new ErrorFrame(42, ErrorType.FatalProtocolError, new Trace(0, 0, 0, (byte) 0), "I'm sorry Dave, I can't do that."); TFrame tFrame = MessageCodec.encode(ByteBufAllocator.DEFAULT, errorFrame); ErrorFrame newErrorFrame = (ErrorFrame) MessageCodec.decode(CodecTestUtil.encodeDecode(tFrame)); assertEquals(errorFrame.getId(), newErrorFrame.getId()); assertEquals(errorFrame.getMessage(), newErrorFrame.getMessage()); tFrame.release();//ww w.j a va2s.co m }
From source file:com.uber.tchannel.codecs.InitRequestFrameCodecTest.java
License:Open Source License
@Test public void shouldEncodeAndDecodeInitRequest() throws Exception { InitRequestFrame initReq = new InitRequestFrame(42, InitRequestFrame.DEFAULT_VERSION, new HashMap<String, String>() { {//from w ww.ja v a 2s . c o m put(InitFrame.HOST_PORT_KEY, "0.0.0.0:0"); put(InitFrame.PROCESS_NAME_KEY, "test-process"); } }); TFrame tFrame = CodecTestUtil.encodeDecode(MessageCodec.encode(ByteBufAllocator.DEFAULT, initReq)); InitRequestFrame newInitReq = (InitRequestFrame) MessageCodec.decode(tFrame); tFrame.release(); assertEquals(initReq.getType(), newInitReq.getType()); assertEquals(newInitReq.getId(), newInitReq.getId()); assertEquals(newInitReq.getVersion(), newInitReq.getVersion()); assertEquals(newInitReq.getHostPort(), newInitReq.getHostPort()); assertEquals(newInitReq.getProcessName(), initReq.getProcessName()); }
From source file:com.uber.tchannel.codecs.InitResponseFrameCodecTest.java
License:Open Source License
@Test public void shouldEncodeAndDecodeInitResponse() throws Exception { InitResponseFrame initResponseFrame = new InitResponseFrame(42, InitRequestFrame.DEFAULT_VERSION, new HashMap<String, String>() { {//from www . j a v a2 s . com put(InitFrame.HOST_PORT_KEY, "0.0.0.0:0"); put(InitFrame.PROCESS_NAME_KEY, "test-process"); } }); TFrame tFrame = CodecTestUtil .encodeDecode(MessageCodec.encode(ByteBufAllocator.DEFAULT, initResponseFrame)); InitResponseFrame newInitResponseFrame = (InitResponseFrame) MessageCodec.decode(tFrame); tFrame.release(); assertEquals(newInitResponseFrame.getType(), initResponseFrame.getType()); assertEquals(newInitResponseFrame.getId(), initResponseFrame.getId()); assertEquals(newInitResponseFrame.getVersion(), initResponseFrame.getVersion()); assertEquals(newInitResponseFrame.getHostPort(), initResponseFrame.getHostPort()); assertEquals(newInitResponseFrame.getProcessName(), initResponseFrame.getProcessName()); }
From source file:com.uber.tchannel.codecs.PingRequestFrameCodecTest.java
License:Open Source License
@Test public void testEncodeDecodePingRequest() throws Exception { PingRequestFrame pingRequestFrame = new PingRequestFrame(42); TFrame tFrame = MessageCodec.encode(ByteBufAllocator.DEFAULT, pingRequestFrame); PingRequestFrame newPingRequestFrame = (PingRequestFrame) MessageCodec .decode(CodecTestUtil.encodeDecode(tFrame)); assertEquals(newPingRequestFrame.getId(), pingRequestFrame.getId()); tFrame.release();/*from w w w .jav a 2 s .co m*/ }
From source file:com.uber.tchannel.codecs.PingResponseFrameCodecTest.java
License:Open Source License
@Test public void testEncodeDecodePingResponse() throws Exception { PingResponseFrame pingResponseFrame = new PingResponseFrame(99); PingResponseFrame newPingResponseFrame = (PingResponseFrame) MessageCodec.decode( CodecTestUtil.encodeDecode(MessageCodec.encode(ByteBufAllocator.DEFAULT, pingResponseFrame))); assertEquals(newPingResponseFrame.getId(), pingResponseFrame.getId()); }
From source file:com.uber.tchannel.messages.ThriftSerializer.java
License:Open Source License
@Override public ByteBuf encodeHeaders(Map<String, String> applicationHeaders) { ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(); CodecUtils.encodeHeaders(applicationHeaders, buf); return buf;//from www . j a v a 2 s . c o m }
From source file:com.yahoo.pulsar.common.compression.Crc32cChecksumTest.java
License:Apache License
@Test public void testCrc32cDirectMemoryHardware() { if (HARDWARE_CRC32C_HASH == null) { return;//from ww w. j a v a 2s. c om } ByteBuf payload = ByteBufAllocator.DEFAULT.directBuffer(inputBytes.length); payload.writeBytes(inputBytes); // read directly from memory address int checksum = HARDWARE_CRC32C_HASH.calculate(payload.memoryAddress(), payload.readableBytes()); payload.release(); assertEquals(checksum, expectedChecksum); }
From source file:com.yahoo.pulsar.common.compression.Crc32cChecksumTest.java
License:Apache License
@Test public void testCrc32cIncrementalUsingProvider() { final byte[] data = "data".getBytes(); final byte[] doubleData = "datadata".getBytes(); ByteBuf payload = Unpooled.wrappedBuffer(data); ByteBuf doublePayload = Unpooled.wrappedBuffer(doubleData); int expectedChecksum = Crc32cChecksum.computeChecksum(doublePayload); // (1) heap-memory int checksum = Crc32cChecksum.computeChecksum(payload); int incrementalChecksum = Crc32cChecksum.resumeChecksum(checksum, payload); assertEquals(expectedChecksum, incrementalChecksum); payload.release();/*from w w w. ja v a2s . c o m*/ doublePayload.release(); // (2) direct-memory payload = ByteBufAllocator.DEFAULT.directBuffer(data.length); payload.writeBytes(data); checksum = Crc32cChecksum.computeChecksum(payload); incrementalChecksum = Crc32cChecksum.resumeChecksum(checksum, payload); assertEquals(expectedChecksum, incrementalChecksum); payload.release(); }
From source file:consulo.google.go.run.dlv.api.SimpleInOutMessage.java
License:Apache License
@Override public ByteBuf getBuffer() { ByteBuf buffer = ByteBufAllocator.DEFAULT.heapBuffer(); String json = DlvRequest.ourGson.toJson(myObject); buffer.writeCharSequence(json, StandardCharsets.UTF_8); return buffer; }
From source file:discord4j.rest.http.JacksonWriterStrategy.java
License:Open Source License
@Override public Mono<HttpClient.ResponseReceiver<?>> write(HttpClient.RequestSender sender, @Nullable Object body) { if (body == null) { return Mono.error(new RuntimeException("Missing body")); }/*from w w w . ja va 2s . c om*/ Mono<String> source = Mono.fromCallable(() -> mapToString(body)).doOnNext(json -> { if (log.isTraceEnabled()) { log.trace("{}", json); } }); return Mono.fromCallable(() -> sender .send(ByteBufFlux.fromString(source, StandardCharsets.UTF_8, ByteBufAllocator.DEFAULT))); }