public ByteBuffer toBuffer(int headerPos) { byte[] topic = topic().getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Integer.BYTES /* partition */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putInt(_partition); buffer.putDouble(value()); return buffer; }
@Override public String toString() { return String.format("[%s,%s,time=%d,brokerId=%d,partition=%s,value=%.3f]", MetricClassId.PARTITION_METRIC, rawMetricType(), time(), brokerId(), new TopicPartition(topic(), partition()), value()); } }
public ByteBuffer toBuffer(int headerPos) { byte[] topic = topic().getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Integer.BYTES /* partition */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putInt(_partition); buffer.putDouble(value()); return buffer; }
@Override public String toString() { return String.format("[%s,%s,time=%d,brokerId=%d,partition=%s,value=%.3f]", MetricClassId.PARTITION_METRIC, rawMetricType(), time(), brokerId(), new TopicPartition(topic(), partition()), value()); } }