Skip to content

Commit 487c0cc

Browse files
committed
Fix MarshalerUtil sizeRepeatedString calculation per issue#8272
1 parent 74e4ad0 commit 487c0cc

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ private static int sizeRepeatedFixed64(ProtoFieldInfo field, int numValues) {
115115
public static int sizeRepeatedString(ProtoFieldInfo field, byte[][] utf8Bytes) {
116116
int size = 0;
117117
for (byte[] i : utf8Bytes) {
118-
int s = field.getTagSize() + CodedOutputStream.computeByteArraySizeNoTag(i);
119-
size += s;
118+
size += sizeBytes(field, i, /* skipEmpty= */ false);
120119
}
121120
return size;
122121
}
@@ -385,7 +384,12 @@ public static int sizeFixed32(ProtoFieldInfo field, int message) {
385384

386385
/** Returns the size of a bytes field. */
387386
public static int sizeBytes(ProtoFieldInfo field, byte[] message) {
388-
if (message.length == 0) {
387+
return sizeBytes(field, message, /* skipEmpty= */ true);
388+
}
389+
390+
/** Returns the size of a bytes field. */
391+
public static int sizeBytes(ProtoFieldInfo field, byte[] message, boolean skipEmpty) {
392+
if (message.length == 0 && skipEmpty) {
389393
return 0;
390394
}
391395
return field.getTagSize() + CodedOutputStream.computeByteArraySizeNoTag(message);

0 commit comments

Comments
 (0)