* 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.rsvp.parser.spi.subobjects;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public abstract class AbstractRSVPObjectParser implements RSVPTeObjectSerializer, RSVPTeObjectParser {
}
protected static void writeAttributeFilter(final AttributeFilter attributeFilter, final ByteBuf body) {
- writeUnsignedInt(attributeFilter != null ? attributeFilter.getValue() : null, body);
+ if (attributeFilter != null) {
+ ByteBufUtils.write(body, attributeFilter.getValue());
+ } else {
+ body.writeInt(0);
+ }
}
@Override
package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class CommonPathKeyParser {
public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
.subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) {
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, pceIdFLength);
- final PathKeyBuilder pBuilder = new PathKeyBuilder();
- pBuilder.setPceId(new PceId(pceId));
- pBuilder.setPathKey(new PathKey(pathKey));
- return pBuilder.build();
+ return new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, pceIdFLength)))
+ .build();
}
public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) {
final ByteBuf body = Unpooled.buffer();
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
- checkArgument(pk.getPceId() != null, "PceId is mandatory.");
- body.writeBytes(pk.getPceId().getValue());
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
+
+ final PceId pceId = pk.getPceId();
+ checkArgument(pceId != null, "PceId is mandatory.");
+ body.writeBytes(pceId.getValue());
return body;
}
}
*/
package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
-import static com.google.common.base.Preconditions.checkArgument;
-
import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.Unnumbered;
}
protected static void serializeUnnumeredInterface(final Unnumbered unnumbered, final ByteBuf body) {
- checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory.");
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRouterId(), body);
- checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory.");
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getInterfaceId(), body);
+ ByteBufUtils.writeMandatory(body, unnumbered.getRouterId(), "RouterId");
+ ByteBufUtils.writeMandatory(body, unnumbered.getInterfaceId(), "InterfaceId");
}
}