2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.parser.spi;
10 import org.opendaylight.protocol.util.ByteArray;
12 import com.google.common.primitives.UnsignedBytes;
14 public final class CapabilityUtil {
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;
20 private CapabilityUtil() {
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);