コード例 #1
0
 /** Encode message with raw data and other informations */
 public byte[] encode() throws IOException {
   byte[] buffer = new byte[8 + 26];
   ByteBuffer dos = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN);
   dos.put((byte) 0xFE);
   dos.put((byte) (length & 0x00FF));
   dos.put((byte) (sequence & 0x00FF));
   dos.put((byte) (sysId & 0x00FF));
   dos.put((byte) (componentId & 0x00FF));
   dos.put((byte) (messageType & 0x00FF));
   dos.putFloat(nav_roll);
   dos.putFloat(nav_pitch);
   dos.putFloat(alt_error);
   dos.putFloat(aspd_error);
   dos.putFloat(xtrack_error);
   dos.putShort((short) (nav_bearing & 0x00FFFF));
   dos.putShort((short) (target_bearing & 0x00FFFF));
   dos.putShort((short) (wp_dist & 0x00FFFF));
   int crc = MAVLinkCRC.crc_calculate_encode(buffer, 26);
   crc = MAVLinkCRC.crc_accumulate((byte) IMAVLinkCRC.MAVLINK_MESSAGE_CRCS[messageType], crc);
   byte crcl = (byte) (crc & 0x00FF);
   byte crch = (byte) ((crc >> 8) & 0x00FF);
   buffer[32] = crcl;
   buffer[33] = crch;
   return buffer;
 }
コード例 #2
0
ファイル: Guitar.java プロジェクト: viotatsuya/firetaps
  private void loadWaveformResources(Context context, GL10 gl) throws IOException {
    m_waveformTexture = GLHelpers.loadTexture(gl, context, R.drawable.waveform);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

    if (m_waveformVertices == null) {
      ByteBuffer vertices = GLHelpers.allocateFloatBuffer(WAVEFORM_POINTS * 3);
      vertices
          .putFloat(+WAVEFORM_HEAD_WIDTH / 2)
          .putFloat(0)
          .putFloat(0)
          .putFloat(-WAVEFORM_HEAD_WIDTH / 2)
          .putFloat(0)
          .putFloat(0)
          .putFloat(+0.5f)
          .putFloat(0)
          .putFloat(WAVEFORM_HEAD_HEIGHT)
          .putFloat(-0.5f)
          .putFloat(0)
          .putFloat(WAVEFORM_HEAD_HEIGHT)
          .putFloat(+0.5f)
          .putFloat(0)
          .putFloat(1 - WAVEFORM_TAIL_HEIGHT)
          .putFloat(-0.5f)
          .putFloat(0)
          .putFloat(1 - WAVEFORM_TAIL_HEIGHT)
          .putFloat(+WAVEFORM_TAIL_WIDTH / 2)
          .putFloat(0)
          .putFloat(1)
          .putFloat(-WAVEFORM_TAIL_WIDTH / 2)
          .putFloat(0)
          .putFloat(1);

      ByteBuffer texcoords = GLHelpers.allocateFloatBuffer(WAVEFORM_POINTS * 2);
      {
        vertices.position(0);
        for (int i = 0; i != WAVEFORM_POINTS; ++i) {
          float x = vertices.getFloat();
          /*float y=*/ vertices.getFloat();
          float z = vertices.getFloat();
          texcoords.putFloat(-x + 0.5f);
          texcoords.putFloat(z);
        }
      }
      m_waveformVertices = GLBufferObject.createVertices(3, GL10.GL_FLOAT, vertices);
      m_waveformTexcoords = GLBufferObject.createTexcoords(2, GL10.GL_FLOAT, texcoords);
    }
    m_waveformVertices.bind(gl);
    m_waveformTexcoords.bind(gl);
  }
コード例 #3
0
ファイル: FloatDataType.java プロジェクト: omnik/baser-lib
 @Override
 public int write(Object value, ByteBuffer bb) {
   if (value == null) {
     return -1;
   }
   if (value instanceof Float) {
     bb.putFloat((Float) value);
   } else if (value instanceof Double) {
     bb.putFloat(((Double) value).floatValue());
   } else {
     throw new RuntimeException(
         "Can't write value of class " + value.getClass().getName() + " to FloatDataType");
   }
   return 8;
 }
