X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fietf-stateful07%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fietf%2Fstateful07%2FStateful07LspUpdateErrorTlvParser.java;h=db07363f20a75b363650fcb9bc1b8b8062803a29;hb=2894d2f6aaf1ed73ff9253cbd2fe283a4a471aa0;hp=ce5a162b42cb7d87019b018e9fa09c277c1b46a6;hpb=9ad60da9f34b2efed5267dc03557afcf038838c3;p=bgpcep.git diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java index ce5a162b42..db07363f20 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java @@ -7,35 +7,41 @@ */ package org.opendaylight.protocol.pcep.ietf.stateful07; -import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil; +import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; -import org.opendaylight.protocol.util.ByteArray; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; +import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; +import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils; /** - * Parser for {@link LspErrorCode} + * Parser for {@link LspErrorCode}. */ public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSerializer { + public static final int TYPE = 20; - public static final int TYPE = 20; - - private static final int UPDATE_ERR_CODE_LENGTH = 4; + private static final int CONTENT_LENGTH = Integer.SIZE / Byte.SIZE; - @Override - public LspErrorCode parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new LspErrorCodeBuilder().setErrorCode(ByteArray.bytesToLong(buffer)).build(); - } + @Override + public LspErrorCode parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { + if (buffer == null) { + return null; + } + return new LspErrorCodeBuilder().setErrorCode(ByteBufUtils.readUint32(buffer)).build(); + } - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) { - throw new IllegalArgumentException("LspErrorCodeTlv is mandatory."); - } - final LspErrorCode lsp = (LspErrorCode) tlv; - return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH)); - } + @Override + public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { + Preconditions.checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory."); + final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); + writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body); + TlvUtil.formatTlv(TYPE, body, buffer); + } }