Bug 4827: MultiPathSupport utilities
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / 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;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.List;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOneByteValue;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
14
15 /**
16  * Parser class for NumericOneByteValues.
17  */
18 public final class NumericOneByteOperandParser extends AbstractNumericByteOperandParser<NumericOneByteValue, Short> {
19
20     public static final NumericOneByteOperandParser INSTANCE;
21
22     static {
23         INSTANCE = new NumericOneByteOperandParser();
24     }
25
26     private NumericOneByteOperandParser() {
27
28     }
29
30     /**
31      * Serializes Flowspec component type that has maximum of 1B sized value field and numeric operand.
32      *
33      * @param list        of operands to be serialized
34      * @param nlriByteBuf where the operands will be serialized
35      */
36     @Override
37     public <T extends NumericOneByteValue> void serialize(final List<T> list, final ByteBuf nlriByteBuf) {
38         for (final T operand : list) {
39             super.serialize(operand.getOp(), 1, nlriByteBuf);
40             Util.writeShortest(operand.getValue(), nlriByteBuf);
41         }
42     }
43
44     @Override
45     protected <T extends NumericOneByteValue> Short getValue(final T item) {
46         return item.getValue();
47     }
48
49     @Override
50     <T extends NumericOneByteValue> NumericOperand getOp(final T item) {
51         return item.getOp();
52     }
53 }