*/
package org.opendaylight.protocol.pcep.impl.tlv;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
*/
public class OrderTlvParser implements TlvParser, TlvSerializer {
- public static final int TYPE = 5;
-
- private static final int ORDR_DEL_LENGTH = 4;
-
- private static final int ORDR_SETUP_LENGTH = 4;
-
- @Override
- public Order parseTlv(final byte[] buffer) throws PCEPDeserializerException {
- return new OrderBuilder().setDelete(Long.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, ORDR_DEL_LENGTH)))).setSetup(
- ByteArray.bytesToLong(ByteArray.subByte(buffer, ORDR_DEL_LENGTH, ORDR_SETUP_LENGTH))).build();
- }
-
- @Override
- public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null) {
- throw new IllegalArgumentException("OrderTlv is mandatory.");
- }
- final Order otlv = (Order) tlv;
- final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
- int offset = 0;
- ByteArray.copyWhole(ByteArray.longToBytes(otlv.getDelete(), ORDR_DEL_LENGTH), bytes, offset);
- offset += ORDR_DEL_LENGTH;
- ByteArray.copyWhole(ByteArray.longToBytes(otlv.getSetup(), ORDR_SETUP_LENGTH), bytes, offset);
- return TlvUtil.formatTlv(TYPE, bytes);
- }
+ public static final int TYPE = 5;
+
+ private static final int ORDR_DEL_LENGTH = 4;
+
+ private static final int ORDR_SETUP_LENGTH = 4;
+
+ @Override
+ public Order parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+ if (buffer == null) {
+ return null;
+ }
+ return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build();
+ }
+
+ @Override
+ public byte[] serializeTlv(final Tlv tlv) {
+ if (tlv == null) {
+ throw new IllegalArgumentException("OrderTlv is mandatory.");
+ }
+ final Order otlv = (Order) tlv;
+ final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
+ int offset = 0;
+ ByteArray.copyWhole(ByteArray.longToBytes(otlv.getDelete(), ORDR_DEL_LENGTH), bytes, offset);
+ offset += ORDR_DEL_LENGTH;
+ ByteArray.copyWhole(ByteArray.longToBytes(otlv.getSetup(), ORDR_SETUP_LENGTH), bytes, offset);
+ return TlvUtil.formatTlv(TYPE, bytes);
+ }
}