2 * Copyright (c) 2014 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.pcep.spi;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
13 public final class MessageUtil {
15 private static final int VERSION_SF_LENGTH = 3;
17 private MessageUtil() {
18 throw new UnsupportedOperationException();
21 public static void formatMessage(final int messageType, final ByteBuf body, final ByteBuf out) {
22 final int msgLength = body.writerIndex();
23 out.writeByte(PCEPMessageConstants.PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH));
24 out.writeByte(messageType);
25 out.writeShort(msgLength + PCEPMessageConstants.COMMON_HEADER_LENGTH);
26 Preconditions.checkState(out.writerIndex() == PCEPMessageConstants.COMMON_HEADER_LENGTH);