}
private static byte[] serializeAs4BytesCapability(final As4BytesCapability as4Capability) {
- final ByteBuf buffer = Unpooled.buffer(1 /*CODE*/ + 1 /*LENGTH*/
- + Integer.SIZE / Byte.SIZE /*4 byte value*/);
+ final ByteBuf buffer = Unpooled.buffer(1 /*CODE*/ + 1 /*LENGTH*/ + Integer.BYTES /*4 byte value*/);
final As4CapabilityHandler serializer = new As4CapabilityHandler();
serializer.serializeCapability(new CParametersBuilder().setAs4BytesCapability(as4Capability).build(), buffer);
return buffer.array();
public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
public static final int TYPE = 20;
- private static final int CONTENT_LENGTH = Integer.SIZE / Byte.SIZE;
-
@Override
public LspErrorCode parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
- final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+ final ByteBuf body = Unpooled.buffer(Integer.BYTES);
ByteBufUtils.writeOrZero(body, ((LspErrorCode) tlv).getErrorCode());
TlvUtil.formatTlv(TYPE, body, buffer);
}
* @return int
*/
public static int bytesToInt(final byte[] bytes) {
- checkArgument(bytes.length <= Integer.SIZE / Byte.SIZE,
- "Cannot convert bytes to integer. Byte array too big.");
+ checkArgument(bytes.length <= Integer.BYTES, "Cannot convert bytes to integer. Byte array too big.");
final byte[] res;
- if (bytes.length != Integer.SIZE / Byte.SIZE) {
- res = new byte[Integer.SIZE / Byte.SIZE];
- System.arraycopy(bytes, 0, res, Integer.SIZE / Byte.SIZE - bytes.length, bytes.length);
+ if (bytes.length != Integer.BYTES) {
+ res = new byte[Integer.BYTES];
+ System.arraycopy(bytes, 0, res, Integer.BYTES - bytes.length, bytes.length);
} else {
res = bytes;
}
* @return long
*/
public static long bytesToLong(final byte[] bytes) {
- checkArgument(bytes.length <= Long.SIZE / Byte.SIZE,
- "Cannot convert bytes to long.Byte array too big.");
+ checkArgument(bytes.length <= Long.BYTES, "Cannot convert bytes to long.Byte array too big.");
final byte[] res;
- if (bytes.length != Long.SIZE / Byte.SIZE) {
- res = new byte[Long.SIZE / Byte.SIZE];
- System.arraycopy(bytes, 0, res, Long.SIZE / Byte.SIZE - bytes.length, bytes.length);
+ if (bytes.length != Long.BYTES) {
+ res = new byte[Long.BYTES];
+ System.arraycopy(bytes, 0, res, Long.BYTES - bytes.length, bytes.length);
} else {
res = bytes;
}