67e527665247627122574c3c1e9d4ad54f565a81
[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         private static final int HEADER_SIZE = 2;
17
18         private CapabilityUtil() {
19
20         }
21
22         public static byte[] formatCapability(final int code, final byte[] value) {
23                 final byte[] ret = new byte[HEADER_SIZE + value.length];
24                 ret[0] = UnsignedBytes.checkedCast(code);
25                 ret[1] = UnsignedBytes.checkedCast(value.length);
26                 ByteArray.copyWhole(value, ret, HEADER_SIZE);
27                 return ret;
28         }
29 }