コード例 #4
0
  public byte[] generateTestPacket() {
    ByteBuffer payload = ByteBuffer.allocate(6 + MAVLINK_MSG_LENGTH + 2);
    payload.put((byte) MAVLinkPacket.MAVLINK_STX); // stx
    payload.put((byte) MAVLINK_MSG_LENGTH); // len
    payload.put((byte) 0); // seq
    payload.put((byte) 255); // sysid
    payload.put((byte) 190); // comp id
    payload.put((byte) MAVLINK_MSG_ID_PARAM_SET); // msg id
    payload.putFloat((float) 17.0); // param_value
    payload.put((byte) 17); // target_system
    payload.put((byte) 84); // target_component
    // param_id
    payload.put((byte) 'G');
    payload.put((byte) 'H');
    payload.put((byte) 'I');
    payload.put((byte) 'J');
    payload.put((byte) 'K');
    payload.put((byte) 'L');
    payload.put((byte) 'M');
    payload.put((byte) 'N');
    payload.put((byte) 'O');
    payload.put((byte) 'P');
    payload.put((byte) 'Q');
    payload.put((byte) 'R');
    payload.put((byte) 'S');
    payload.put((byte) 'T');
    payload.put((byte) 'U');
    payload.put((byte) 'G');
    payload.put((byte) 199); // param_type

    CRC crc = generateCRC(payload.array());
    payload.put((byte) crc.getLSB());
    payload.put((byte) crc.getMSB());
    return payload.array();
  }
コード例 #5
0
  /**
   * returns the Vertex Buffer for the Collision World
   *
   * @return Vertex Buffer
   */
  public ByteBuffer getVertexBuffer(MTTriangleMesh mesh) {

    Vertex[] vertices = mesh.getGeometryInfo().getVertices();

    ByteBuffer buf =
        ByteBuffer.allocateDirect(vertices.length * 4 * 3).order(ByteOrder.nativeOrder());
    for (int i = 0; i < vertices.length; i++) {

      // vertices[i].scaleLocal(scale);
      buf.putFloat(vertices[i].x);
      buf.putFloat(vertices[i].y);
      buf.putFloat(vertices[i].z);
    }
    buf.flip();
    return buf;
  }
コード例 #6
0
  @Override
  public boolean serialize() {
    int size = getSize();

    if (size == 0) {
      return false;
    }

    ByteBuffer buffer = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN);

    try {
      buffer.putShort(getHeader());

      buffer.putInt(unknown1);
      buffer.putFloat(unknown2[0]);
      buffer.putFloat(unknown2[1]);
      buffer.putShort(unknown3);
    } catch (BufferOverflowException e) {
      return false;
    }

    setBuffer(buffer);

    return true;
  }
コード例 #7
0
ファイル: MAVLinkMessage.java プロジェクト: yueyehu/cjMAVSim
 private void setValue(MAVLinkDataType type, int offset, Object value) {
   switch (type) {
     case CHAR:
     case UINT8:
     case INT8:
       payloadBB.put(offset, ((Number) value).byteValue());
       break;
     case UINT16:
     case INT16:
       payloadBB.putShort(offset, ((Number) value).shortValue());
       break;
     case UINT32:
     case INT32:
       payloadBB.putInt(offset, ((Number) value).intValue());
       break;
     case UINT64:
     case INT64:
       payloadBB.putLong(offset, ((Number) value).longValue());
       break;
     case FLOAT:
       payloadBB.putFloat(offset, ((Number) value).floatValue());
       break;
     case DOUBLE:
       payloadBB.putDouble(offset, ((Number) value).doubleValue());
       break;
     default:
       throw new RuntimeException("Unknown type: " + type);
   }
 }
