+ final int type = buffer.readUnsignedShort();
+ final PathBindingTlvCodec codec = BT_PARSERS.get(type);
+ if (codec == null) {
+ throw new PCEPDeserializerException("Unsupported Path Binding Type: " + type);
+ }
+ final PathBindingBuilder builder = new PathBindingBuilder();
+ backwardsParser(type, buffer, builder);
+ return builder.setBindingTypeValue(codec.deserialize(buffer)).build();
+ }
+
+ private void backwardsParser(final int type, final ByteBuf buffer, final PathBindingBuilder builder) {
+ builder.setBindingType((short) type);
+ final byte[] value = new byte[buffer.readableBytes()];
+ //codec will do the reading from buffer
+ buffer.getBytes(0, value);
+ builder.setBindingValue(value);
+ }
+
+ private void backwardsSerializer(final PathBinding pTlv, final ByteBuf body) {
+ ByteBufWriteUtil.writeUnsignedShort((int)pTlv.getBindingType(), body);
+ body.writeBytes(pTlv.getBindingValue());
+ }
+
+ private static final class MplsLabelCodec implements PathBindingTlvCodec {
+
+ @Override
+ public ByteBuf serialize(final BindingTypeValue bindingValue) {
+ final MplsLabel mplsLabel = (MplsLabel) bindingValue;
+ final ByteBuf value = Unpooled.buffer(MPLS_ENTRY_LENGTH);
+ ByteBufWriteUtil.writeUnsignedInt(getMplsStackEntry(mplsLabel.getMplsLabel()), value);
+ return value;
+ }
+
+ @Override
+ public BindingTypeValue deserialize(final ByteBuf buffer) {
+ final MplsLabelBuilder builder = new MplsLabelBuilder();
+ builder.setMplsLabel(getMplsLabel(buffer.readUnsignedInt()));
+ return builder.build();
+ }
+
+ @Override
+ public int getBindingType() {
+ return MPLS_LABEL;