All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rsocket.frame.RequestNFrameFlyweight Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
package io.rsocket.frame;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

public class RequestNFrameFlyweight {
  private RequestNFrameFlyweight() {}

  public static ByteBuf encode(
      final ByteBufAllocator allocator, final int streamId, long requestN) {

    if (requestN < 1) {
      throw new IllegalArgumentException("request n is less than 1");
    }

    int reqN = requestN > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) requestN;

    ByteBuf header = FrameHeaderFlyweight.encode(allocator, streamId, FrameType.REQUEST_N, 0);
    return header.writeInt(reqN);
  }

  public static long requestN(ByteBuf byteBuf) {
    FrameHeaderFlyweight.ensureFrameType(FrameType.REQUEST_N, byteBuf);
    byteBuf.markReaderIndex();
    byteBuf.skipBytes(FrameHeaderFlyweight.size());
    int i = byteBuf.readInt();
    byteBuf.resetReaderIndex();
    return i == Integer.MAX_VALUE ? Long.MAX_VALUE : i;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy