* 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.bgp.evpn.impl.esi.types;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractSystmeMac;
import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractUint24LD;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
@Override
public ByteBuf serializeBody(final Esi esi, final ByteBuf body) {
- Preconditions.checkArgument(esi instanceof MacAutoGeneratedCase,
- "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass());
+ checkArgument(esi instanceof MacAutoGeneratedCase,
+ "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass());
final MacAutoGenerated macAuto = ((MacAutoGeneratedCase) esi).getMacAutoGenerated();
body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(macAuto.getSystemMacAddress()));
- ByteBufWriteUtil.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue(), body);
+ body.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue());
return body;
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeMedium;
import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
object.getClass());
final Lsp specObj = (Lsp) object;
final ByteBuf body = Unpooled.buffer();
- checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
- writeMedium(specObj.getPlspId().getValue().intValue() << FOUR_BITS_SHIFT, body);
+ final PlspId plspId = specObj.getPlspId();
+ checkArgument(plspId != null, "PLSP-ID not present");
+ body.writeMedium(plspId.getValue().intValue() << FOUR_BITS_SHIFT);
final BitArray flags = serializeFlags(specObj);
byte op = 0;
if (specObj.getOperational() != null) {
// Hidden on purpose
}
- /**
- * Writes 24-bit integer <code>value</code> if not null, otherwise writes
- * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
- * increased by 3.
- *
- * @param value
- * Medium value to be written to the output.
- * @param output
- * ByteBuf, where value or zeros are written.
- */
- public static void writeMedium(final Integer value, final ByteBuf output) {
- output.writeMedium(value != null ? value : 0);
- }
-
/**
* Writes IPv4 address if not null, otherwise writes zeros to the
* <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeMedium;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
public class ByteBufWriteUtilTest {
private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
- @Test
- public void testWriteMediumValue() {
- final byte[] result = { 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(3);
- writeMedium(5, output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- final byte[] resultZero = { 0, 0, 0 };
- writeMedium(null, output);
- assertArrayEquals(resultZero, output.array());
- }
-
@Test
public void testWriteIpv4Address() {
final byte[] result = { 127, 0, 0, 1 };