@Override protected void writeLong(Encoder encoder, long val) throws IOException { encoder.writeLong(val); }
@Override public Encoder writeLong(long l) throws IOException { return encoder.writeLong(l); }
@Override public Encoder writeLong(long l) throws IOException { return encoder.writeLong(l); }
@Override protected void writeLong(Encoder encoder, long val) throws IOException { encoder.writeLong(val); }
/** * Encodes the given {@link StreamEvent} into {@code byte[]} that could become * payload of a QueueEntry. * * @param event The {@link StreamEvent} to encode. * @return Encoded {@code byte[]}. */ public byte[] encodePayload(StreamEvent event) { // TODO: This is a bit hacky to do it directly for now, for performance reason. ByteBuffer body = event.getBody(); Map<String, String> headers = event.getHeaders(); long timestamp = event.getTimestamp(); // Some assumption on the header size to minimize array copying // 16 bytes Schema hash + body size + (header size) * (50 bytes key/value pair) + 9 bytes timestamp (vlong encoding) ByteArrayOutputStream os = new ByteArrayOutputStream(16 + body.remaining() + headers.size() * 50 + 9); Encoder encoder = new BinaryEncoder(os); try { // Write the schema hash os.write(STREAM_EVENT_SCHEMA.getSchemaHash().toByteArray()); StreamEventDataCodec.encode(event, encoder); encoder.writeLong(timestamp); return os.toByteArray(); } catch (IOException e) { // It should never happens, otherwise something very wrong. throw Throwables.propagate(e); } }
break; case LONG: encoder.writeLong((Long) value); break; case FLOAT:
break; case LONG: encoder.writeLong((Long) value); break; case FLOAT:
Assert.assertEquals(Integer.MIN_VALUE, decoder.readInt()); encoder.writeLong(0); Assert.assertEquals(0, decoder.readLong()); encoder.writeLong(-20); Assert.assertEquals(-20, decoder.readLong()); encoder.writeLong(30000); Assert.assertEquals(30000, decoder.readLong()); encoder.writeLong(-600000); Assert.assertEquals(-600000, decoder.readLong()); encoder.writeLong(Integer.MAX_VALUE); Assert.assertEquals(Integer.MAX_VALUE, decoder.readLong()); encoder.writeLong(Integer.MIN_VALUE); Assert.assertEquals(Integer.MIN_VALUE, decoder.readLong()); encoder.writeLong(Long.MAX_VALUE); Assert.assertEquals(Long.MAX_VALUE, decoder.readLong()); encoder.writeLong(Long.MIN_VALUE); Assert.assertEquals(Long.MIN_VALUE, decoder.readLong());