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 com.google.common.annotations.VisibleForTesting;
11 import com.google.common.primitives.UnsignedBytes;
12 import io.netty.buffer.ByteBuf;
13 import java.util.Arrays;
15 public final class MessageUtil {
18 public static final int MARKER_LENGTH = 16;
20 public static final int COMMON_HEADER_LENGTH = 19;
21 private static final byte[] MARKER = new byte[MARKER_LENGTH];
24 Arrays.fill(MARKER, 0, MARKER_LENGTH, UnsignedBytes.MAX_VALUE);
27 private MessageUtil() {
28 throw new UnsupportedOperationException();
32 * Adds header to message value.
34 * @param type of the message
35 * @param value message value
36 * @param buffer ByteBuf where the message will be copied with its header
38 public static void formatMessage(final int type, final ByteBuf body, final ByteBuf buffer) {
39 buffer.writeBytes(MARKER);
40 buffer.writeShort(body.writerIndex() + COMMON_HEADER_LENGTH);
41 buffer.writeByte(type);
42 buffer.writeBytes(body);