*/
package org.opendaylight.lispflowmapping.lisp.serializer;
+import static org.opendaylight.yangtools.yang.common.UintConversions.fromJava;
+
import java.nio.ByteBuffer;
import org.apache.commons.lang3.BooleanUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
-public class LocatorRecordSerializer {
+public final class LocatorRecordSerializer {
private static final LocatorRecordSerializer INSTANCE = new LocatorRecordSerializer();
protected LocatorRecord deserialize(ByteBuffer buffer) {
LocatorRecordBuilder builder = new LocatorRecordBuilder();
- builder.setPriority((short) ByteUtil.getUnsignedByte(buffer));
- builder.setWeight((short) ByteUtil.getUnsignedByte(buffer));
- builder.setMulticastPriority((short) ByteUtil.getUnsignedByte(buffer));
- builder.setMulticastWeight((short) ByteUtil.getUnsignedByte(buffer));
+ builder.setPriority(fromJava((short) ByteUtil.getUnsignedByte(buffer)));
+ builder.setWeight(fromJava((short) ByteUtil.getUnsignedByte(buffer)));
+ builder.setMulticastPriority(fromJava((short) ByteUtil.getUnsignedByte(buffer)));
+ builder.setMulticastWeight(fromJava((short) ByteUtil.getUnsignedByte(buffer)));
byte flags = (byte) buffer.getShort();
builder.setLocalLocator(ByteUtil.extractBit(flags, Flags.LOCAL_LOCATOR));
builder.setRlocProbed(ByteUtil.extractBit(flags, Flags.RLOC_PROBED));
replyBuffer.put((byte) NumberUtil.asShort(record.getMulticastPriority()));
replyBuffer.put((byte) NumberUtil.asShort(record.getMulticastWeight()));
replyBuffer.position(replyBuffer.position() + Length.UNUSED_FLAGS);
- replyBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(record.isLocalLocator()), Flags.LOCAL_LOCATOR) | //
- ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRlocProbed()), Flags.RLOC_PROBED) | //
- ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRouted()), Flags.ROUTED)));
+ replyBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(record.isLocalLocator()), Flags.LOCAL_LOCATOR)
+ | ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRlocProbed()), Flags.RLOC_PROBED)
+ | ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRouted()), Flags.ROUTED)));
LispAddressSerializer.getInstance().serialize(replyBuffer, record.getRloc());
}