import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.Optional;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
import org.opendaylight.yangtools.yang.common.QName;
}
/**
- * Writes path-id value into the buffer when
- * the path-id is not null or does not equal to zero.
+ * Writes path-id value into the buffer when the path-id is not null or does not equal to zero.
*
* @param pathId The NLRI Path Identifier.
* @param buffer The ByteBuf where path-id value can be written.
*/
public static void writePathId(final PathId pathId, final ByteBuf buffer) {
if (pathId != null) {
- final Uint32 value = pathId.getValue();
- if (value.toJava() != 0) {
- ByteBufWriteUtil.writeUnsignedInt(value, buffer);
+ final int value = pathId.getValue().intValue();
+ if (value != 0) {
+ buffer.writeInt(value);
}
}
}
package org.opendaylight.protocol.bgp.parser.spi.extended.community;
import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommon;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
}
public static As4SpecificCommon parseCommon(final ByteBuf body) {
- return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(ByteBufUtils.readUint32(body)))
- .setLocalAdministrator(ByteBufUtils.readUint16(body)).build();
+ return new As4SpecificCommonBuilder()
+ .setAsNumber(new AsNumber(ByteBufUtils.readUint32(body)))
+ .setLocalAdministrator(ByteBufUtils.readUint16(body))
+ .build();
}
public static void serializeCommon(final As4SpecificCommon extComm, final ByteBuf body) {
- body.writeInt(extComm.getAsNumber().getValue().intValue());
- ByteBufWriteUtil.writeUnsignedShort(extComm.getLocalAdministrator(), body);
+ ByteBufUtils.write(body, extComm.getAsNumber().getValue());
+ ByteBufUtils.writeOrZero(body, extComm.getLocalAdministrator());
}
}
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityRegistry;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
import org.opendaylight.yangtools.concepts.Registration;
if (serializer == null) {
return;
}
- ByteBufWriteUtil.writeUnsignedByte(Shorts.checkedCast(serializer.getType(extendedCommunity.isTransitive())),
- byteAggregator);
- ByteBufWriteUtil.writeUnsignedByte(Shorts.checkedCast(serializer.getSubType()), byteAggregator);
+ byteAggregator.writeByte(Shorts.checkedCast(serializer.getType(extendedCommunity.isTransitive())));
+ byteAggregator.writeByte(Shorts.checkedCast(serializer.getSubType()));
serializer.serializeExtendedCommunity(extendedCommunity.getExtendedCommunity(), byteAggregator);
}
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint32;
@Test
public void testReadPathId() {
- final long expected = 10L;
- ByteBufWriteUtil.writeUnsignedInt(expected, this.buffer);
+ this.buffer.writeInt(10);
final PathId pathId = PathIdUtil.readPathId(this.buffer);
- Assert.assertEquals(expected, pathId.getValue().longValue());
+ Assert.assertEquals(Uint32.TEN, pathId.getValue());
}
@Test