/** * Returns a test instance of {@link FrameLengthFrame}. * * @return a test instance of {@link FrameLengthFrame} */ public static FrameLengthFrame createTestFrameLengthFrame() { return createFrameLengthFrame(DEFAULT, createTestStreamIdFrame()); }
public static FrameLengthFrame createTestFrameLengthFrame() { return createFrameLengthFrame(DEFAULT, createTestStreamIdFrame()); }
/** * 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); } } }
/** * Returns a {@link Tuple2} of the stream id, and the frame. This strips the frame length and * stream id header from the abstraction leaking frame. * * @param abstractionLeakingFrame the abstraction leaking frame * @return a {@link Tuple2} of the stream id, and the frame * @throws NullPointerException if {@code abstractionLeakingFrame} is {@code null} */ public static Tuple2<Integer, io.rsocket.framing.Frame> fromAbstractionLeakingFrame( Frame abstractionLeakingFrame) { Objects.requireNonNull(abstractionLeakingFrame, "abstractionLeakingFrame must not be null"); FrameLengthFrame frameLengthFrame = null; StreamIdFrame streamIdFrame = null; try { frameLengthFrame = createFrameLengthFrame(abstractionLeakingFrame.content()); streamIdFrame = frameLengthFrame.mapFrameWithoutFrameLength(StreamIdFrame::createStreamIdFrame); io.rsocket.framing.Frame frame = streamIdFrame.mapFrameWithoutStreamId(FrameFactory::createFrame); return Tuples.of(streamIdFrame.getStreamId(), frame); } finally { disposeQuietly(frameLengthFrame, streamIdFrame); release(abstractionLeakingFrame); } }
@DisplayName("createFrameLengthFrame throws NullPointerException with null byteBufAllocator") @Test void createFrameLengthFrameNullByteBufAllocator() { assertThatNullPointerException() .isThrownBy(() -> createFrameLengthFrame(null, createTestCancelFrame())) .withMessage("byteBufAllocator must not be null"); }
/** * 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); } } }
/** * Returns a {@link Tuple2} of the stream id, and the frame. This strips the frame length and * stream id header from the abstraction leaking frame. * * @param abstractionLeakingFrame the abstraction leaking frame * @return a {@link Tuple2} of the stream id, and the frame * @throws NullPointerException if {@code abstractionLeakingFrame} is {@code null} */ public static Tuple2<Integer, io.rsocket.framing.Frame> fromAbstractionLeakingFrame( Frame abstractionLeakingFrame) { Objects.requireNonNull(abstractionLeakingFrame, "abstractionLeakingFrame must not be null"); FrameLengthFrame frameLengthFrame = null; StreamIdFrame streamIdFrame = null; try { frameLengthFrame = createFrameLengthFrame(abstractionLeakingFrame.content()); streamIdFrame = frameLengthFrame.mapFrameWithoutFrameLength(StreamIdFrame::createStreamIdFrame); io.rsocket.framing.Frame frame = streamIdFrame.mapFrameWithoutStreamId(FrameFactory::createFrame); return Tuples.of(streamIdFrame.getStreamId(), frame); } finally { disposeQuietly(frameLengthFrame, streamIdFrame); release(abstractionLeakingFrame); } }