List of usage examples for io.netty.buffer ByteBufUtil getBytes
public static byte[] getBytes(ByteBuf buf, int start, int length)
From source file:com.heliosapm.streams.metrics.StreamedMetric.java
License:Open Source License
/** * Returns a byte array containing the serialized streammetric * @return a byte array /*from ww w.jav a 2 s.co m*/ */ public byte[] toByteArray() { final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize); try { buff.writeByte(TYPE_CODE); writeByteArray(buff); return ByteBufUtil.getBytes(buff, 0, buff.readableBytes()); } finally { try { buff.release(); } catch (Exception x) { /* No Op */} } }
From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java
License:Apache License
/** * Returns a byte array containing the serialized streammetric * @return a byte array /*from w ww . j a v a2 s. c o m*/ */ @Override public byte[] toByteArray() { final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize); try { buff.writeByte(TYPE_CODE); writeByteArray(buff); if (isDoubleValue) { buff.writeByte(0); buff.writeDouble(doubleValue); } else { buff.writeByte(1); buff.writeLong(longValue); } return ByteBufUtil.getBytes(buff, 0, buff.readableBytes()); } finally { try { buff.release(); } catch (Exception x) { /* No Op */} } }