Skip to content

Commit ec1bf6e

Browse files
Update src/main/java/com/google/devtools/build/lib/query2/query/output/StreamedProtoOutputFormatter.java
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 5fc8b13 commit ec1bf6e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/main/java/com/google/devtools/build/lib/query2/query/output/StreamedProtoOutputFormatter.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,25 @@ private Build.Target toProto(Target target) {
113113
private static byte[] writeDelimited(Build.Target targetProtoBuffer) {
114114
try {
115115
var serializedSize = targetProtoBuffer.getSerializedSize();
116-
var headerSize = CodedOutputStream.computeUInt32SizeNoTag(serializedSize);
117-
var output = new byte[headerSize + serializedSize];
118-
var codedOut = CodedOutputStream.newInstance(output, headerSize, output.length - headerSize);
119-
targetProtoBuffer.writeTo(codedOut);
120-
codedOut.flush();
116+
- var headerSize = CodedOutputStream.computeUInt32SizeNoTag(serializedSize);
117+
- var output = new byte[headerSize + serializedSize];
118+
- var codedOut = CodedOutputStream.newInstance(output, headerSize, output.length - headerSize);
119+
- targetProtoBuffer.writeTo(codedOut);
120+
+ int headerSize = CodedOutputStream.computeUInt32SizeNoTag(serializedSize);
121+
+ byte[] output = new byte[headerSize + serializedSize];
122+
+
123+
+ // 1. write the var-int length prefix
124+
+ CodedOutputStream headerOut = CodedOutputStream.newInstance(output, 0, headerSize);
125+
+ headerOut.writeUInt32NoTag(serializedSize);
126+
+ headerOut.flush();
127+
+
128+
+ // 2. write the message bytes immediately after the prefix
129+
+ CodedOutputStream bodyOut =
130+
+ CodedOutputStream.newInstance(output, headerSize, serializedSize);
131+
+ targetProtoBuffer.writeTo(bodyOut);
132+
+ bodyOut.flush();
121133
return output;
134+
}
122135
} catch (IOException e) {
123136
throw new WrappedIOException(e);
124137
}

0 commit comments

Comments
 (0)