コード例 #8
0
ファイル: Points.java プロジェクト: LuanSala/Viewer
 // Separa o buffer (variavel byte[] buffer) em 2 buffers, colocando em um buffer os vertices
 // (vertexBuffer) e em outro buffer as cores (colorBuffer).
 private void separateBuffers() {
   if (problemBufferInterleaved) {
     System.gc();
     vertexBuffer = ByteBuffer.allocate(totalPoints * 3 * 4).order(ByteOrder.LITTLE_ENDIAN);
     colorBuffer = ByteBuffer.allocate(totalPoints * 3).order(ByteOrder.LITTLE_ENDIAN);
     vertexBuffer.position(0);
     colorBuffer.position(0);
     for (int i = 0; i < (totalPoints - 1); i++) {
       vertexBuffer.putFloat(buffer.getFloat(i * 15));
       vertexBuffer.putFloat(buffer.getFloat((i * 15) + 4));
       vertexBuffer.putFloat(buffer.getFloat((i * 15) + 8));
       colorBuffer.put(buffer.get((i * 15) + 12));
       colorBuffer.put(buffer.get((i * 15) + 13));
       colorBuffer.put(buffer.get((i * 15) + 14));
     }
   }
 }
コード例 #9
0
  @Theory
  public void shouldGetFloatFromNativeBuffer(final AtomicBuffer buffer) {
    final ByteBuffer duplicateBuffer = byteBuffer(buffer);

    duplicateBuffer.putFloat(INDEX, FLOAT_VALUE);

    assertThat(buffer.getFloat(INDEX), is(FLOAT_VALUE));
  }
コード例 #10
0
ファイル: FidBlockHeader.java プロジェクト: bayes/Bayes
  public static void writeBlockHeader(FileChannel channel, FidBlockHeader blockHeader)
      throws IOException {
    ByteBuffer buffer = ByteBuffer.allocateDirect(FidFileHeader.BLOCK_HEADER_LENGTH);

    buffer.putShort(blockHeader.scale);
    buffer.putShort(blockHeader.status);
    buffer.putShort(blockHeader.index);
    buffer.putShort(blockHeader.mode);
    buffer.putInt(blockHeader.ctcount);
    buffer.putFloat(blockHeader.lpval);
    buffer.putFloat(blockHeader.rpval);
    buffer.putFloat(blockHeader.lvl);
    buffer.putFloat(blockHeader.tlt);

    buffer.rewind();
    channel.write(buffer);
  }
コード例 #11
0
 public static ByteBuffer updatePlayerPosition(int iId, float x, float y) {
   ByteBuffer oByteBuffer = allocateByteBuffer(14);
   oByteBuffer.putShort(MSG_UPDATE_POSITION);
   oByteBuffer.putInt(iId);
   oByteBuffer.putFloat(x);
   oByteBuffer.putFloat(y);
   oByteBuffer.flip();
   return oByteBuffer;
 }
コード例 #12
0
  /**
   * Writes a double in the good byte order (LITTLE_ENDIAN) in the writer.
   *
   * @param writer the writer which writes in the file
   * @param a the double to write
   * @throws IOException if the writer throws an error
   */
  private static void writeInGoodOrder(final OutputStream writer, final double a)
      throws IOException {

    // Write the double, but must before order it in the LITTLE_ENDIAN
    // format.
    final ByteBuffer bBuf = ByteBuffer.allocate(Float.SIZE);
    bBuf.order(ByteOrder.LITTLE_ENDIAN);
    bBuf.putFloat((float) a);

    writer.write(bBuf.array(), 0, Float.SIZE / Byte.SIZE);
  }
コード例 #13
0
  /**
   * Creates an array of bytes to be sent across the network that represents a Message object.
   *
   * @return A byte representation of the Message object.
   */
  public byte[] getByteMessage() throws Exception {
    // Get the header
    byte[] header = getByteHeader();
    byte[] message = new byte[header.length + dataLength];

    // Place the header information
    ByteBuffer buffer = ByteBuffer.wrap(message);
    buffer.put(header);

    // Start position
    buffer.putFloat(startPos.getX());
    buffer.putFloat(startPos.getY());

    // Direction
    buffer.putFloat(direction.getX());
    buffer.putFloat(direction.getY());

    // Return the fully created message
    return message;
  }
コード例 #14
0
 public static ByteBuffer playerLoggedIn(int iId, String sUsername, float x, float y, int iMap) {
   ByteBuffer oByteBuffer = allocateByteBuffer(sUsername.getBytes().length + 10 + 12);
   oByteBuffer.putShort(MSG_PLAYER_LOGGED_IN);
   oByteBuffer.putInt(iId);
   putString(oByteBuffer, sUsername);
   oByteBuffer.putFloat(x);
   oByteBuffer.putFloat(y);
   oByteBuffer.putInt(iMap);
   oByteBuffer.flip();
   return oByteBuffer;
 }
