/** * Reads a var int 32 from the internal byte buffer. */ public int readRawVarint32() throws IOException { return ByteBufUtils.readVarInt(byteBuf); }
/** * Reads a var int 64 from the internal byte buffer. */ public long readRawVarint64() throws IOException { return ByteBufUtils.readVarLong(byteBuf); }
public void writeRawInt32(int value) throws IOException { ByteBufUtils.writeVarInt(byteBuf, value); }
@Override public void writeInt64(int fieldNumber, long value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarLong(byteBuf, value); }
ByteBufUtils.writeVarLong(buffer, tracer.getSpanId()); ByteBufUtils.writeVarLong(buffer, tracer.getParentId()); ByteBufUtils.writeVarLong(buffer, tracer.getCs()); ByteBufUtils.writeVarLong(buffer, tracer.getCr()); ByteBufUtils.writeVarLong(buffer, tracer.getSs()); ByteBufUtils.writeVarLong(buffer, tracer.getSr());
@Override public void writeUInt64(int fieldNumber, long value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarLong(byteBuf, value); }
ByteBufUtils.writeVarLong(buffer, tracer.getSpanId()); ByteBufUtils.writeVarLong(buffer, tracer.getParentId()); ByteBufUtils.writeVarLong(buffer, tracer.getCs()); ByteBufUtils.writeVarLong(buffer, tracer.getCr()); ByteBufUtils.writeVarLong(buffer, tracer.getSs()); ByteBufUtils.writeVarLong(buffer, tracer.getSr());
@Override public void writeUInt32(int fieldNumber, int value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarInt(byteBuf, value); }
@Override public void writeSInt64(int fieldNumber, long value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarLong(byteBuf, encodeZigZag64(value)); }
public final Tracer read(ByteBuf buffer) { byte flag = buffer.readByte(); if (flag == 0) { return null; } Tracer tracer = new Tracer(); if ((flag & TRACE_ID_FLAG) == TRACE_ID_FLAG) { tracer.setTraceId(new ObjectId(buffer)); } if ((flag & SPAN_ID_FLAG) == SPAN_ID_FLAG) { tracer.setSpanId(ByteBufUtils.readVarLong(buffer)); } if ((flag & PARENT_ID_FLAG) == PARENT_ID_FLAG) { tracer.setParentId(ByteBufUtils.readVarLong(buffer)); } if ((flag & CS_FLAG) == CS_FLAG) { tracer.setCs(ByteBufUtils.readVarLong(buffer)); } if ((flag & CR_FLAG) == CR_FLAG) { tracer.setCr(ByteBufUtils.readVarLong(buffer)); } if ((flag & SS_FLAG) == SS_FLAG) { tracer.setSs(ByteBufUtils.readVarLong(buffer)); } if ((flag & SR_FLAG) == SR_FLAG) { tracer.setSr(ByteBufUtils.readVarLong(buffer)); } return tracer; }
public Request readRequest(ByteBuf byteBuf) throws IOException { int requestId = byteBuf.readInt(); int serviceId = ByteBufUtils.readVarInt(byteBuf); Tracer tracer = tracerSerializer.read(byteBuf); MethodParam methodParam = null; if (byteBuf.readBoolean()) { Class<?> clazz = getMethodParamClass(serviceId); methodParam = (MethodParam) kryoContext().readObject(byteBuf, clazz); } Request request = RecycleRequest.newInstance(requestId, serviceId, tracer, methodParam); return request; }
@Override public void writeInt32(int fieldNumber, int value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarInt(byteBuf, value); }
public final Tracer read(ByteBuf buffer) { byte flag = buffer.readByte(); if (flag == 0) { return null; } Tracer tracer = new Tracer(); if ((flag & TRACE_ID_FLAG) == TRACE_ID_FLAG) { tracer.setTraceId(new ObjectId(buffer)); } if ((flag & SPAN_ID_FLAG) == SPAN_ID_FLAG) { tracer.setSpanId(ByteBufUtils.readVarLong(buffer)); } if ((flag & PARENT_ID_FLAG) == PARENT_ID_FLAG) { tracer.setParentId(ByteBufUtils.readVarLong(buffer)); } if ((flag & CS_FLAG) == CS_FLAG) { tracer.setCs(ByteBufUtils.readVarLong(buffer)); } if ((flag & CR_FLAG) == CR_FLAG) { tracer.setCr(ByteBufUtils.readVarLong(buffer)); } if ((flag & SS_FLAG) == SS_FLAG) { tracer.setSs(ByteBufUtils.readVarLong(buffer)); } if ((flag & SR_FLAG) == SR_FLAG) { tracer.setSr(ByteBufUtils.readVarLong(buffer)); } return tracer; }
public Request readRequest(ByteBuf byteBuf) throws IOException { int requestId = byteBuf.readInt(); int serviceId = ByteBufUtils.readVarInt(byteBuf); Tracer tracer = TRACER_SERIALIZER.read(byteBuf); Schema<MethodParam> schema = schema(serviceId); MethodParam methodParam = null; if (EmptyMethodParam.class.equals(schema.typeClass())) { methodParam = EmptyMethodParam.empty(); } else { ByteBufInput input = getOrUpdate(INPUT_ATTACHMENT_INDEX, INPUT_SUPPLIER); input.setByteBuf(byteBuf, true); methodParam = schema.newMessage(); schema.mergeFrom(input, methodParam); } Request request = RecycleRequest.newInstance(requestId, serviceId, tracer, methodParam); return request; }
@Override public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED)); ByteBufUtils.writeVarInt(byteBuf, length); byteBuf.writeBytes(value, offset, length); }
public void writeBytes(int fieldNumber, ByteBuf value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED)); ByteBufUtils.writeVarInt(byteBuf, value.readableBytes()); byteBuf.writeBytes(value); }
@Override public void writeBool(int fieldNumber, boolean value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); byteBuf.writeByte(value ? (byte) 0x01 : 0x00); }
@Override public void writeSInt32(int fieldNumber, int value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_VARINT)); ByteBufUtils.writeVarInt(byteBuf, encodeZigZag32(value)); }
@Override public <T> void writeObject(final int fieldNumber, final T value, final Schema<T> schema, final boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_START_GROUP)); schema.writeTo(this, value); ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_END_GROUP)); }
@Override public void writeFloat(int fieldNumber, float value, boolean repeated) throws IOException { ByteBufUtils.writeVarInt(byteBuf, makeTag(fieldNumber, WIRETYPE_FIXED32)); byteBuf.writeLongLE(Float.floatToRawIntBits(value)); }