X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fobject%2FAbstractVendorInformationObjectParser.java;fp=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fobject%2FAbstractVendorInformationObjectParser.java;h=7a5df2b5ef013abf1136cdfe5ed4a22235009828;hb=59bd8a58570b93fef65340808e37cab3c6fced8c;hp=53a83eca77721328720439d6664cf886802884b0;hpb=3b658310b793d4882ce59198a6d2563ce6ba114d;p=bgpcep.git diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractVendorInformationObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractVendorInformationObjectParser.java index 53a83eca77..7a5df2b5ef 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractVendorInformationObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractVendorInformationObjectParser.java @@ -5,14 +5,12 @@ * 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.pcep.parser.object; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS; import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE; -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.CommonObjectParser; @@ -25,30 +23,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder; +import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils; public abstract class AbstractVendorInformationObjectParser extends CommonObjectParser implements ObjectSerializer, EnterpriseSpecificInformationParser { - public AbstractVendorInformationObjectParser(final int objectClass, final int objectType) { super(objectClass, objectType); } @Override public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { - Preconditions.checkArgument(buffer != null && buffer.isReadable(), - "Array of bytes is mandatory. Can't be null or empty."); - final VendorInformationObjectBuilder builder = new VendorInformationObjectBuilder(); - builder.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber())); - builder.setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer)); - return builder.build(); + checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); + return new VendorInformationObjectBuilder() + .setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber())) + .setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer)) + .build(); } @Override public final void serializeObject(final Object object, final ByteBuf buffer) { - Preconditions.checkArgument(object instanceof VendorInformationObject, + checkArgument(object instanceof VendorInformationObject, "Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass()); final ByteBuf body = Unpooled.buffer(); - writeUnsignedInt(getEnterpriseNumber().getValue(), body); + ByteBufUtils.write(body, getEnterpriseNumber().getValue()); serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(), body); ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS,