* 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 com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.BMP_VERSION;
import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.COMMON_HEADER_LENGTH;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public final void serializeMessage(final Notification message, final ByteBuf buffer) {
- Preconditions.checkArgument(message != null, "BMP message is mandatory.");
+ checkArgument(message != null, "BMP message is mandatory.");
final ByteBuf bodyBuffer = Unpooled.buffer();
serializeMessageBody(message, bodyBuffer);
formatMessage(bodyBuffer, buffer);
@Override
public final Notification parseMessage(final ByteBuf bytes) throws BmpDeserializationException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable());
+ checkArgument(bytes != null && bytes.isReadable());
final Notification parsedMessage = parseMessageBody(bytes);
LOG.trace("Parsed BMP message: {}", parsedMessage);
return parsedMessage;
private void formatMessage(final ByteBuf body, final ByteBuf output) {
output.writeByte(BMP_VERSION);
- ByteBufWriteUtil.writeInt(body.writerIndex() + COMMON_HEADER_LENGTH, output);
+ output.writeInt(body.writerIndex() + COMMON_HEADER_LENGTH);
output.writeByte(getBmpMessageType());
output.writeBytes(body);
}
// Hidden on purpose
}
- /**
- * Writes 32-bit integer <code>value</code> if not null, otherwise writes
- * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
- * increased by 4.
- *
- * @param value
- * Integer value to be written to the output.
- * @param output
- * ByteBuf, where value or zeros are written.
- */
- public static void writeInt(final Integer value, final ByteBuf output) {
- output.writeInt(value != null ? value : 0);
- }
-
/**
* Writes 24-bit integer <code>value</code> if not null, otherwise writes
* zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
import static org.junit.Assert.assertArrayEquals;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeInt;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
public class ByteBufWriteUtilTest {
private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
- @Test
- public void testWriteIntegerValue() {
- final byte[] result = { 0, 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(Integer.BYTES);
- writeInt(5, output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- writeInt(null, output);
- assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
- }
-
@Test
public void testWriteMediumValue() {
final byte[] result = { 0, 0, 5 };