Fix junit dependencies in poms. Reuse existing from parent,
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / CapabilityUtil.java
1 /*
2  * Copyright (c) 2013 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.parser.spi;
9
10 import org.opendaylight.protocol.util.ByteArray;
11
12 import com.google.common.primitives.UnsignedBytes;
13
14 public final class CapabilityUtil {
15
16         public static final int CODE_SIZE = 1; // bytes
17         public static final int LENGTH_SIZE = 1; // bytes
18         private static final int HEADER_SIZE = CODE_SIZE + LENGTH_SIZE;
19
20         private CapabilityUtil() {
21
22         }
23
24         public static byte[] formatCapability(final int code, final byte[] value) {
25                 final byte[] ret = new byte[HEADER_SIZE + value.length];
26                 ret[0] = UnsignedBytes.checkedCast(code);
27                 ret[1] = UnsignedBytes.checkedCast(value.length);
28                 ByteArray.copyWhole(value, ret, HEADER_SIZE);
29                 return ret;
30         }
31 }