コード例 #15
0
 public static ByteBuffer loginResponse(byte i, int iId, float x, float y, int iMap) {
   ByteBuffer oByteBuffer = allocateByteBuffer(7 + 4 * 2 + 4);
   oByteBuffer.putShort(MSG_LOGIN);
   oByteBuffer.put(i);
   oByteBuffer.putInt(iId);
   oByteBuffer.putFloat(x);
   oByteBuffer.putFloat(y);
   oByteBuffer.putInt(iMap);
   oByteBuffer.flip();
   return oByteBuffer;
 }
コード例 #16
0
ファイル: TlvEncoder.java プロジェクト: weihuaiyu/leshan
 /** Encodes a floating point value. */
 public static byte[] encodeFloat(Number number) {
   ByteBuffer fBuf = null;
   double dValue = number.doubleValue();
   if (dValue >= Float.MIN_VALUE && dValue <= Float.MAX_VALUE) {
     fBuf = ByteBuffer.allocate(4);
     fBuf.putFloat((float) dValue);
   } else {
     fBuf = ByteBuffer.allocate(8);
     fBuf.putDouble(dValue);
   }
   return fBuf.array();
 }
コード例 #17
0
ファイル: class_4632_bQV.java プロジェクト: juankdams/Synx
 public boolean g(ByteBuffer paramByteBuffer) {
   if (this.gZr != null) {
     if (this.gZr.length > 65535) return false;
     paramByteBuffer.putShort((short) this.gZr.length);
     paramByteBuffer.put(this.gZr);
   } else {
     paramByteBuffer.putShort((short) 0);
   }
   paramByteBuffer.putInt(this.gZs);
   paramByteBuffer.putFloat(this.gZt);
   return true;
 }
コード例 #18
0
  public byte[] generateTestPacket() {
    ByteBuffer payload = ByteBuffer.allocate(6 + MAVLINK_MSG_LENGTH + 2);
    payload.put((byte) MAVLinkPacket.MAVLINK_STX); // stx
    payload.put((byte) MAVLINK_MSG_LENGTH); // len
    payload.put((byte) 0); // seq
    payload.put((byte) 255); // sysid
    payload.put((byte) 190); // comp id
    payload.put((byte) MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED); // msg id
    payload.putInt(963497464); // time_boot_ms
    payload.putFloat((float) 45.0); // x
    payload.putFloat((float) 73.0); // y
    payload.putFloat((float) 101.0); // z
    payload.putFloat((float) 129.0); // vx
    payload.putFloat((float) 157.0); // vy
    payload.putFloat((float) 185.0); // vz
    payload.putFloat((float) 213.0); // afx
    payload.putFloat((float) 241.0); // afy
    payload.putFloat((float) 269.0); // afz
    payload.putFloat((float) 297.0); // yaw
    payload.putFloat((float) 325.0); // yaw_rate
    payload.putShort((short) 19731); // type_mask
    payload.put((byte) 27); // coordinate_frame

    CRC crc = generateCRC(payload.array());
    payload.put((byte) crc.getLSB());
    payload.put((byte) crc.getMSB());
    return payload.array();
  }
コード例 #19
0
 /** Encode message with raw data and other informations */
 public byte[] encode() throws IOException {
   byte[] buffer = new byte[8 + 20];
   ByteBuffer dos = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN);
   dos.put((byte) 0xFE);
   dos.put((byte) (length & 0x00FF));
   dos.put((byte) (sequence & 0x00FF));
   dos.put((byte) (sysId & 0x00FF));
   dos.put((byte) (componentId & 0x00FF));
   dos.put((byte) (messageType & 0x00FF));
   dos.putInt((int) (time_boot_ms & 0x00FFFFFFFF));
   dos.putFloat(roll_rate);
   dos.putFloat(pitch_rate);
   dos.putFloat(yaw_rate);
   dos.putFloat(thrust);
   int crc = MAVLinkCRC.crc_calculate_encode(buffer, 20);
   crc = MAVLinkCRC.crc_accumulate((byte) IMAVLinkCRC.MAVLINK_MESSAGE_CRCS[messageType], crc);
   byte crcl = (byte) (crc & 0x00FF);
   byte crch = (byte) ((crc >> 8) & 0x00FF);
   buffer[26] = crcl;
   buffer[27] = crch;
   return buffer;
 }
