FloatCodec implements BlockCodec<Float> { @Override public byte[] encode(Float data, int bitLength) throws BlockCodecException { try { float value = data.floatValue(); return ByteBuffer.allocate(4).putFloat(value).array(); } catch (Exception ex) { throw new BlockCodecException("float encode failure. " + ex.getMessage(), ex); } }  @Override Float zeroValue(); @Override Float decode(byte[] data, int bitLength); @Override byte[] encode(Float data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testEncode() throws Exception { FloatCodec codec = new FloatCodec(); Assert.assertArrayEquals( new byte[] { (byte) 0x41, (byte) 0x44, (byte) 0xc4, (byte) 0x9c }, codec.encode(new Float(12.298f), 8)); }