Create common parent for extensions families
[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.rev180329.NumericOneByteValue;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
15
16 /**
17  * Parser class for NumericOneByteValues.
18  */
19 public final class NumericOneByteOperandParser extends AbstractNumericByteOperandParser<NumericOneByteValue, Short> {
20
21     public static final NumericOneByteOperandParser INSTANCE;
22
23     static {
24         INSTANCE = new NumericOneByteOperandParser();
25     }
26
27     private NumericOneByteOperandParser() {
28
29     }
30
31     /**
32      * Serializes Flowspec component type that has maximum of 1B sized value field and numeric operand.
33      *
34      * @param list        of operands to be serialized
35      * @param nlriByteBuf where the operands will be serialized
36      */
37     @Override
38     public <T extends NumericOneByteValue> void serialize(final List<T> list, final ByteBuf nlriByteBuf) {
39         for (final Iterator<T> it = list.iterator(); it.hasNext(); ) {
40             final T operand = it.next();
41             super.serialize(operand.getOp(), 1, !it.hasNext(), nlriByteBuf);
42             Util.writeShortest(operand.getValue(), nlriByteBuf);
43         }
44     }
45
46     @Override
47     protected <T extends NumericOneByteValue> Short getValue(final T item) {
48         return item.getValue();
49     }
50
51     @Override
52     <T extends NumericOneByteValue> NumericOperand getOp(final T item) {
53         return item.getOp();
54     }
55 }