Java ByteBuffer Fill fillDdsBuffer(ByteBuffer buf)

Here you can find the source of fillDdsBuffer(ByteBuffer buf)

Description

fill Dds Buffer

License

Apache License

Declaration

public static ByteBuffer fillDdsBuffer(ByteBuffer buf) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    public static final float ddsPrecision = 0.95f;
    public static final String ddsDescription = "Answer";
    public static final boolean ddsAcknowledged = false;
    public static final int ddsNumber = 42;

    public static ByteBuffer fillDdsBuffer(ByteBuffer buf) {
        // Actually, format of SUPPORTED_CLASS topic is:
        // an int (number)
        // a boolean (acknowledeged)
        // a String (description)
        // a float (precision)

        // rewind the buffer
        buf.rewind();/*from w w  w. j  av a2 s  .  c o  m*/

        // put a number
        buf.putInt(ddsNumber);
        buf.put((byte) (ddsAcknowledged ? 1 : 0));
        buf.putInt(ddsDescription.length());
        for (int i = 0; i < ddsDescription.length(); i++) {
            buf.putChar(ddsDescription.charAt(i));
        }
        buf.putFloat(ddsPrecision);

        buf.rewind(); //Don't forget to rewind the buffer. The interface processor won't do it...
        return buf;
    }
}

Related

  1. fill(ByteBuffer buffer, int position, int length, byte filler)
  2. fill(ByteBuffer to, byte[] b, int off, int len)
  3. fillBuffer(ByteBuffer buffer, byte[] bytes)
  4. fillBuffer(ByteBuffer buffer, int seed)
  5. fillBufFromTime(ByteBuffer buf, Calendar cal)
  6. fillHlaBuffer(ByteBuffer buf)
  7. fillRange(ByteBuffer buffer, int start, int end)