本文整理了Java中io.rsocket.Frame.from()
方法的一些代码示例,展示了Frame.from()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Frame.from()
方法的具体详情如下:
包路径:io.rsocket.Frame
类名称:Frame
方法名:from
[英]Acquire a free Frame backed by given ByteBuf
[中]获得一个由给定ByteBuf支持的自由帧
代码示例来源:origin: rsocket/rsocket-java
/** Returns a new {@link Frame} which contains the specified {@code content}. */
@Override
public Frame replace(ByteBuf content) {
return from(content);
}
代码示例来源:origin: rsocket/rsocket-java
@Override
public Flux<Frame> receive() {
return connection.inbound().receive().map(buf -> Frame.from(buf.retain()));
}
代码示例来源:origin: rsocket/rsocket-java
/**
* Returns an abstraction leaking frame with the stream id and frame. This adds the frame length
* and stream id header to the frame.
*
* @param byteBufAllocator the {@link ByteBufAllocator} to use
* @param streamId the stream id
* @param frame the frame
* @return an abstraction leaking frame with the stream id and frame
* @throws NullPointerException if {@code byteBufAllocator} or {@code frame} is {@code null}
*/
public static Frame toAbstractionLeakingFrame(
ByteBufAllocator byteBufAllocator, int streamId, io.rsocket.framing.Frame frame) {
Objects.requireNonNull(byteBufAllocator, "byteBufAllocator must not be null");
Objects.requireNonNull(frame, "frame must not be null");
StreamIdFrame streamIdFrame = null;
FrameLengthFrame frameLengthFrame = null;
try {
streamIdFrame = createStreamIdFrame(byteBufAllocator, streamId, frame);
frameLengthFrame = createFrameLengthFrame(byteBufAllocator, streamIdFrame);
return frameLengthFrame.mapFrame(byteBuf -> Frame.from(byteBuf.retain()));
} finally {
disposeQuietly(frame, streamIdFrame, frameLengthFrame);
}
}
}
代码示例来源:origin: rsocket/rsocket-java
@Override
public Flux<Frame> receive() {
return connection
.inbound()
.receive()
.map(
buf -> {
CompositeByteBuf composite = connection.channel().alloc().compositeBuffer();
ByteBuf length = wrappedBuffer(new byte[FRAME_LENGTH_SIZE]);
FrameHeaderFlyweight.encodeLength(length, 0, buf.readableBytes());
composite.addComponents(true, length, buf.retain());
return Frame.from(composite);
});
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns CanceledException")
@Test
void fromCanceledException() {
ByteBuf byteBuf = createErrorFrame(CANCELED, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(CanceledException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns InvalidException")
@Test
void fromInvalidException() {
ByteBuf byteBuf = createErrorFrame(INVALID, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(InvalidException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns UnsupportedSetupException")
@Test
void fromUnsupportedSetupException() {
ByteBuf byteBuf = createErrorFrame(UNSUPPORTED_SETUP, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(UnsupportedSetupException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns ConnectionCloseException")
@Test
void fromConnectionCloseException() {
ByteBuf byteBuf = createErrorFrame(CONNECTION_CLOSE, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(ConnectionCloseException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns RejectedException")
@Test
void fromRejectedException() {
ByteBuf byteBuf = createErrorFrame(REJECTED, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(RejectedException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns IllegalArgumentException if error frame has illegal error code")
@Test
void fromIllegalErrorFrame() {
ByteBuf byteBuf = createErrorFrame(0x00000000, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(IllegalArgumentException.class)
.withFailMessage("Invalid Error frame: %d, '%s'", 0, "test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns ApplicationErrorException")
@Test
void fromApplicationException() {
ByteBuf byteBuf = createErrorFrame(APPLICATION_ERROR, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(ApplicationErrorException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns ConnectionErrorException")
@Test
void fromConnectionErrorException() {
ByteBuf byteBuf = createErrorFrame(CONNECTION_ERROR, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(ConnectionErrorException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns InvalidSetupException")
@Test
void fromInvalidSetupException() {
ByteBuf byteBuf = createErrorFrame(INVALID_SETUP, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(InvalidSetupException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns RejectedResumeException")
@Test
void fromRejectedResumeException() {
ByteBuf byteBuf = createErrorFrame(REJECTED_RESUME, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(RejectedResumeException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@DisplayName("from returns RejectedSetupException")
@Test
void fromRejectedSetupException() {
ByteBuf byteBuf = createErrorFrame(REJECTED_SETUP, "test-message");
assertThat(Exceptions.from(Frame.from(byteBuf)))
.isInstanceOf(RejectedSetupException.class)
.withFailMessage("test-message");
}
代码示例来源:origin: rsocket/rsocket-java
@Test
public void testEncodingWithEmptyMetadata() {
int encoded =
RequestFrameFlyweight.encode(
byteBuf,
1,
FrameHeaderFlyweight.FLAGS_M,
FrameType.REQUEST_STREAM,
1,
Unpooled.copiedBuffer("", StandardCharsets.UTF_8),
Unpooled.copiedBuffer("d", StandardCharsets.UTF_8));
assertEquals("00000e0000000119000000000100000064", ByteBufUtil.hexDump(byteBuf, 0, encoded));
Payload payload =
DefaultPayload.create(Frame.from(stringToBuf("00000e0000000119000000000100000064")));
assertEquals("", StandardCharsets.UTF_8.decode(payload.getMetadata()).toString());
}
代码示例来源:origin: rsocket/rsocket-java
@Test
public void testEncoding() {
int encoded =
RequestFrameFlyweight.encode(
byteBuf,
1,
FrameHeaderFlyweight.FLAGS_M,
FrameType.REQUEST_STREAM,
1,
Unpooled.copiedBuffer("md", StandardCharsets.UTF_8),
Unpooled.copiedBuffer("d", StandardCharsets.UTF_8));
assertEquals(
"000010000000011900000000010000026d6464", ByteBufUtil.hexDump(byteBuf, 0, encoded));
Payload payload =
DefaultPayload.create(Frame.from(stringToBuf("000010000000011900000000010000026d6464")));
assertEquals("md", StandardCharsets.UTF_8.decode(payload.getMetadata()).toString());
}
代码示例来源:origin: io.rsocket/rsocket-core
/** Returns a new {@link Frame} which contains the specified {@code content}. */
@Override
public Frame replace(ByteBuf content) {
return from(content);
}
代码示例来源:origin: rsocket/rsocket-java
@Test
public void testEncodingWithNullMetadata() {
int encoded =
RequestFrameFlyweight.encode(
byteBuf,
1,
0,
FrameType.REQUEST_STREAM,
1,
null,
Unpooled.copiedBuffer("d", StandardCharsets.UTF_8));
assertEquals("00000b0000000118000000000164", ByteBufUtil.hexDump(byteBuf, 0, encoded));
Payload payload =
DefaultPayload.create(Frame.from(stringToBuf("00000b0000000118000000000164")));
assertFalse(payload.hasMetadata());
}
代码示例来源:origin: io.rsocket/rsocket-transport-netty
@Override
public Flux<Frame> receive() {
return connection.inbound().receive().map(buf -> Frame.from(buf.retain()));
}
内容来源于网络,如有侵权,请联系作者删除!