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;
13 import io.netty.buffer.ByteBuf;
15 import java.util.Arrays;
17 public final class MessageUtil {
20 public static final int MARKER_LENGTH = 16;
22 public static final int COMMON_HEADER_LENGTH = 19;
23 private static final byte[] MARKER = new byte[MARKER_LENGTH];
26 Arrays.fill(MARKER, 0, MARKER_LENGTH, UnsignedBytes.MAX_VALUE);
29 private MessageUtil() {
33 * Adds header to message value.
35 * @param type of the message
36 * @param value message value
37 * @param buffer ByteBuf where the message will be copied with its header
39 public static void formatMessage(final int type, final ByteBuf body, final ByteBuf buffer) {
40 buffer.writeBytes(MARKER);
41 buffer.writeShort(body.writerIndex() + COMMON_HEADER_LENGTH);
42 buffer.writeByte(type);
43 buffer.writeBytes(body);