Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void append(StringBuilder sb, Value<?> value) {
appendMap(sb, (List<KeyValue>) value.getValue());
break;
case BYTES:
appendBytes(sb, (ByteBuffer) value.getValue());
appendBytes(sb, (Value<ByteBuffer>) value);
break;
case EMPTY:
sb.append("null");
Expand Down Expand Up @@ -97,9 +97,11 @@ private static void appendDouble(StringBuilder sb, double value) {
}
}

private static void appendBytes(StringBuilder sb, ByteBuffer value) {
byte[] bytes = new byte[value.remaining()];
value.get(bytes);
private static void appendBytes(StringBuilder sb, Value<ByteBuffer> value) {
ByteBuffer buf = value.getValue();
byte[] bytes = new byte[buf.remaining()];
// getValue() above returns a new ByteBuffer, so mutating its position here is safe
buf.get(bytes);
sb.append('"').append(Base64.getEncoder().encodeToString(bytes)).append('"');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static MarshalerWithSize create(Value<?> value) {
case KEY_VALUE_LIST:
return KeyValueListAnyValueMarshaler.create((List<KeyValue>) value.getValue());
case BYTES:
return BytesAnyValueMarshaler.create((ByteBuffer) value.getValue());
return BytesAnyValueMarshaler.create((Value<ByteBuffer>) value);
case EMPTY:
return EmptyAnyValueMarshaler.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void writeTo(Serializer output, Value<?> value, MarshalerContext context)
return;
case BYTES:
BytesAnyValueStatelessMarshaler.INSTANCE.writeTo(
output, (ByteBuffer) value.getValue(), context);
output, (Value<ByteBuffer>) value, context);
return;
case EMPTY:
// no field to write
Expand Down Expand Up @@ -104,7 +104,7 @@ public int getBinarySerializedSize(Value<?> value, MarshalerContext context) {
context);
case BYTES:
return BytesAnyValueStatelessMarshaler.INSTANCE.getBinarySerializedSize(
(ByteBuffer) value.getValue(), context);
(Value<ByteBuffer>) value, context);
case EMPTY:
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.exporter.internal.otlp;

import io.opentelemetry.api.common.Value;
import io.opentelemetry.exporter.internal.marshal.CodedOutputStream;
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import io.opentelemetry.exporter.internal.marshal.Serializer;
Expand All @@ -21,9 +22,11 @@ private BytesAnyValueMarshaler(byte[] value) {
this.value = value;
}

static MarshalerWithSize create(ByteBuffer value) {
byte[] bytes = new byte[value.remaining()];
value.get(bytes);
static MarshalerWithSize create(Value<ByteBuffer> value) {
ByteBuffer buf = value.getValue();
byte[] bytes = new byte[buf.remaining()];
// getValue() above returns a new ByteBuffer, so mutating its position here is safe
buf.get(bytes);
return new BytesAnyValueMarshaler(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.exporter.internal.otlp;

import io.opentelemetry.api.common.Value;
import io.opentelemetry.exporter.internal.marshal.CodedOutputStream;
import io.opentelemetry.exporter.internal.marshal.MarshalerContext;
import io.opentelemetry.exporter.internal.marshal.Serializer;
Expand All @@ -14,22 +15,24 @@
import java.nio.ByteBuffer;

/** See {@link BytesAnyValueMarshaler}. */
final class BytesAnyValueStatelessMarshaler implements StatelessMarshaler<ByteBuffer> {
final class BytesAnyValueStatelessMarshaler implements StatelessMarshaler<Value<ByteBuffer>> {
static final BytesAnyValueStatelessMarshaler INSTANCE = new BytesAnyValueStatelessMarshaler();

private BytesAnyValueStatelessMarshaler() {}

@Override
public void writeTo(Serializer output, ByteBuffer value, MarshalerContext context)
public void writeTo(Serializer output, Value<ByteBuffer> value, MarshalerContext context)
throws IOException {
byte[] bytes = context.getData(byte[].class);
output.writeBytes(AnyValue.BYTES_VALUE, bytes);
}

@Override
public int getBinarySerializedSize(ByteBuffer value, MarshalerContext context) {
byte[] bytes = new byte[value.remaining()];
value.get(bytes);
public int getBinarySerializedSize(Value<ByteBuffer> value, MarshalerContext context) {
ByteBuffer buf = value.getValue();
byte[] bytes = new byte[buf.remaining()];
// getValue() above returns a new ByteBuffer, so mutating its position here is safe
buf.get(bytes);
context.addData(bytes);
return AnyValue.BYTES_VALUE.getTagSize() + CodedOutputStream.computeByteArraySizeNoTag(bytes);
}
Expand Down
Loading