OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ((UnknownFieldSetLite) objects[i]).writeTo(output); | 169 ((UnknownFieldSetLite) objects[i]).writeTo(output); |
170 output.writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); | 170 output.writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); |
171 break; | 171 break; |
172 default: | 172 default: |
173 throw InvalidProtocolBufferException.invalidWireType(); | 173 throw InvalidProtocolBufferException.invalidWireType(); |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 /** | 178 /** |
| 179 * Serializes the set and writes it to {@code output} using {@code MessageSet}
wire format. |
| 180 * |
| 181 * <p>For use by generated code only. |
| 182 */ |
| 183 public void writeAsMessageSetTo(CodedOutputStream output) throws IOException { |
| 184 for (int i = 0; i < count; i++) { |
| 185 int fieldNumber = WireFormat.getTagFieldNumber(tags[i]); |
| 186 output.writeRawMessageSetExtension(fieldNumber, (ByteString) objects[i]); |
| 187 } |
| 188 } |
| 189 |
| 190 /** |
| 191 * Get the number of bytes required to encode this field, including field |
| 192 * number, using {@code MessageSet} wire format. |
| 193 */ |
| 194 public int getSerializedSizeAsMessageSet() { |
| 195 int size = memoizedSerializedSize; |
| 196 if (size != -1) { |
| 197 return size; |
| 198 } |
| 199 |
| 200 size = 0; |
| 201 for (int i = 0; i < count; i++) { |
| 202 int tag = tags[i]; |
| 203 int fieldNumber = WireFormat.getTagFieldNumber(tag); |
| 204 size += CodedOutputStream.computeRawMessageSetExtensionSize( |
| 205 fieldNumber, (ByteString) objects[i]); |
| 206 } |
| 207 |
| 208 memoizedSerializedSize = size; |
| 209 |
| 210 return size; |
| 211 } |
| 212 |
| 213 /** |
179 * Get the number of bytes required to encode this set. | 214 * Get the number of bytes required to encode this set. |
180 * | 215 * |
181 * <p>For use by generated code only. | 216 * <p>For use by generated code only. |
182 */ | 217 */ |
183 public int getSerializedSize() { | 218 public int getSerializedSize() { |
184 int size = memoizedSerializedSize; | 219 int size = memoizedSerializedSize; |
185 if (size != -1) { | 220 if (size != -1) { |
186 return size; | 221 return size; |
187 } | 222 } |
188 | 223 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 * @param buffer the buffer to write to | 296 * @param buffer the buffer to write to |
262 * @param indent the number of spaces the fields should be indented by | 297 * @param indent the number of spaces the fields should be indented by |
263 */ | 298 */ |
264 final void printWithIndent(StringBuilder buffer, int indent) { | 299 final void printWithIndent(StringBuilder buffer, int indent) { |
265 for (int i = 0; i < count; i++) { | 300 for (int i = 0; i < count; i++) { |
266 int fieldNumber = WireFormat.getTagFieldNumber(tags[i]); | 301 int fieldNumber = WireFormat.getTagFieldNumber(tags[i]); |
267 MessageLiteToString.printField(buffer, indent, String.valueOf(fieldNumber)
, objects[i]); | 302 MessageLiteToString.printField(buffer, indent, String.valueOf(fieldNumber)
, objects[i]); |
268 } | 303 } |
269 } | 304 } |
270 | 305 |
271 private void storeField(int tag, Object value) { | 306 // Package private for unsafe experimental runtime. |
| 307 void storeField(int tag, Object value) { |
272 ensureCapacity(); | 308 ensureCapacity(); |
273 | 309 |
274 tags[count] = tag; | 310 tags[count] = tag; |
275 objects[count] = value; | 311 objects[count] = value; |
276 count++; | 312 count++; |
277 } | 313 } |
278 | 314 |
279 /** | 315 /** |
280 * Ensures that our arrays are long enough to store more metadata. | 316 * Ensures that our arrays are long enough to store more metadata. |
281 */ | 317 */ |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // Ensures initialization in mergeFieldFrom. | 405 // Ensures initialization in mergeFieldFrom. |
370 while (true) { | 406 while (true) { |
371 final int tag = input.readTag(); | 407 final int tag = input.readTag(); |
372 if (tag == 0 || !mergeFieldFrom(tag, input)) { | 408 if (tag == 0 || !mergeFieldFrom(tag, input)) { |
373 break; | 409 break; |
374 } | 410 } |
375 } | 411 } |
376 return this; | 412 return this; |
377 } | 413 } |
378 } | 414 } |
OLD | NEW |