コード例 #20
0
ファイル: UnitTestCase.java プロジェクト: igorhvr/hornetq
  protected byte[] autoEncode(final Object... args) {

    int size = 0;

    for (Object arg : args) {
      if (arg instanceof Byte) {
        size++;
      } else if (arg instanceof Boolean) {
        size++;
      } else if (arg instanceof Integer) {
        size += 4;
      } else if (arg instanceof Long) {
        size += 8;
      } else if (arg instanceof Float) {
        size += 4;
      } else if (arg instanceof Double) {
        size += 8;
      } else {
        throw new IllegalArgumentException(
            "method autoEncode doesn't know how to convert " + arg.getClass() + " yet");
      }
    }

    ByteBuffer buffer = ByteBuffer.allocate(size);

    for (Object arg : args) {
      if (arg instanceof Byte) {
        buffer.put(((Byte) arg).byteValue());
      } else if (arg instanceof Boolean) {
        Boolean b = (Boolean) arg;
        buffer.put((byte) (b.booleanValue() ? 1 : 0));
      } else if (arg instanceof Integer) {
        buffer.putInt(((Integer) arg).intValue());
      } else if (arg instanceof Long) {
        buffer.putLong(((Long) arg).longValue());
      } else if (arg instanceof Float) {
        buffer.putFloat(((Float) arg).floatValue());
      } else if (arg instanceof Double) {
        buffer.putDouble(((Double) arg).doubleValue());
      } else {
        throw new IllegalArgumentException(
            "method autoEncode doesn't know how to convert " + arg.getClass() + " yet");
      }
    }

    return buffer.array();
  }
コード例 #21
0
  public boolean putObservation(Observation observation) {
    int ncStatus = 0;
    NativeLongByReference record_startp = new NativeLongByReference(new NativeLong(record_index));
    NativeLongByReference record_countp = new NativeLongByReference(new NativeLong(1));

    boolean observationPutSuccessful = false;
    if (!isClosed && record.isObservationValid(observation)) {
      ByteBuffer recordBuffer = ByteBuffer.allocateDirect(record.getCompoundSize());
      recordBuffer.order(ByteOrder.nativeOrder());

      recordBuffer.putInt(observation.station_index);
      recordBuffer.putInt(observation.time_offset);
      for (Object value : observation.values) {
        if (value instanceof String) {
          throw new UnsupportedOperationException("Need to implement char[] or string");
          //                    String val = (String) value;
          //                    ncStatus = nc_put_att_text(ncId, ncVarId, key, val);
          //                    status(ncStatus);
        } else if (value instanceof Integer) {
          int val = ((Integer) value).intValue();
          recordBuffer.putInt(val);
        } else if (value instanceof Short) {
          short val = ((Short) value).shortValue();
          recordBuffer.putShort(val);
        } else if (value instanceof Float) {
          float val = ((Float) value).floatValue();
          recordBuffer.putFloat(val);
        } else if (value instanceof Double) {
          double val = ((Double) value).doubleValue();
          recordBuffer.putDouble(val);
        } else {
          throw new UnsupportedOperationException("Should implement the other types");
        }
      } // record complete

      recordBuffer.rewind();
      ncStatus = nc_put_vara(ncId, record.getVarId(), record_startp, record_countp, recordBuffer);
      status(ncStatus);
      record_index++;

      // station_indexp.setValue(station_indexp.longValue() + 1);
      return true;
    }
    return observationPutSuccessful;
  }
