001package org.xbib.elasticsearch.transport.netty;
002
003import org.elasticsearch.Version;
004import org.jboss.netty.buffer.ChannelBuffer;
005
006/**
007 */
008public class NettyHeader {
009
010    public static final int HEADER_SIZE = 2 + 4 + 8 + 1 + 4;
011
012    public static void writeHeader(ChannelBuffer buffer, long requestId, byte status, Version version) {
013        int index = buffer.readerIndex();
014        buffer.setByte(index, 'E');
015        index += 1;
016        buffer.setByte(index, 'S');
017        index += 1;
018        // write the size, the size indicates the remaining message size, not including the size int
019        buffer.setInt(index, buffer.readableBytes() - 6);
020        index += 4;
021        buffer.setLong(index, requestId);
022        index += 8;
023        buffer.setByte(index, status);
024        index += 1;
025        buffer.setInt(index, version.id);
026    }
027}