Bump versions to 0.21.7-SNAPSHOT
[bgpcep.git] / bgp / extensions / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / handlers / NumericOneByteOperandParser.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.flowspec.handlers;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.Iterator;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOneByteValue;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand;
15 import org.opendaylight.yangtools.yang.common.Uint8;
16 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
17
18 /**
19  * Parser class for NumericOneByteValues.
20  */
21 public final class NumericOneByteOperandParser extends AbstractNumericByteOperandParser<NumericOneByteValue, Uint8> {
22     public static final NumericOneByteOperandParser INSTANCE = new NumericOneByteOperandParser();
23
24     private NumericOneByteOperandParser() {
25
26     }
27
28     /**
29      * Serializes Flowspec component type that has maximum of 1B sized value field and numeric operand.
30      *
31      * @param list        of operands to be serialized
32      * @param nlriByteBuf where the operands will be serialized
33      */
34     @Override
35     public <T extends NumericOneByteValue> void serialize(final List<T> list, final ByteBuf nlriByteBuf) {
36         for (final Iterator<T> it = list.iterator(); it.hasNext(); ) {
37             final T operand = it.next();
38             serialize(operand.getOp(), 1, !it.hasNext(), nlriByteBuf);
39             ByteBufUtils.write(nlriByteBuf, operand.getValue());
40         }
41     }
42
43     @Override
44     protected <T extends NumericOneByteValue> Uint8 getValue(final T item) {
45         return item.getValue();
46     }
47
48     @Override
49     <T extends NumericOneByteValue> NumericOperand getOp(final T item) {
50         return item.getOp();
51     }
52 }