コード例 #22
0
ファイル: PyMarkObject.java プロジェクト: orangeduck/PyMark
  public static void PackObject(ByteBuffer bb, PyMarkObject o) throws IOException {

    bb.put(o.type());

    switch (o.type()) {
      case PyMarkIntType:
        bb.putInt(o.asInt());
        break;
      case PyMarkLongType:
        bb.putLong(o.asLong());
        break;
      case PyMarkFloatType:
        bb.putFloat(o.asFloat());
        break;
      case PyMarkDoubleType:
        bb.putDouble(o.asDouble());
        break;
      case PyMarkBoolType:
        if (o.asBool()) {
          bb.put((byte) 1);
        } else {
          bb.put((byte) 0);
        }
        break;
      case PyMarkNoneType:
        break;
      case PyMarkStringType:
        bb.putLong((long) o.asString().length());
        for (int i = 0; i < o.asString().length(); i++) {
          byte b = (byte) o.asString().charAt(i);
          bb.put(b);
        }
        break;
      case PyMarkListType:
      case PyMarkTupleType:
      case PyMarkDictType:
        bb.putLong((long) o.length());
        for (int i = 0; i < o.length(); i++) {
          PackObject(bb, o.at(i));
        }
        break;
      default:
        throw new IOException("Unknown typeId " + (int) o.type());
    }
  }
コード例 #23
0
  public byte[] generateTestPacket() {
    ByteBuffer payload = ByteBuffer.allocate(6 + MAVLINK_MSG_LENGTH + 2);
    payload.put((byte) MAVLinkPacket.MAVLINK_STX); // stx
    payload.put((byte) MAVLINK_MSG_LENGTH); // len
    payload.put((byte) 0); // seq
    payload.put((byte) 255); // sysid
    payload.put((byte) 190); // comp id
    payload.put((byte) MAVLINK_MSG_ID_SCALED_PRESSURE3); // msg id
    payload.putInt((int) 963497464); // time_boot_ms
    payload.putFloat((float) 45.0); // press_abs
    payload.putFloat((float) 73.0); // press_diff
    payload.putShort((short) 17859); // temperature

    CRC crc = generateCRC(payload.array());
    payload.put((byte) crc.getLSB());
    payload.put((byte) crc.getMSB());
    return payload.array();
  }
コード例 #24
0
ファイル: UDPTweakClient.java プロジェクト: huwung/processing
  public boolean sendFloat(int index, float val) {
    if (!initialized) {
      return false;
    }

    try {
      byte[] buf = new byte[12];
      ByteBuffer bb = ByteBuffer.wrap(buf);
      bb.putInt(0, VAR_FLOAT);
      bb.putInt(4, index);
      bb.putFloat(8, val);
      DatagramPacket packet = new DatagramPacket(buf, buf.length, address, sketchPort);
      socket.send(packet);
    } catch (Exception e) {
      return false;
    }

    return true;
  }
コード例 #25
0
 @Override
 public ByteBuffer write(ByteBuffer buff, Object obj) {
   if (!(obj instanceof Float)) {
     return super.write(buff, obj);
   }
   float x = (Float) obj;
   int f = Float.floatToIntBits(x);
   if (f == ObjectDataType.FLOAT_ZERO_BITS) {
     buff.put((byte) TAG_FLOAT_0);
   } else if (f == ObjectDataType.FLOAT_ONE_BITS) {
     buff.put((byte) TAG_FLOAT_1);
   } else {
     int value = Integer.reverse(f);
     if (value >= 0 && value <= DataUtils.COMPRESSED_VAR_INT_MAX) {
       buff.put((byte) TYPE_FLOAT);
       DataUtils.writeVarInt(buff, value);
     } else {
       buff.put((byte) TAG_FLOAT_FIXED);
       buff.putFloat(x);
     }
   }
   return buff;
 }
コード例 #26
0
 public static void put(
     ByteBuffer buf, VertexFormatElement e, boolean denormalize, Number fill, Number... ns) {
   if (e.getElementCount() > ns.length && fill == null)
     throw new IllegalArgumentException("not enough elements");
   Number n;
   for (int i = 0; i < e.getElementCount(); i++) {
     if (i < ns.length) n = ns[i];
     else n = fill;
     switch (e.getType()) {
       case BYTE:
         buf.put(denormalize ? (byte) (n.floatValue() * (Byte.MAX_VALUE - 1)) : n.byteValue());
         break;
       case UBYTE:
         buf.put(denormalize ? (byte) (n.floatValue() * ((1 << Byte.SIZE) - 1)) : n.byteValue());
         break;
       case SHORT:
         buf.putShort(
             denormalize ? (short) (n.floatValue() * (Short.MAX_VALUE - 1)) : n.shortValue());
         break;
       case USHORT:
         buf.putShort(
             denormalize ? (short) (n.floatValue() * ((1 << Short.SIZE) - 1)) : n.shortValue());
         break;
       case INT:
         buf.putInt(
             denormalize ? (int) (n.doubleValue() * (Integer.MAX_VALUE - 1)) : n.intValue());
         break;
       case UINT:
         buf.putInt(
             denormalize ? (int) (n.doubleValue() * ((1L << Integer.SIZE) - 1)) : n.intValue());
         break;
       case FLOAT:
         buf.putFloat(n.floatValue());
         break;
     }
   }
 }
