Java ByteBuffer Write writeSize(final int s, ByteBuffer buffer)

Here you can find the source of writeSize(final int s, ByteBuffer buffer)

Description

write Size

License

Open Source License

Declaration

public final static void writeSize(final int s, ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/**//from  w w  w  .j  ava2s. c  o  m
 * Copyright - See the COPYRIGHT that is included with this distribution.
 * EPICS pvData is distributed subject to a Software License Agreement found
 * in file LICENSE that is included with this distribution.
 */

import java.nio.ByteBuffer;

public class Main {
    public final static void writeSize(final int s, ByteBuffer buffer) {
        if (s == -1) // null
            buffer.put((byte) -1);
        else if (s < 254)
            buffer.put((byte) s);
        else
            buffer.put((byte) -2).putInt(s); // (byte)-2 + size
    }
}

Related

  1. writeRemaining(WritableByteChannel channel, ByteBuffer buffer)
  2. writeResBit15(int value, ByteBuffer toBuffer)
  3. writeShortString(ByteBuffer buffer, String s)
  4. writeSign(ByteBuffer bb)
  5. writeSignedVarint(ByteBuffer buffer, int val)
  6. writeSlice(ByteBuffer src, int number, ByteBuffer dst)
  7. writeString(ByteBuffer buf, String s)
  8. writeString(ByteBuffer buf, String str)
  9. writeString(ByteBuffer buf, String value)