static void writeAnnotation(long timestamp, String value, @Nullable byte[] endpoint, Buffer b) { b.writeAscii("{\"timestamp\":").writeAscii(timestamp); b.writeAscii(",\"value\":\"").writeUtf8(jsonEscape(value)).writeByte('"'); if (endpoint != null) b.writeAscii(",\"endpoint\":").write(endpoint); b.writeByte('}'); } }
static void writeBinaryAnnotation(String key, String value, @Nullable byte[] endpoint, Buffer b) { b.writeAscii("{\"key\":\"").writeUtf8(jsonEscape(key)); b.writeAscii("\",\"value\":\"").writeUtf8(jsonEscape(value)).writeByte('"'); if (endpoint != null) b.writeAscii(",\"endpoint\":").write(endpoint); b.writeAscii("}"); } }
public Buffer writeAscii(long v) { if (v == 0) return writeByte('0'); if (v == Long.MIN_VALUE) return writeAscii("-9223372036854775808"); int width = asciiSizeInBytes(v); int pos = this.pos += width; // We write backwards from right to left. boolean negative = false; if (v < 0) { negative = true; v = -v; // needs to be positive so we can use this for an array index } while (v != 0) { int digit = (int) (v % 10); buf[--pos] = DIGITS[digit]; v /= 10; } if (negative) buf[--pos] = '-'; return this; }
static void writeEndpoint(Endpoint value, Buffer b, boolean writeEmptyServiceName) { b.writeByte('{'); boolean wroteField = false; String serviceName = value.serviceName(); if (serviceName == null && writeEmptyServiceName) serviceName = ""; if (serviceName != null) { b.writeAscii("\"serviceName\":\""); b.writeUtf8(jsonEscape(serviceName)).writeByte('"'); wroteField = true; } if (value.ipv4() != null) { if (wroteField) b.writeByte(','); b.writeAscii("\"ipv4\":\""); b.writeAscii(value.ipv4()).writeByte('"'); wroteField = true; } if (value.ipv6() != null) { if (wroteField) b.writeByte(','); b.writeAscii("\"ipv6\":\""); b.writeAscii(value.ipv6()).writeByte('"'); wroteField = true; } int port = value.portAsInt(); if (port != 0) { if (wroteField) b.writeByte(','); b.writeAscii("\"port\":").writeAscii(port); } b.writeByte('}'); }
@Override public void write(Span value, Buffer b) { b.writeAscii("{\"traceId\":\"").writeAscii(value.traceId()).writeByte('"'); if (value.parentId() != null) { b.writeAscii(",\"parentId\":\"").writeAscii(value.parentId()).writeByte('"'); b.writeAscii(",\"id\":\"").writeAscii(value.id()).writeByte('"'); if (value.kind() != null) { b.writeAscii(",\"kind\":\"").writeAscii(value.kind().toString()).writeByte('"'); b.writeAscii(",\"name\":\"").writeUtf8(jsonEscape(value.name())).writeByte('"'); b.writeAscii(",\"timestamp\":").writeAscii(value.timestampAsLong()); b.writeAscii(",\"duration\":").writeAscii(value.durationAsLong()); b.writeAscii(",\"localEndpoint\":"); writeEndpoint(value.localEndpoint(), b, false); b.writeAscii(",\"remoteEndpoint\":"); writeEndpoint(value.remoteEndpoint(), b, false); b.writeAscii(",\"annotations\":"); b.writeByte('['); for (int i = 0, length = value.annotations().size(); i < length; ) { b.writeAscii(",\"tags\":{"); Iterator<Map.Entry<String, String>> i = value.tags().entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, String> entry = i.next();
@Override public void write(V1Span value, Buffer b) { b.writeAscii("{\"traceId\":\""); if (value.traceIdHigh() != 0L) b.writeLongHex(value.traceIdHigh()); b.writeLongHex(value.traceId()).writeByte('"'); if (value.parentId() != 0L) { b.writeAscii(",\"parentId\":\"").writeLongHex(value.parentId()).writeByte('"'); b.writeAscii(",\"id\":\"").writeLongHex(value.id()).writeByte('"'); b.writeAscii(",\"name\":\""); if (value.name() != null) b.writeUtf8(jsonEscape(value.name())); b.writeByte('"'); b.writeAscii(",\"timestamp\":").writeAscii(value.timestamp()); b.writeAscii(",\"duration\":").writeAscii(value.duration()); byte[] lastEndpointBytes = null; if (annotationCount > 0) { b.writeAscii(",\"annotations\":["); for (int i = 0; i < annotationCount; ) { V1Annotation a = value.annotations().get(i++); b.writeAscii(",\"binaryAnnotations\":["); for (int i = 0; i < binaryAnnotationCount; ) { V1BinaryAnnotation a = value.binaryAnnotations().get(i++); writeBinaryAnnotation(a.key(), a.stringValue(), endpointBytes, b); } else { b.writeAscii("{\"key\":\"").writeAscii(a.key());