コード例 #27
0
      public void encode(ByteBuffer bytes, int pos) {

        if (bytes.array() == null) {
          return;
        }

        if (bytes.order() != ByteOrder.LITTLE_ENDIAN) {
          bytes.order(ByteOrder.LITTLE_ENDIAN);
        }

        try {
          short m_PresenceVectorTemp = (short) JausUtils.getPVInt(m_PresenceVector);
          bytes.put(pos, (byte) m_PresenceVectorTemp);
          pos += JausUtils.getNumBytes("byte");
        } catch (Exception e) {
          logger.log(Level.SEVERE, null, e);
        }
        bytes.putInt(pos, m_Command);
        pos += JausUtils.getNumBytes("int");
        if (checkPresenceVector(0)) {
          bytes.putFloat(pos, m_Value);
          pos += JausUtils.getNumBytes("int");
        }
      }
コード例 #28
0
 /**
  * Ensures space for an additional float value, sets the specified value at the allocated offset
  * and returns that offset.
  */
 public int floatParam(float value) {
   int offset = floatParam();
   buffer.putFloat(offset, value);
   return offset;
 }
コード例 #29
0
 public static byte[] floatToBytes(float x) {
   buffer.putFloat(0, x);
   return buffer.array();
 }
コード例 #30
0
 @Override
 public ByteBuffer write(ByteBuffer buff, Object obj) {
   if (!isArray(obj)) {
     return super.write(buff, obj);
   }
   Class<?> type = obj.getClass().getComponentType();
   Integer classId = getCommonClassId(type);
   if (classId != null) {
     if (type.isPrimitive()) {
       if (type == byte.class) {
         byte[] data = (byte[]) obj;
         int len = data.length;
         if (len <= 15) {
           buff.put((byte) (TAG_BYTE_ARRAY_0_15 + len));
         } else {
           buff.put((byte) TYPE_ARRAY);
           buff.put((byte) classId.intValue());
           DataUtils.writeVarInt(buff, len);
         }
         buff = DataUtils.ensureCapacity(buff, data.length);
         buff.put(data);
         return buff;
       }
       buff.put((byte) TYPE_ARRAY);
       buff.put((byte) classId.intValue());
       int len = Array.getLength(obj);
       DataUtils.writeVarInt(buff, len);
       buff = DataUtils.ensureCapacity(buff, 8 * len);
       for (int i = 0; i < len; i++) {
         if (type == boolean.class) {
           buff.put((byte) (((boolean[]) obj)[i] ? 1 : 0));
         } else if (type == char.class) {
           buff.putChar(((char[]) obj)[i]);
         } else if (type == short.class) {
           buff.putShort(((short[]) obj)[i]);
         } else if (type == int.class) {
           buff.putInt(((int[]) obj)[i]);
         } else if (type == float.class) {
           buff.putFloat(((float[]) obj)[i]);
         } else if (type == double.class) {
           buff.putDouble(((double[]) obj)[i]);
         } else {
           buff.putLong(((long[]) obj)[i]);
         }
       }
       return buff;
     }
     buff.put((byte) TYPE_ARRAY);
     buff.put((byte) classId.intValue());
   } else {
     buff.put((byte) TYPE_ARRAY);
     buff.put((byte) -1);
     String c = type.getName();
     buff = StringDataType.INSTANCE.write(buff, c);
   }
   Object[] array = (Object[]) obj;
   int len = array.length;
   DataUtils.writeVarInt(buff, len);
   for (Object x : array) {
     buff = elementType.write(buff, x);
   }
   return buff;
 }