* @return Decoded PathId.
*/
public static PathId readPathId(final ByteBuf buffer) {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(ByteBufWriteUtil.INT_BYTES_LENGTH));
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(Integer.BYTES));
return new PathId(ByteBufUtils.readUint32(buffer));
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bmp.parser.message;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import com.google.common.base.Preconditions;
final StatsReportsMessageBuilder statReport = new StatsReportsMessageBuilder()
.setPeerHeader(parsePerPeerHeader(bytes));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
- bytes.skipBytes(INT_BYTES_LENGTH);
+ bytes.skipBytes(Integer.BYTES);
parseTlvs(tlvsBuilder, bytes);
return statReport.setTlvs(tlvsBuilder.build()).build();
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bmp.spi.parser;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.LONG_BYTES_LENGTH;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.SHORT_BYTES_LENGTH;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
}
public static void formatTlvShort16(final int type, final int value, final ByteBuf out) {
- formatTlvHeader(type, SHORT_BYTES_LENGTH, out);
+ formatTlvHeader(type, Short.BYTES, out);
ByteBufWriteUtil.writeUnsignedShort(value, out);
}
public static void formatTlvCounter32(final int type, final Counter32 value, final ByteBuf out) {
if (value != null && value.getValue() != null) {
- formatTlvHeader(type, INT_BYTES_LENGTH, out);
+ formatTlvHeader(type, Integer.BYTES, out);
ByteBufWriteUtil.writeUnsignedInt(value.getValue(), out);
}
}
public static void formatTlvGauge64(final int type, final Gauge64 value, final ByteBuf out) {
if (value != null && value.getValue() != null) {
- formatTlvHeader(type, LONG_BYTES_LENGTH, out);
+ formatTlvHeader(type, Long.BYTES, out);
ByteBufWriteUtil.writeUnsignedLong(value.getValue(), out);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.parser.object;
import com.google.common.base.Preconditions;
private static final int TYPE = 1;
private static final int RESERVED = 1;
private static final int FLAGS = RESERVED;
- private static final int BODY_SIZE = RESERVED + FLAGS + ByteBufWriteUtil.SHORT_BYTES_LENGTH;
+ private static final int BODY_SIZE = RESERVED + FLAGS + Short.BYTES;
public PCEPOverloadObjectParser() {
super(CLASS, TYPE);
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
private static final int RESERVED = 2;
private static final int FLAGS = 16;
private static final int COUNT_FIELDS = 5;
- private static final int BODY_SIZE = RESERVED + FLAGS + COUNT_FIELDS * INT_BYTES_LENGTH;
+ private static final int BODY_SIZE = RESERVED + FLAGS + COUNT_FIELDS * Integer.BYTES;
private static final int E_FLAG_POSITION = 15;
public PCEPProcTimeObjectParser() {
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.rsvp.parser.impl.te;
import com.google.common.base.Preconditions;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.admin.status.object.AdminStatusObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.admin.status.object.AdminStatusObjectBuilder;
final AdminStatusObjectBuilder adm = new AdminStatusObjectBuilder();
final BitArray reflect = BitArray.valueOf(byteBuf, FLAGS_SIZE);
adm.setReflect(reflect.get(REFLECT));
- byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ byteBuf.skipBytes(Short.BYTES);
final BitArray flags = BitArray.valueOf(byteBuf, FLAGS_SIZE);
adm.setTesting(flags.get(TESTING));
adm.setAdministrativelyDown(flags.get(DOWN));
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.rsvp.parser.impl.te;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufUtils;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ServiceNumber;
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
final FlowSpecObjectBuilder builder = new FlowSpecObjectBuilder();
//skip version number, reserved, overall length
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
builder.setServiceHeader(ServiceNumber.forValue(byteBuf.readUnsignedByte()));
//skip reserved
- byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ byteBuf.skipBytes(Byte.BYTES);
//skip Length of controlled-load data
- byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ byteBuf.skipBytes(Short.BYTES);
//skip parameter ID 127 and 127 flags
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
final TspecObjectBuilder tBuilder = new TspecObjectBuilder()
.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
builder.setTspecObject(tBuilder.build());
if (builder.getServiceHeader().getIntValue() == 2) {
//skip parameter ID 130, flags, lenght
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
builder.setRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
builder.setSlackTerm(ByteBufUtils.readUint32(byteBuf));
}
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufUtils;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
.setHopLimit(ByteBufUtils.readUint8(byteBuf));
//skip reserved
- byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ byteBuf.skipBytes(Byte.BYTES);
final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufUtils;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObject;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ byteBuf.skipBytes(Short.BYTES);
final BitArray flags = BitArray.valueOf(byteBuf.readByte());
return new MetricObjectBuilder()
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LinkFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspFlag;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.protection.subobject.ProtectionSubobject;
final int lspFlags = byteBuf.readByte();
sub.setLspFlag(LspFlag.forValue(lspFlags)).build();
//Skip Reserved
- byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ byteBuf.skipBytes(Byte.BYTES);
final int linkFlags = byteBuf.readByte();
sub.setLinkFlags(LinkFlags.forValue(linkFlags));
final int segFlags = byteBuf.readByte();
sub.setSegFlag(LspFlag.forValue(segFlags));
- byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ byteBuf.skipBytes(Short.BYTES);
return sub.build();
}
final ProtectionSubobjectBuilder sub = new ProtectionSubobjectBuilder();
sub.setSecondary(bitArray.get(SECONDARY));
//Skip Reserved
- byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ byteBuf.skipBytes(Short.BYTES);
final int linkFlags = byteBuf.readByte();
sub.setLinkFlags(LinkFlags.forValue(linkFlags));
return sub.build();
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufUtils;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
//skip version number, reserved, Overall length
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
//skip Service header, reserved, Length of service
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
//skip Parameter ID, Parameter 127 flags, Parameter 127 length
- byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ byteBuf.skipBytes(Integer.BYTES);
return new TspecObjectBuilder()
.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
output.writeShort(0);
output.writeShort(OVERALL_LENGTH);
// FIXME: this is weird. Use explicit 1?
- output.writeByte(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ output.writeByte(Byte.BYTES);
output.writeByte(0);
output.writeShort(SERVICE_LENGTH);
output.writeByte(TOKEN_BUCKET_TSPEC);
* Utility class for ByteBuf's write methods.
*/
public final class ByteBufWriteUtil {
-
- public static final int SHORT_BYTES_LENGTH = Short.SIZE / Byte.SIZE;
-
- public static final int INT_BYTES_LENGTH = Integer.SIZE / Byte.SIZE;
-
- public static final int LONG_BYTES_LENGTH = Long.SIZE / Byte.SIZE;
-
- public static final int FLOAT32_BYTES_LENGTH = INT_BYTES_LENGTH;
-
- public static final int ONE_BYTE_LENGTH = 1;
-
public static final int IPV4_PREFIX_BYTE_LENGTH = Ipv4Util.IP4_LENGTH + 1;
-
public static final int IPV6_PREFIX_BYTE_LENGTH = Ipv6Util.IPV6_LENGTH + 1;
private ByteBufWriteUtil() {
@Test
public void testWriteIntegerValue() {
final byte[] result = { 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Integer.BYTES);
writeInt(5, output);
assertArrayEquals(result, output.array());
@Test
public void testWriteShortValue() {
final byte[] result = { 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Short.BYTES);
writeShort((short) 5, output);
assertArrayEquals(result, output.array());
@Test
public void testWriteLongValue() {
final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.LONG_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Long.BYTES);
writeLong((long) 5, output);
assertArrayEquals(result, output.array());
@Test
public void testWriteBooleanValue() {
final byte[] result = { 1 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Byte.BYTES);
writeBoolean(true, output);
assertArrayEquals(result, output.array());
@Test
public void testWriteUnsignedByteValue() {
final byte[] result = { 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Byte.BYTES);
writeUnsignedByte(Uint8.valueOf(5), output);
assertArrayEquals(result, output.array());
@Test
public void testWriteUnsignedShortValue() {
final byte[] result = { 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Short.BYTES);
writeUnsignedShort(Uint16.valueOf(5), output);
assertArrayEquals(result, output.array());
@Test
public void testWriteUnsignedIntValue() {
final byte[] result = { 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Integer.BYTES);
ByteBufWriteUtil.writeUnsignedInt(Uint32.valueOf(5), output);
assertArrayEquals(result, output.array());
@Test
public void testWriteUnsignedLongValue() {
final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.LONG_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Long.BYTES);
writeUnsignedLong(Uint64.valueOf(5), output);
assertArrayEquals(result, output.array());
@Test
public void testWriteFloat32() {
final byte[] result = { 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.FLOAT32_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(Float.BYTES);
writeFloat32(new Float32(result), output);
assertArrayEquals(result, output.array());