CodedOutputStream.java
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 package com.google.protobuf;
32 
33 import static com.google.protobuf.WireFormat.FIXED32_SIZE;
34 import static com.google.protobuf.WireFormat.FIXED64_SIZE;
35 import static com.google.protobuf.WireFormat.MAX_VARINT32_SIZE;
36 import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE;
37 import static java.lang.Math.max;
38 
40 import java.io.IOException;
41 import java.io.OutputStream;
42 import java.nio.BufferOverflowException;
43 import java.nio.ByteBuffer;
44 import java.nio.ByteOrder;
45 import java.util.logging.Level;
46 import java.util.logging.Logger;
47 
59 public abstract class CodedOutputStream extends ByteOutput {
60  private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName());
61  private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations();
62 
64  CodedOutputStreamWriter wrapper;
65 
67  @Deprecated public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE;
68 
70  public static final int DEFAULT_BUFFER_SIZE = 4096;
71 
78  static int computePreferredBufferSize(int dataLength) {
79  if (dataLength > DEFAULT_BUFFER_SIZE) {
80  return DEFAULT_BUFFER_SIZE;
81  }
82  return dataLength;
83  }
84 
92  public static CodedOutputStream newInstance(final OutputStream output) {
94  }
95 
104  public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) {
105  return new OutputStreamEncoder(output, bufferSize);
106  }
107 
114  public static CodedOutputStream newInstance(final byte[] flatArray) {
115  return newInstance(flatArray, 0, flatArray.length);
116  }
117 
125  final byte[] flatArray, final int offset, final int length) {
126  return new ArrayEncoder(flatArray, offset, length);
127  }
128 
130  public static CodedOutputStream newInstance(ByteBuffer buffer) {
131  if (buffer.hasArray()) {
132  return new HeapNioEncoder(buffer);
133  }
134  if (buffer.isDirect() && !buffer.isReadOnly()) {
135  return UnsafeDirectNioEncoder.isSupported()
136  ? newUnsafeInstance(buffer)
137  : newSafeInstance(buffer);
138  }
139  throw new IllegalArgumentException("ByteBuffer is read-only");
140  }
141 
143  static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) {
144  return new UnsafeDirectNioEncoder(buffer);
145  }
146 
148  static CodedOutputStream newSafeInstance(ByteBuffer buffer) {
149  return new SafeDirectNioEncoder(buffer);
150  }
151 
183  }
184 
185  boolean isSerializationDeterministic() {
187  }
188 
189  private boolean serializationDeterministic;
190 
198  @Deprecated
200  ByteBuffer byteBuffer, @SuppressWarnings("unused") int unused) {
201  return newInstance(byteBuffer);
202  }
203 
215  static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) {
216  if (bufferSize < 0) {
217  throw new IllegalArgumentException("bufferSize must be positive");
218  }
219 
220  return new ByteOutputEncoder(byteOutput, bufferSize);
221  }
222 
223  // Disallow construction outside of this class.
224  private CodedOutputStream() {}
225 
226  // -----------------------------------------------------------------
227 
229  // Abstract to avoid overhead of additional virtual method calls.
230  public abstract void writeTag(int fieldNumber, int wireType) throws IOException;
231 
233  // Abstract to avoid overhead of additional virtual method calls.
234  public abstract void writeInt32(int fieldNumber, int value) throws IOException;
235 
237  // Abstract to avoid overhead of additional virtual method calls.
238  public abstract void writeUInt32(int fieldNumber, int value) throws IOException;
239 
241  public final void writeSInt32(final int fieldNumber, final int value) throws IOException {
242  writeUInt32(fieldNumber, encodeZigZag32(value));
243  }
244 
246  // Abstract to avoid overhead of additional virtual method calls.
247  public abstract void writeFixed32(int fieldNumber, int value) throws IOException;
248 
250  public final void writeSFixed32(final int fieldNumber, final int value) throws IOException {
251  writeFixed32(fieldNumber, value);
252  }
253 
255  public final void writeInt64(final int fieldNumber, final long value) throws IOException {
256  writeUInt64(fieldNumber, value);
257  }
258 
260  // Abstract to avoid overhead of additional virtual method calls.
261  public abstract void writeUInt64(int fieldNumber, long value) throws IOException;
262 
264  public final void writeSInt64(final int fieldNumber, final long value) throws IOException {
265  writeUInt64(fieldNumber, encodeZigZag64(value));
266  }
267 
269  // Abstract to avoid overhead of additional virtual method calls.
270  public abstract void writeFixed64(int fieldNumber, long value) throws IOException;
271 
273  public final void writeSFixed64(final int fieldNumber, final long value) throws IOException {
274  writeFixed64(fieldNumber, value);
275  }
276 
278  public final void writeFloat(final int fieldNumber, final float value) throws IOException {
279  writeFixed32(fieldNumber, Float.floatToRawIntBits(value));
280  }
281 
283  public final void writeDouble(final int fieldNumber, final double value) throws IOException {
284  writeFixed64(fieldNumber, Double.doubleToRawLongBits(value));
285  }
286 
288  // Abstract to avoid overhead of additional virtual method calls.
289  public abstract void writeBool(int fieldNumber, boolean value) throws IOException;
290 
295  public final void writeEnum(final int fieldNumber, final int value) throws IOException {
296  writeInt32(fieldNumber, value);
297  }
298 
300  // Abstract to avoid overhead of additional virtual method calls.
301  public abstract void writeString(int fieldNumber, String value) throws IOException;
302 
304  // Abstract to avoid overhead of additional virtual method calls.
305  public abstract void writeBytes(int fieldNumber, ByteString value) throws IOException;
306 
308  // Abstract to avoid overhead of additional virtual method calls.
309  public abstract void writeByteArray(int fieldNumber, byte[] value) throws IOException;
310 
312  // Abstract to avoid overhead of additional virtual method calls.
313  public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length)
314  throws IOException;
315 
324  // Abstract to avoid overhead of additional virtual method calls.
325  public abstract void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException;
326 
328  public final void writeRawByte(final byte value) throws IOException {
329  write(value);
330  }
331 
333  public final void writeRawByte(final int value) throws IOException {
334  write((byte) value);
335  }
336 
338  public final void writeRawBytes(final byte[] value) throws IOException {
339  write(value, 0, value.length);
340  }
341 
343  public final void writeRawBytes(final byte[] value, int offset, int length) throws IOException {
345  }
346 
348  public final void writeRawBytes(final ByteString value) throws IOException {
349  value.writeTo(this);
350  }
351 
359  // Abstract to avoid overhead of additional virtual method calls.
360  public abstract void writeRawBytes(final ByteBuffer value) throws IOException;
361 
363  // Abstract to avoid overhead of additional virtual method calls.
364  public abstract void writeMessage(final int fieldNumber, final MessageLite value)
365  throws IOException;
366 
368  // Abstract to avoid overhead of additional virtual method calls.
369  abstract void writeMessage(final int fieldNumber, final MessageLite value, Schema schema)
370  throws IOException;
371 
376  // Abstract to avoid overhead of additional virtual method calls.
377  public abstract void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
378  throws IOException;
379 
384  // Abstract to avoid overhead of additional virtual method calls.
385  public abstract void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
386  throws IOException;
387 
388  // -----------------------------------------------------------------
389 
391  // Abstract to avoid overhead of additional virtual method calls.
392  public abstract void writeInt32NoTag(final int value) throws IOException;
393 
395  // Abstract to avoid overhead of additional virtual method calls.
396  public abstract void writeUInt32NoTag(int value) throws IOException;
397 
399  public final void writeSInt32NoTag(final int value) throws IOException {
401  }
402 
404  // Abstract to avoid overhead of additional virtual method calls.
405  public abstract void writeFixed32NoTag(int value) throws IOException;
406 
408  public final void writeSFixed32NoTag(final int value) throws IOException {
410  }
411 
413  public final void writeInt64NoTag(final long value) throws IOException {
415  }
416 
418  // Abstract to avoid overhead of additional virtual method calls.
419  public abstract void writeUInt64NoTag(long value) throws IOException;
420 
422  public final void writeSInt64NoTag(final long value) throws IOException {
424  }
425 
427  // Abstract to avoid overhead of additional virtual method calls.
428  public abstract void writeFixed64NoTag(long value) throws IOException;
429 
431  public final void writeSFixed64NoTag(final long value) throws IOException {
433  }
434 
436  public final void writeFloatNoTag(final float value) throws IOException {
437  writeFixed32NoTag(Float.floatToRawIntBits(value));
438  }
439 
441  public final void writeDoubleNoTag(final double value) throws IOException {
442  writeFixed64NoTag(Double.doubleToRawLongBits(value));
443  }
444 
446  public final void writeBoolNoTag(final boolean value) throws IOException {
447  write((byte) (value ? 1 : 0));
448  }
449 
454  public final void writeEnumNoTag(final int value) throws IOException {
456  }
457 
459  // TODO(dweis): Document behavior on ill-formed UTF-16 input.
460  // Abstract to avoid overhead of additional virtual method calls.
461  public abstract void writeStringNoTag(String value) throws IOException;
462 
464  // Abstract to avoid overhead of additional virtual method calls.
465  public abstract void writeBytesNoTag(final ByteString value) throws IOException;
466 
468  public final void writeByteArrayNoTag(final byte[] value) throws IOException {
469  writeByteArrayNoTag(value, 0, value.length);
470  }
471 
473  // Abstract to avoid overhead of additional virtual method calls.
474  public abstract void writeMessageNoTag(final MessageLite value) throws IOException;
475 
477  // Abstract to avoid overhead of additional virtual method calls.
478  abstract void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException;
479 
480  // =================================================================
481 
483  @Override
484  public abstract void write(byte value) throws IOException;
485 
487  @Override
488  public abstract void write(byte[] value, int offset, int length) throws IOException;
489 
491  @Override
492  public abstract void writeLazy(byte[] value, int offset, int length) throws IOException;
493 
494  @Override
495  public abstract void write(ByteBuffer value) throws IOException;
496 
498  @Override
499  public abstract void writeLazy(ByteBuffer value) throws IOException;
500 
501  // =================================================================
502  // =================================================================
503 
508  public static int computeInt32Size(final int fieldNumber, final int value) {
509  return computeTagSize(fieldNumber) + computeInt32SizeNoTag(value);
510  }
511 
516  public static int computeUInt32Size(final int fieldNumber, final int value) {
517  return computeTagSize(fieldNumber) + computeUInt32SizeNoTag(value);
518  }
519 
524  public static int computeSInt32Size(final int fieldNumber, final int value) {
525  return computeTagSize(fieldNumber) + computeSInt32SizeNoTag(value);
526  }
527 
532  public static int computeFixed32Size(final int fieldNumber, final int value) {
533  return computeTagSize(fieldNumber) + computeFixed32SizeNoTag(value);
534  }
535 
540  public static int computeSFixed32Size(final int fieldNumber, final int value) {
541  return computeTagSize(fieldNumber) + computeSFixed32SizeNoTag(value);
542  }
543 
548  public static int computeInt64Size(final int fieldNumber, final long value) {
549  return computeTagSize(fieldNumber) + computeInt64SizeNoTag(value);
550  }
551 
556  public static int computeUInt64Size(final int fieldNumber, final long value) {
557  return computeTagSize(fieldNumber) + computeUInt64SizeNoTag(value);
558  }
559 
564  public static int computeSInt64Size(final int fieldNumber, final long value) {
565  return computeTagSize(fieldNumber) + computeSInt64SizeNoTag(value);
566  }
567 
572  public static int computeFixed64Size(final int fieldNumber, final long value) {
573  return computeTagSize(fieldNumber) + computeFixed64SizeNoTag(value);
574  }
575 
580  public static int computeSFixed64Size(final int fieldNumber, final long value) {
581  return computeTagSize(fieldNumber) + computeSFixed64SizeNoTag(value);
582  }
583 
588  public static int computeFloatSize(final int fieldNumber, final float value) {
589  return computeTagSize(fieldNumber) + computeFloatSizeNoTag(value);
590  }
591 
596  public static int computeDoubleSize(final int fieldNumber, final double value) {
597  return computeTagSize(fieldNumber) + computeDoubleSizeNoTag(value);
598  }
599 
603  public static int computeBoolSize(final int fieldNumber, final boolean value) {
604  return computeTagSize(fieldNumber) + computeBoolSizeNoTag(value);
605  }
606 
612  public static int computeEnumSize(final int fieldNumber, final int value) {
613  return computeTagSize(fieldNumber) + computeEnumSizeNoTag(value);
614  }
615 
620  public static int computeStringSize(final int fieldNumber, final String value) {
621  return computeTagSize(fieldNumber) + computeStringSizeNoTag(value);
622  }
623 
628  public static int computeBytesSize(final int fieldNumber, final ByteString value) {
629  return computeTagSize(fieldNumber) + computeBytesSizeNoTag(value);
630  }
631 
636  public static int computeByteArraySize(final int fieldNumber, final byte[] value) {
637  return computeTagSize(fieldNumber) + computeByteArraySizeNoTag(value);
638  }
639 
644  public static int computeByteBufferSize(final int fieldNumber, final ByteBuffer value) {
645  return computeTagSize(fieldNumber) + computeByteBufferSizeNoTag(value);
646  }
647 
652  public static int computeLazyFieldSize(final int fieldNumber, final LazyFieldLite value) {
653  return computeTagSize(fieldNumber) + computeLazyFieldSizeNoTag(value);
654  }
655 
660  public static int computeMessageSize(final int fieldNumber, final MessageLite value) {
661  return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value);
662  }
663 
668  static int computeMessageSize(
669  final int fieldNumber, final MessageLite value, final Schema schema) {
670  return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value, schema);
671  }
672 
677  public static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value) {
678  return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
679  + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
680  + computeMessageSize(WireFormat.MESSAGE_SET_MESSAGE, value);
681  }
682 
688  final int fieldNumber, final ByteString value) {
689  return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
690  + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
691  + computeBytesSize(WireFormat.MESSAGE_SET_MESSAGE, value);
692  }
693 
700  final int fieldNumber, final LazyFieldLite value) {
701  return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
702  + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
703  + computeLazyFieldSize(WireFormat.MESSAGE_SET_MESSAGE, value);
704  }
705 
706  // -----------------------------------------------------------------
707 
709  public static int computeTagSize(final int fieldNumber) {
710  return computeUInt32SizeNoTag(WireFormat.makeTag(fieldNumber, 0));
711  }
712 
717  public static int computeInt32SizeNoTag(final int value) {
718  if (value >= 0) {
720  } else {
721  // Must sign-extend.
722  return MAX_VARINT_SIZE;
723  }
724  }
725 
727  public static int computeUInt32SizeNoTag(final int value) {
728  if ((value & (~0 << 7)) == 0) {
729  return 1;
730  }
731  if ((value & (~0 << 14)) == 0) {
732  return 2;
733  }
734  if ((value & (~0 << 21)) == 0) {
735  return 3;
736  }
737  if ((value & (~0 << 28)) == 0) {
738  return 4;
739  }
740  return 5;
741  }
742 
744  public static int computeSInt32SizeNoTag(final int value) {
746  }
747 
749  public static int computeFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
750  return FIXED32_SIZE;
751  }
752 
754  public static int computeSFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
755  return FIXED32_SIZE;
756  }
757 
762  public static int computeInt64SizeNoTag(final long value) {
764  }
765 
770  public static int computeUInt64SizeNoTag(long value) {
771  // handle two popular special cases up front ...
772  if ((value & (~0L << 7)) == 0L) {
773  return 1;
774  }
775  if (value < 0L) {
776  return 10;
777  }
778  // ... leaving us with 8 remaining, which we can divide and conquer
779  int n = 2;
780  if ((value & (~0L << 35)) != 0L) {
781  n += 4;
782  value >>>= 28;
783  }
784  if ((value & (~0L << 21)) != 0L) {
785  n += 2;
786  value >>>= 14;
787  }
788  if ((value & (~0L << 14)) != 0L) {
789  n += 1;
790  }
791  return n;
792  }
793 
795  public static int computeSInt64SizeNoTag(final long value) {
797  }
798 
800  public static int computeFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
801  return FIXED64_SIZE;
802  }
803 
805  public static int computeSFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
806  return FIXED64_SIZE;
807  }
808 
813  public static int computeFloatSizeNoTag(@SuppressWarnings("unused") final float unused) {
814  return FIXED32_SIZE;
815  }
816 
821  public static int computeDoubleSizeNoTag(@SuppressWarnings("unused") final double unused) {
822  return FIXED64_SIZE;
823  }
824 
826  public static int computeBoolSizeNoTag(@SuppressWarnings("unused") final boolean unused) {
827  return 1;
828  }
829 
834  public static int computeEnumSizeNoTag(final int value) {
836  }
837 
839  public static int computeStringSizeNoTag(final String value) {
840  int length;
841  try {
842  length = Utf8.encodedLength(value);
843  } catch (UnpairedSurrogateException e) {
844  // TODO(dweis): Consider using nio Charset methods instead.
845  final byte[] bytes = value.getBytes(Internal.UTF_8);
846  length = bytes.length;
847  }
848 
849  return computeLengthDelimitedFieldSize(length);
850  }
851 
856  public static int computeLazyFieldSizeNoTag(final LazyFieldLite value) {
857  return computeLengthDelimitedFieldSize(value.getSerializedSize());
858  }
859 
861  public static int computeBytesSizeNoTag(final ByteString value) {
862  return computeLengthDelimitedFieldSize(value.size());
863  }
864 
866  public static int computeByteArraySizeNoTag(final byte[] value) {
867  return computeLengthDelimitedFieldSize(value.length);
868  }
869 
871  public static int computeByteBufferSizeNoTag(final ByteBuffer value) {
872  return computeLengthDelimitedFieldSize(value.capacity());
873  }
874 
876  public static int computeMessageSizeNoTag(final MessageLite value) {
877  return computeLengthDelimitedFieldSize(value.getSerializedSize());
878  }
879 
881  static int computeMessageSizeNoTag(final MessageLite value, final Schema schema) {
882  return computeLengthDelimitedFieldSize(((AbstractMessageLite) value).getSerializedSize(schema));
883  }
884 
885  static int computeLengthDelimitedFieldSize(int fieldLength) {
886  return computeUInt32SizeNoTag(fieldLength) + fieldLength;
887  }
888 
898  public static int encodeZigZag32(final int n) {
899  // Note: the right-shift must be arithmetic
900  return (n << 1) ^ (n >> 31);
901  }
902 
912  public static long encodeZigZag64(final long n) {
913  // Note: the right-shift must be arithmetic
914  return (n << 1) ^ (n >> 63);
915  }
916 
917  // =================================================================
918 
923  public abstract void flush() throws IOException;
924 
929  public abstract int spaceLeft();
930 
937  public final void checkNoSpaceLeft() {
938  if (spaceLeft() != 0) {
939  throw new IllegalStateException("Did not write as much data as expected.");
940  }
941  }
942 
947  public static class OutOfSpaceException extends IOException {
948  private static final long serialVersionUID = -6947486886997889499L;
949 
950  private static final String MESSAGE =
951  "CodedOutputStream was writing to a flat byte array and ran out of space.";
952 
954  super(MESSAGE);
955  }
956 
957  OutOfSpaceException(String explanationMessage) {
958  super(MESSAGE + ": " + explanationMessage);
959  }
960 
961  OutOfSpaceException(Throwable cause) {
962  super(MESSAGE, cause);
963  }
964 
965  OutOfSpaceException(String explanationMessage, Throwable cause) {
966  super(MESSAGE + ": " + explanationMessage, cause);
967  }
968  }
969 
974  public abstract int getTotalBytesWritten();
975 
976  // =================================================================
977 
979  abstract void writeByteArrayNoTag(final byte[] value, final int offset, final int length)
980  throws IOException;
981 
982  final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException cause)
983  throws IOException {
984  logger.log(
985  Level.WARNING,
986  "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!",
987  cause);
988 
989  // Unfortunately there does not appear to be any way to tell Java to encode
990  // UTF-8 directly into our buffer, so we have to let it create its own byte
991  // array and then copy.
992  // TODO(dweis): Consider using nio Charset methods instead.
993  final byte[] bytes = value.getBytes(Internal.UTF_8);
994  try {
995  writeUInt32NoTag(bytes.length);
996  writeLazy(bytes, 0, bytes.length);
997  } catch (IndexOutOfBoundsException e) {
998  throw new OutOfSpaceException(e);
999  } catch (OutOfSpaceException e) {
1000  throw e;
1001  }
1002  }
1003 
1004  // =================================================================
1005 
1011  @Deprecated
1012  public final void writeGroup(final int fieldNumber, final MessageLite value) throws IOException {
1015  writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP);
1016  }
1017 
1023  @Deprecated
1024  final void writeGroup(final int fieldNumber, final MessageLite value, Schema schema)
1025  throws IOException {
1027  writeGroupNoTag(value, schema);
1028  writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP);
1029  }
1030 
1036  @Deprecated
1037  public final void writeGroupNoTag(final MessageLite value) throws IOException {
1038  value.writeTo(this);
1039  }
1040 
1046  @Deprecated
1047  final void writeGroupNoTag(final MessageLite value, Schema schema) throws IOException {
1048  schema.writeTo(value, wrapper);
1049  }
1050 
1057  @Deprecated
1058  public static int computeGroupSize(final int fieldNumber, final MessageLite value) {
1059  return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value);
1060  }
1061 
1068  @Deprecated
1069  static int computeGroupSize(final int fieldNumber, final MessageLite value, Schema schema) {
1070  return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value, schema);
1071  }
1072 
1074  @Deprecated
1075  public static int computeGroupSizeNoTag(final MessageLite value) {
1076  return value.getSerializedSize();
1077  }
1078 
1080  @Deprecated
1081  static int computeGroupSizeNoTag(final MessageLite value, Schema schema) {
1082  return ((AbstractMessageLite) value).getSerializedSize(schema);
1083  }
1084 
1091  @Deprecated
1092  public final void writeRawVarint32(int value) throws IOException {
1094  }
1095 
1101  @Deprecated
1102  public final void writeRawVarint64(long value) throws IOException {
1104  }
1105 
1112  @Deprecated
1113  public static int computeRawVarint32Size(final int value) {
1114  return computeUInt32SizeNoTag(value);
1115  }
1116 
1122  @Deprecated
1123  public static int computeRawVarint64Size(long value) {
1124  return computeUInt64SizeNoTag(value);
1125  }
1126 
1132  @Deprecated
1133  public final void writeRawLittleEndian32(final int value) throws IOException {
1135  }
1136 
1142  @Deprecated
1143  public final void writeRawLittleEndian64(final long value) throws IOException {
1145  }
1146 
1147  // =================================================================
1148 
1150  private static class ArrayEncoder extends CodedOutputStream {
1151  private final byte[] buffer;
1152  private final int offset;
1153  private final int limit;
1154  private int position;
1155 
1156  ArrayEncoder(byte[] buffer, int offset, int length) {
1157  if (buffer == null) {
1158  throw new NullPointerException("buffer");
1159  }
1160  if ((offset | length | (buffer.length - (offset + length))) < 0) {
1161  throw new IllegalArgumentException(
1162  String.format(
1163  "Array range is invalid. Buffer.length=%d, offset=%d, length=%d",
1164  buffer.length, offset, length));
1165  }
1166  this.buffer = buffer;
1167  this.offset = offset;
1168  position = offset;
1169  limit = offset + length;
1170  }
1171 
1172  @Override
1173  public final void writeTag(final int fieldNumber, final int wireType) throws IOException {
1174  writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
1175  }
1176 
1177  @Override
1178  public final void writeInt32(final int fieldNumber, final int value) throws IOException {
1179  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1181  }
1182 
1183  @Override
1184  public final void writeUInt32(final int fieldNumber, final int value) throws IOException {
1185  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1187  }
1188 
1189  @Override
1190  public final void writeFixed32(final int fieldNumber, final int value) throws IOException {
1191  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
1193  }
1194 
1195  @Override
1196  public final void writeUInt64(final int fieldNumber, final long value) throws IOException {
1197  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1199  }
1200 
1201  @Override
1202  public final void writeFixed64(final int fieldNumber, final long value) throws IOException {
1203  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
1205  }
1206 
1207  @Override
1208  public final void writeBool(final int fieldNumber, final boolean value) throws IOException {
1209  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1210  write((byte) (value ? 1 : 0));
1211  }
1212 
1213  @Override
1214  public final void writeString(final int fieldNumber, final String value) throws IOException {
1217  }
1218 
1219  @Override
1220  public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
1223  }
1224 
1225  @Override
1226  public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
1227  writeByteArray(fieldNumber, value, 0, value.length);
1228  }
1229 
1230  @Override
1231  public final void writeByteArray(
1232  final int fieldNumber, final byte[] value, final int offset, final int length)
1233  throws IOException {
1236  }
1237 
1238  @Override
1239  public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
1240  throws IOException {
1242  writeUInt32NoTag(value.capacity());
1244  }
1245 
1246  @Override
1247  public final void writeBytesNoTag(final ByteString value) throws IOException {
1248  writeUInt32NoTag(value.size());
1249  value.writeTo(this);
1250  }
1251 
1252  @Override
1253  public final void writeByteArrayNoTag(final byte[] value, int offset, int length)
1254  throws IOException {
1256  write(value, offset, length);
1257  }
1258 
1259  @Override
1260  public final void writeRawBytes(final ByteBuffer value) throws IOException {
1261  if (value.hasArray()) {
1262  write(value.array(), value.arrayOffset(), value.capacity());
1263  } else {
1264  ByteBuffer duplicated = value.duplicate();
1265  duplicated.clear();
1266  write(duplicated);
1267  }
1268  }
1269 
1270  @Override
1271  public final void writeMessage(final int fieldNumber, final MessageLite value)
1272  throws IOException {
1275  }
1276 
1277  @Override
1278  final void writeMessage(final int fieldNumber, final MessageLite value, Schema schema)
1279  throws IOException {
1281  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
1282  schema.writeTo(value, wrapper);
1283  }
1284 
1285  @Override
1286  public final void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
1287  throws IOException {
1289  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1290  writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value);
1291  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1292  }
1293 
1294  @Override
1295  public final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
1296  throws IOException {
1298  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1299  writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value);
1300  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1301  }
1302 
1303  @Override
1304  public final void writeMessageNoTag(final MessageLite value) throws IOException {
1305  writeUInt32NoTag(value.getSerializedSize());
1306  value.writeTo(this);
1307  }
1308 
1309  @Override
1310  final void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException {
1311  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
1312  schema.writeTo(value, wrapper);
1313  }
1314 
1315  @Override
1316  public final void write(byte value) throws IOException {
1317  try {
1318  buffer[position++] = value;
1319  } catch (IndexOutOfBoundsException e) {
1320  throw new OutOfSpaceException(
1321  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
1322  }
1323  }
1324 
1325  @Override
1326  public final void writeInt32NoTag(int value) throws IOException {
1327  if (value >= 0) {
1329  } else {
1330  // Must sign-extend.
1332  }
1333  }
1334 
1335  @Override
1336  public final void writeUInt32NoTag(int value) throws IOException {
1338  && !Android.isOnAndroidDevice()
1339  && spaceLeft() >= MAX_VARINT32_SIZE) {
1340  if ((value & ~0x7F) == 0) {
1341  UnsafeUtil.putByte(buffer, position++, (byte) value);
1342  return;
1343  }
1344  UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
1345  value >>>= 7;
1346  if ((value & ~0x7F) == 0) {
1347  UnsafeUtil.putByte(buffer, position++, (byte) value);
1348  return;
1349  }
1350  UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
1351  value >>>= 7;
1352  if ((value & ~0x7F) == 0) {
1353  UnsafeUtil.putByte(buffer, position++, (byte) value);
1354  return;
1355  }
1356  UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
1357  value >>>= 7;
1358  if ((value & ~0x7F) == 0) {
1359  UnsafeUtil.putByte(buffer, position++, (byte) value);
1360  return;
1361  }
1362  UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
1363  value >>>= 7;
1364  UnsafeUtil.putByte(buffer, position++, (byte) value);
1365  } else {
1366  try {
1367  while (true) {
1368  if ((value & ~0x7F) == 0) {
1369  buffer[position++] = (byte) value;
1370  return;
1371  } else {
1372  buffer[position++] = (byte) ((value & 0x7F) | 0x80);
1373  value >>>= 7;
1374  }
1375  }
1376  } catch (IndexOutOfBoundsException e) {
1377  throw new OutOfSpaceException(
1378  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
1379  }
1380  }
1381  }
1382 
1383  @Override
1384  public final void writeFixed32NoTag(int value) throws IOException {
1385  try {
1386  buffer[position++] = (byte) (value & 0xFF);
1387  buffer[position++] = (byte) ((value >> 8) & 0xFF);
1388  buffer[position++] = (byte) ((value >> 16) & 0xFF);
1389  buffer[position++] = (byte) ((value >> 24) & 0xFF);
1390  } catch (IndexOutOfBoundsException e) {
1391  throw new OutOfSpaceException(
1392  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
1393  }
1394  }
1395 
1396  @Override
1397  public final void writeUInt64NoTag(long value) throws IOException {
1398  if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) {
1399  while (true) {
1400  if ((value & ~0x7FL) == 0) {
1401  UnsafeUtil.putByte(buffer, position++, (byte) value);
1402  return;
1403  } else {
1404  UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
1405  value >>>= 7;
1406  }
1407  }
1408  } else {
1409  try {
1410  while (true) {
1411  if ((value & ~0x7FL) == 0) {
1412  buffer[position++] = (byte) value;
1413  return;
1414  } else {
1415  buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
1416  value >>>= 7;
1417  }
1418  }
1419  } catch (IndexOutOfBoundsException e) {
1420  throw new OutOfSpaceException(
1421  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
1422  }
1423  }
1424  }
1425 
1426  @Override
1427  public final void writeFixed64NoTag(long value) throws IOException {
1428  try {
1429  buffer[position++] = (byte) ((int) (value) & 0xFF);
1430  buffer[position++] = (byte) ((int) (value >> 8) & 0xFF);
1431  buffer[position++] = (byte) ((int) (value >> 16) & 0xFF);
1432  buffer[position++] = (byte) ((int) (value >> 24) & 0xFF);
1433  buffer[position++] = (byte) ((int) (value >> 32) & 0xFF);
1434  buffer[position++] = (byte) ((int) (value >> 40) & 0xFF);
1435  buffer[position++] = (byte) ((int) (value >> 48) & 0xFF);
1436  buffer[position++] = (byte) ((int) (value >> 56) & 0xFF);
1437  } catch (IndexOutOfBoundsException e) {
1438  throw new OutOfSpaceException(
1439  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
1440  }
1441  }
1442 
1443  @Override
1444  public final void write(byte[] value, int offset, int length) throws IOException {
1445  try {
1446  System.arraycopy(value, offset, buffer, position, length);
1447  position += length;
1448  } catch (IndexOutOfBoundsException e) {
1449  throw new OutOfSpaceException(
1450  String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e);
1451  }
1452  }
1453 
1454  @Override
1455  public final void writeLazy(byte[] value, int offset, int length) throws IOException {
1456  write(value, offset, length);
1457  }
1458 
1459  @Override
1460  public final void write(ByteBuffer value) throws IOException {
1461  final int length = value.remaining();
1462  try {
1463  value.get(buffer, position, length);
1464  position += length;
1465  } catch (IndexOutOfBoundsException e) {
1466  throw new OutOfSpaceException(
1467  String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e);
1468  }
1469  }
1470 
1471  @Override
1472  public final void writeLazy(ByteBuffer value) throws IOException {
1473  write(value);
1474  }
1475 
1476  @Override
1477  public final void writeStringNoTag(String value) throws IOException {
1478  final int oldPosition = position;
1479  try {
1480  // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()),
1481  // and at most 3 times of it. We take advantage of this in both branches below.
1482  final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
1483  final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
1484  final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
1485  if (minLengthVarIntSize == maxLengthVarIntSize) {
1486  position = oldPosition + minLengthVarIntSize;
1487  int newPosition = Utf8.encode(value, buffer, position, spaceLeft());
1488  // Since this class is stateful and tracks the position, we rewind and store the state,
1489  // prepend the length, then reset it back to the end of the string.
1490  position = oldPosition;
1491  int length = newPosition - oldPosition - minLengthVarIntSize;
1493  position = newPosition;
1494  } else {
1495  int length = Utf8.encodedLength(value);
1497  position = Utf8.encode(value, buffer, position, spaceLeft());
1498  }
1499  } catch (UnpairedSurrogateException e) {
1500  // Roll back the change - we fall back to inefficient path.
1501  position = oldPosition;
1502 
1503  // TODO(nathanmittler): We should throw an IOException here instead.
1504  inefficientWriteStringNoTag(value, e);
1505  } catch (IndexOutOfBoundsException e) {
1506  throw new OutOfSpaceException(e);
1507  }
1508  }
1509 
1510  @Override
1511  public void flush() {
1512  // Do nothing.
1513  }
1514 
1515  @Override
1516  public final int spaceLeft() {
1517  return limit - position;
1518  }
1519 
1520  @Override
1521  public final int getTotalBytesWritten() {
1522  return position - offset;
1523  }
1524  }
1525 
1530  private static final class HeapNioEncoder extends ArrayEncoder {
1531  private final ByteBuffer byteBuffer;
1532  private int initialPosition;
1533 
1534  HeapNioEncoder(ByteBuffer byteBuffer) {
1535  super(
1536  byteBuffer.array(),
1537  byteBuffer.arrayOffset() + byteBuffer.position(),
1538  byteBuffer.remaining());
1539  this.byteBuffer = byteBuffer;
1540  this.initialPosition = byteBuffer.position();
1541  }
1542 
1543  @Override
1544  public void flush() {
1545  // Update the position on the buffer.
1547  }
1548  }
1549 
1554  private static final class SafeDirectNioEncoder extends CodedOutputStream {
1555  private final ByteBuffer originalBuffer;
1556  private final ByteBuffer buffer;
1557  private final int initialPosition;
1558 
1559  SafeDirectNioEncoder(ByteBuffer buffer) {
1560  this.originalBuffer = buffer;
1561  this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN);
1562  initialPosition = buffer.position();
1563  }
1564 
1565  @Override
1566  public void writeTag(final int fieldNumber, final int wireType) throws IOException {
1567  writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
1568  }
1569 
1570  @Override
1571  public void writeInt32(final int fieldNumber, final int value) throws IOException {
1572  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1574  }
1575 
1576  @Override
1577  public void writeUInt32(final int fieldNumber, final int value) throws IOException {
1578  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1580  }
1581 
1582  @Override
1583  public void writeFixed32(final int fieldNumber, final int value) throws IOException {
1584  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
1586  }
1587 
1588  @Override
1589  public void writeUInt64(final int fieldNumber, final long value) throws IOException {
1590  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1592  }
1593 
1594  @Override
1595  public void writeFixed64(final int fieldNumber, final long value) throws IOException {
1596  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
1598  }
1599 
1600  @Override
1601  public void writeBool(final int fieldNumber, final boolean value) throws IOException {
1602  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1603  write((byte) (value ? 1 : 0));
1604  }
1605 
1606  @Override
1607  public void writeString(final int fieldNumber, final String value) throws IOException {
1610  }
1611 
1612  @Override
1613  public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
1616  }
1617 
1618  @Override
1619  public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
1620  writeByteArray(fieldNumber, value, 0, value.length);
1621  }
1622 
1623  @Override
1624  public void writeByteArray(
1625  final int fieldNumber, final byte[] value, final int offset, final int length)
1626  throws IOException {
1629  }
1630 
1631  @Override
1632  public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
1634  writeUInt32NoTag(value.capacity());
1636  }
1637 
1638  @Override
1639  public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
1642  }
1643 
1644  @Override
1645  void writeMessage(final int fieldNumber, final MessageLite value, Schema schema)
1646  throws IOException {
1648  writeMessageNoTag(value, schema);
1649  }
1650 
1651  @Override
1652  public void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
1653  throws IOException {
1655  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1656  writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value);
1657  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1658  }
1659 
1660  @Override
1661  public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
1662  throws IOException {
1664  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1665  writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value);
1666  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1667  }
1668 
1669  @Override
1670  public void writeMessageNoTag(final MessageLite value) throws IOException {
1671  writeUInt32NoTag(value.getSerializedSize());
1672  value.writeTo(this);
1673  }
1674 
1675  @Override
1676  void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException {
1677  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
1678  schema.writeTo(value, wrapper);
1679  }
1680 
1681  @Override
1682  public void write(byte value) throws IOException {
1683  try {
1684  buffer.put(value);
1685  } catch (BufferOverflowException e) {
1686  throw new OutOfSpaceException(e);
1687  }
1688  }
1689 
1690  @Override
1691  public void writeBytesNoTag(final ByteString value) throws IOException {
1692  writeUInt32NoTag(value.size());
1693  value.writeTo(this);
1694  }
1695 
1696  @Override
1697  public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
1699  write(value, offset, length);
1700  }
1701 
1702  @Override
1703  public void writeRawBytes(final ByteBuffer value) throws IOException {
1704  if (value.hasArray()) {
1705  write(value.array(), value.arrayOffset(), value.capacity());
1706  } else {
1707  ByteBuffer duplicated = value.duplicate();
1708  duplicated.clear();
1709  write(duplicated);
1710  }
1711  }
1712 
1713  @Override
1714  public void writeInt32NoTag(int value) throws IOException {
1715  if (value >= 0) {
1717  } else {
1718  // Must sign-extend.
1720  }
1721  }
1722 
1723  @Override
1724  public void writeUInt32NoTag(int value) throws IOException {
1725  try {
1726  while (true) {
1727  if ((value & ~0x7F) == 0) {
1728  buffer.put((byte) value);
1729  return;
1730  } else {
1731  buffer.put((byte) ((value & 0x7F) | 0x80));
1732  value >>>= 7;
1733  }
1734  }
1735  } catch (BufferOverflowException e) {
1736  throw new OutOfSpaceException(e);
1737  }
1738  }
1739 
1740  @Override
1741  public void writeFixed32NoTag(int value) throws IOException {
1742  try {
1743  buffer.putInt(value);
1744  } catch (BufferOverflowException e) {
1745  throw new OutOfSpaceException(e);
1746  }
1747  }
1748 
1749  @Override
1750  public void writeUInt64NoTag(long value) throws IOException {
1751  try {
1752  while (true) {
1753  if ((value & ~0x7FL) == 0) {
1754  buffer.put((byte) value);
1755  return;
1756  } else {
1757  buffer.put((byte) (((int) value & 0x7F) | 0x80));
1758  value >>>= 7;
1759  }
1760  }
1761  } catch (BufferOverflowException e) {
1762  throw new OutOfSpaceException(e);
1763  }
1764  }
1765 
1766  @Override
1767  public void writeFixed64NoTag(long value) throws IOException {
1768  try {
1769  buffer.putLong(value);
1770  } catch (BufferOverflowException e) {
1771  throw new OutOfSpaceException(e);
1772  }
1773  }
1774 
1775  @Override
1776  public void write(byte[] value, int offset, int length) throws IOException {
1777  try {
1778  buffer.put(value, offset, length);
1779  } catch (IndexOutOfBoundsException e) {
1780  throw new OutOfSpaceException(e);
1781  } catch (BufferOverflowException e) {
1782  throw new OutOfSpaceException(e);
1783  }
1784  }
1785 
1786  @Override
1787  public void writeLazy(byte[] value, int offset, int length) throws IOException {
1788  write(value, offset, length);
1789  }
1790 
1791  @Override
1792  public void write(ByteBuffer value) throws IOException {
1793  try {
1794  buffer.put(value);
1795  } catch (BufferOverflowException e) {
1796  throw new OutOfSpaceException(e);
1797  }
1798  }
1799 
1800  @Override
1801  public void writeLazy(ByteBuffer value) throws IOException {
1802  write(value);
1803  }
1804 
1805  @Override
1806  public void writeStringNoTag(String value) throws IOException {
1807  final int startPos = buffer.position();
1808  try {
1809  // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()),
1810  // and at most 3 times of it. We take advantage of this in both branches below.
1811  final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR;
1812  final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize);
1813  final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
1814  if (minLengthVarIntSize == maxLengthVarIntSize) {
1815  // Save the current position and increment past the length field. We'll come back
1816  // and write the length field after the encoding is complete.
1817  final int startOfBytes = buffer.position() + minLengthVarIntSize;
1818  buffer.position(startOfBytes);
1819 
1820  // Encode the string.
1821  encode(value);
1822 
1823  // Now go back to the beginning and write the length.
1824  int endOfBytes = buffer.position();
1825  buffer.position(startPos);
1826  writeUInt32NoTag(endOfBytes - startOfBytes);
1827 
1828  // Reposition the buffer past the written data.
1829  buffer.position(endOfBytes);
1830  } else {
1831  final int length = Utf8.encodedLength(value);
1833  encode(value);
1834  }
1835  } catch (UnpairedSurrogateException e) {
1836  // Roll back the change and convert to an IOException.
1837  buffer.position(startPos);
1838 
1839  // TODO(nathanmittler): We should throw an IOException here instead.
1840  inefficientWriteStringNoTag(value, e);
1841  } catch (IllegalArgumentException e) {
1842  // Thrown by buffer.position() if out of range.
1843  throw new OutOfSpaceException(e);
1844  }
1845  }
1846 
1847  @Override
1848  public void flush() {
1849  // Update the position of the original buffer.
1850  originalBuffer.position(buffer.position());
1851  }
1852 
1853  @Override
1854  public int spaceLeft() {
1855  return buffer.remaining();
1856  }
1857 
1858  @Override
1859  public int getTotalBytesWritten() {
1860  return buffer.position() - initialPosition;
1861  }
1862 
1863  private void encode(String value) throws IOException {
1864  try {
1865  Utf8.encodeUtf8(value, buffer);
1866  } catch (IndexOutOfBoundsException e) {
1867  throw new OutOfSpaceException(e);
1868  }
1869  }
1870  }
1871 
1876  private static final class UnsafeDirectNioEncoder extends CodedOutputStream {
1877  private final ByteBuffer originalBuffer;
1878  private final ByteBuffer buffer;
1879  private final long address;
1880  private final long initialPosition;
1881  private final long limit;
1882  private final long oneVarintLimit;
1883  private long position;
1884 
1885  UnsafeDirectNioEncoder(ByteBuffer buffer) {
1886  this.originalBuffer = buffer;
1887  this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN);
1888  address = UnsafeUtil.addressOffset(buffer);
1889  initialPosition = address + buffer.position();
1890  limit = address + buffer.limit();
1891  oneVarintLimit = limit - MAX_VARINT_SIZE;
1893  }
1894 
1895  static boolean isSupported() {
1896  return UnsafeUtil.hasUnsafeByteBufferOperations();
1897  }
1898 
1899  @Override
1900  public void writeTag(int fieldNumber, int wireType) throws IOException {
1901  writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
1902  }
1903 
1904  @Override
1905  public void writeInt32(int fieldNumber, int value) throws IOException {
1906  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1908  }
1909 
1910  @Override
1911  public void writeUInt32(int fieldNumber, int value) throws IOException {
1912  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1914  }
1915 
1916  @Override
1917  public void writeFixed32(int fieldNumber, int value) throws IOException {
1918  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
1920  }
1921 
1922  @Override
1923  public void writeUInt64(int fieldNumber, long value) throws IOException {
1924  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1926  }
1927 
1928  @Override
1929  public void writeFixed64(int fieldNumber, long value) throws IOException {
1930  writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
1932  }
1933 
1934  @Override
1935  public void writeBool(int fieldNumber, boolean value) throws IOException {
1936  writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
1937  write((byte) (value ? 1 : 0));
1938  }
1939 
1940  @Override
1941  public void writeString(int fieldNumber, String value) throws IOException {
1944  }
1945 
1946  @Override
1947  public void writeBytes(int fieldNumber, ByteString value) throws IOException {
1950  }
1951 
1952  @Override
1953  public void writeByteArray(int fieldNumber, byte[] value) throws IOException {
1954  writeByteArray(fieldNumber, value, 0, value.length);
1955  }
1956 
1957  @Override
1958  public void writeByteArray(int fieldNumber, byte[] value, int offset, int length)
1959  throws IOException {
1962  }
1963 
1964  @Override
1965  public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException {
1967  writeUInt32NoTag(value.capacity());
1969  }
1970 
1971  @Override
1972  public void writeMessage(int fieldNumber, MessageLite value) throws IOException {
1975  }
1976 
1977  @Override
1978  void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException {
1980  writeMessageNoTag(value, schema);
1981  }
1982 
1983  @Override
1984  public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException {
1986  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1987  writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value);
1988  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1989  }
1990 
1991  @Override
1992  public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException {
1994  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
1995  writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value);
1996  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
1997  }
1998 
1999  @Override
2000  public void writeMessageNoTag(MessageLite value) throws IOException {
2001  writeUInt32NoTag(value.getSerializedSize());
2002  value.writeTo(this);
2003  }
2004 
2005  @Override
2006  void writeMessageNoTag(MessageLite value, Schema schema) throws IOException {
2007  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
2008  schema.writeTo(value, wrapper);
2009  }
2010 
2011  @Override
2012  public void write(byte value) throws IOException {
2013  if (position >= limit) {
2014  throw new OutOfSpaceException(
2015  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1));
2016  }
2017  UnsafeUtil.putByte(position++, value);
2018  }
2019 
2020  @Override
2021  public void writeBytesNoTag(ByteString value) throws IOException {
2022  writeUInt32NoTag(value.size());
2023  value.writeTo(this);
2024  }
2025 
2026  @Override
2027  public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException {
2029  write(value, offset, length);
2030  }
2031 
2032  @Override
2033  public void writeRawBytes(ByteBuffer value) throws IOException {
2034  if (value.hasArray()) {
2035  write(value.array(), value.arrayOffset(), value.capacity());
2036  } else {
2037  ByteBuffer duplicated = value.duplicate();
2038  duplicated.clear();
2039  write(duplicated);
2040  }
2041  }
2042 
2043  @Override
2044  public void writeInt32NoTag(int value) throws IOException {
2045  if (value >= 0) {
2047  } else {
2048  // Must sign-extend.
2050  }
2051  }
2052 
2053  @Override
2054  public void writeUInt32NoTag(int value) throws IOException {
2055  if (position <= oneVarintLimit) {
2056  // Optimization to avoid bounds checks on each iteration.
2057  while (true) {
2058  if ((value & ~0x7F) == 0) {
2059  UnsafeUtil.putByte(position++, (byte) value);
2060  return;
2061  } else {
2062  UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
2063  value >>>= 7;
2064  }
2065  }
2066  } else {
2067  while (position < limit) {
2068  if ((value & ~0x7F) == 0) {
2069  UnsafeUtil.putByte(position++, (byte) value);
2070  return;
2071  } else {
2072  UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
2073  value >>>= 7;
2074  }
2075  }
2076  throw new OutOfSpaceException(
2077  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1));
2078  }
2079  }
2080 
2081  @Override
2082  public void writeFixed32NoTag(int value) throws IOException {
2083  buffer.putInt(bufferPos(position), value);
2084  position += FIXED32_SIZE;
2085  }
2086 
2087  @Override
2088  public void writeUInt64NoTag(long value) throws IOException {
2089  if (position <= oneVarintLimit) {
2090  // Optimization to avoid bounds checks on each iteration.
2091  while (true) {
2092  if ((value & ~0x7FL) == 0) {
2093  UnsafeUtil.putByte(position++, (byte) value);
2094  return;
2095  } else {
2096  UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
2097  value >>>= 7;
2098  }
2099  }
2100  } else {
2101  while (position < limit) {
2102  if ((value & ~0x7FL) == 0) {
2103  UnsafeUtil.putByte(position++, (byte) value);
2104  return;
2105  } else {
2106  UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
2107  value >>>= 7;
2108  }
2109  }
2110  throw new OutOfSpaceException(
2111  String.format("Pos: %d, limit: %d, len: %d", position, limit, 1));
2112  }
2113  }
2114 
2115  @Override
2116  public void writeFixed64NoTag(long value) throws IOException {
2117  buffer.putLong(bufferPos(position), value);
2118  position += FIXED64_SIZE;
2119  }
2120 
2121  @Override
2122  public void write(byte[] value, int offset, int length) throws IOException {
2123  if (value == null
2124  || offset < 0
2125  || length < 0
2126  || (value.length - length) < offset
2127  || (limit - length) < position) {
2128  if (value == null) {
2129  throw new NullPointerException("value");
2130  }
2131  throw new OutOfSpaceException(
2132  String.format("Pos: %d, limit: %d, len: %d", position, limit, length));
2133  }
2134 
2135  UnsafeUtil.copyMemory(value, offset, position, length);
2136  position += length;
2137  }
2138 
2139  @Override
2140  public void writeLazy(byte[] value, int offset, int length) throws IOException {
2141  write(value, offset, length);
2142  }
2143 
2144  @Override
2145  public void write(ByteBuffer value) throws IOException {
2146  try {
2147  int length = value.remaining();
2149  buffer.put(value);
2150  position += length;
2151  } catch (BufferOverflowException e) {
2152  throw new OutOfSpaceException(e);
2153  }
2154  }
2155 
2156  @Override
2157  public void writeLazy(ByteBuffer value) throws IOException {
2158  write(value);
2159  }
2160 
2161  @Override
2162  public void writeStringNoTag(String value) throws IOException {
2163  long prevPos = position;
2164  try {
2165  // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()),
2166  // and at most 3 times of it. We take advantage of this in both branches below.
2167  int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR;
2168  int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize);
2169  int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
2170  if (minLengthVarIntSize == maxLengthVarIntSize) {
2171  // Save the current position and increment past the length field. We'll come back
2172  // and write the length field after the encoding is complete.
2173  int stringStart = bufferPos(position) + minLengthVarIntSize;
2174  buffer.position(stringStart);
2175 
2176  // Encode the string.
2177  Utf8.encodeUtf8(value, buffer);
2178 
2179  // Write the length and advance the position.
2180  int length = buffer.position() - stringStart;
2182  position += length;
2183  } else {
2184  // Calculate and write the encoded length.
2185  int length = Utf8.encodedLength(value);
2187 
2188  // Write the string and advance the position.
2190  Utf8.encodeUtf8(value, buffer);
2191  position += length;
2192  }
2193  } catch (UnpairedSurrogateException e) {
2194  // Roll back the change and convert to an IOException.
2195  position = prevPos;
2197 
2198  // TODO(nathanmittler): We should throw an IOException here instead.
2199  inefficientWriteStringNoTag(value, e);
2200  } catch (IllegalArgumentException e) {
2201  // Thrown by buffer.position() if out of range.
2202  throw new OutOfSpaceException(e);
2203  } catch (IndexOutOfBoundsException e) {
2204  throw new OutOfSpaceException(e);
2205  }
2206  }
2207 
2208  @Override
2209  public void flush() {
2210  // Update the position of the original buffer.
2211  originalBuffer.position(bufferPos(position));
2212  }
2213 
2214  @Override
2215  public int spaceLeft() {
2216  return (int) (limit - position);
2217  }
2218 
2219  @Override
2220  public int getTotalBytesWritten() {
2221  return (int) (position - initialPosition);
2222  }
2223 
2224  private void repositionBuffer(long pos) {
2225  buffer.position(bufferPos(pos));
2226  }
2227 
2228  private int bufferPos(long pos) {
2229  return (int) (pos - address);
2230  }
2231  }
2232 
2234  private abstract static class AbstractBufferedEncoder extends CodedOutputStream {
2235  final byte[] buffer;
2236  final int limit;
2237  int position;
2238  int totalBytesWritten;
2239 
2240  AbstractBufferedEncoder(int bufferSize) {
2241  if (bufferSize < 0) {
2242  throw new IllegalArgumentException("bufferSize must be >= 0");
2243  }
2244  // As an optimization, we require that the buffer be able to store at least 2
2245  // varints so that we can buffer any integer write (tag + value). This reduces the
2246  // number of range checks for a single write to 1 (i.e. if there is not enough space
2247  // to buffer the tag+value, flush and then buffer it).
2248  this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)];
2249  this.limit = buffer.length;
2250  }
2251 
2252  @Override
2253  public final int spaceLeft() {
2254  throw new UnsupportedOperationException(
2255  "spaceLeft() can only be called on CodedOutputStreams that are "
2256  + "writing to a flat array or ByteBuffer.");
2257  }
2258 
2259  @Override
2260  public final int getTotalBytesWritten() {
2261  return totalBytesWritten;
2262  }
2263 
2268  final void buffer(byte value) {
2269  buffer[position++] = value;
2270  totalBytesWritten++;
2271  }
2272 
2277  final void bufferTag(final int fieldNumber, final int wireType) {
2278  bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
2279  }
2280 
2285  final void bufferInt32NoTag(final int value) {
2286  if (value >= 0) {
2287  bufferUInt32NoTag(value);
2288  } else {
2289  // Must sign-extend.
2290  bufferUInt64NoTag(value);
2291  }
2292  }
2293 
2298  final void bufferUInt32NoTag(int value) {
2300  final long originalPos = position;
2301  while (true) {
2302  if ((value & ~0x7F) == 0) {
2303  UnsafeUtil.putByte(buffer, position++, (byte) value);
2304  break;
2305  } else {
2306  UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80));
2307  value >>>= 7;
2308  }
2309  }
2310  int delta = (int) (position - originalPos);
2311  totalBytesWritten += delta;
2312  } else {
2313  while (true) {
2314  if ((value & ~0x7F) == 0) {
2315  buffer[position++] = (byte) value;
2316  totalBytesWritten++;
2317  return;
2318  } else {
2319  buffer[position++] = (byte) ((value & 0x7F) | 0x80);
2320  totalBytesWritten++;
2321  value >>>= 7;
2322  }
2323  }
2324  }
2325  }
2326 
2331  final void bufferUInt64NoTag(long value) {
2333  final long originalPos = position;
2334  while (true) {
2335  if ((value & ~0x7FL) == 0) {
2336  UnsafeUtil.putByte(buffer, position++, (byte) value);
2337  break;
2338  } else {
2339  UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
2340  value >>>= 7;
2341  }
2342  }
2343  int delta = (int) (position - originalPos);
2344  totalBytesWritten += delta;
2345  } else {
2346  while (true) {
2347  if ((value & ~0x7FL) == 0) {
2348  buffer[position++] = (byte) value;
2349  totalBytesWritten++;
2350  return;
2351  } else {
2352  buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
2353  totalBytesWritten++;
2354  value >>>= 7;
2355  }
2356  }
2357  }
2358  }
2359 
2364  final void bufferFixed32NoTag(int value) {
2365  buffer[position++] = (byte) (value & 0xFF);
2366  buffer[position++] = (byte) ((value >> 8) & 0xFF);
2367  buffer[position++] = (byte) ((value >> 16) & 0xFF);
2368  buffer[position++] = (byte) ((value >> 24) & 0xFF);
2369  totalBytesWritten += FIXED32_SIZE;
2370  }
2371 
2376  final void bufferFixed64NoTag(long value) {
2377  buffer[position++] = (byte) (value & 0xFF);
2378  buffer[position++] = (byte) ((value >> 8) & 0xFF);
2379  buffer[position++] = (byte) ((value >> 16) & 0xFF);
2380  buffer[position++] = (byte) ((value >> 24) & 0xFF);
2381  buffer[position++] = (byte) ((int) (value >> 32) & 0xFF);
2382  buffer[position++] = (byte) ((int) (value >> 40) & 0xFF);
2383  buffer[position++] = (byte) ((int) (value >> 48) & 0xFF);
2384  buffer[position++] = (byte) ((int) (value >> 56) & 0xFF);
2385  totalBytesWritten += FIXED64_SIZE;
2386  }
2387  }
2388 
2394  private static final class ByteOutputEncoder extends AbstractBufferedEncoder {
2395  private final ByteOutput out;
2396 
2397  ByteOutputEncoder(ByteOutput out, int bufferSize) {
2398  super(bufferSize);
2399  if (out == null) {
2400  throw new NullPointerException("out");
2401  }
2402  this.out = out;
2403  }
2404 
2405  @Override
2406  public void writeTag(final int fieldNumber, final int wireType) throws IOException {
2407  writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
2408  }
2409 
2410  @Override
2411  public void writeInt32(final int fieldNumber, final int value) throws IOException {
2412  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2413  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2414  bufferInt32NoTag(value);
2415  }
2416 
2417  @Override
2418  public void writeUInt32(final int fieldNumber, final int value) throws IOException {
2419  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2420  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2421  bufferUInt32NoTag(value);
2422  }
2423 
2424  @Override
2425  public void writeFixed32(final int fieldNumber, final int value) throws IOException {
2426  flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE);
2427  bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
2428  bufferFixed32NoTag(value);
2429  }
2430 
2431  @Override
2432  public void writeUInt64(final int fieldNumber, final long value) throws IOException {
2433  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2434  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2435  bufferUInt64NoTag(value);
2436  }
2437 
2438  @Override
2439  public void writeFixed64(final int fieldNumber, final long value) throws IOException {
2440  flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE);
2441  bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
2442  bufferFixed64NoTag(value);
2443  }
2444 
2445  @Override
2446  public void writeBool(final int fieldNumber, final boolean value) throws IOException {
2447  flushIfNotAvailable(MAX_VARINT_SIZE + 1);
2448  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2449  buffer((byte) (value ? 1 : 0));
2450  }
2451 
2452  @Override
2453  public void writeString(final int fieldNumber, final String value) throws IOException {
2456  }
2457 
2458  @Override
2459  public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
2462  }
2463 
2464  @Override
2465  public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
2466  writeByteArray(fieldNumber, value, 0, value.length);
2467  }
2468 
2469  @Override
2470  public void writeByteArray(
2471  final int fieldNumber, final byte[] value, final int offset, final int length)
2472  throws IOException {
2475  }
2476 
2477  @Override
2478  public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
2480  writeUInt32NoTag(value.capacity());
2482  }
2483 
2484  @Override
2485  public void writeBytesNoTag(final ByteString value) throws IOException {
2486  writeUInt32NoTag(value.size());
2487  value.writeTo(this);
2488  }
2489 
2490  @Override
2491  public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
2493  write(value, offset, length);
2494  }
2495 
2496  @Override
2497  public void writeRawBytes(final ByteBuffer value) throws IOException {
2498  if (value.hasArray()) {
2499  write(value.array(), value.arrayOffset(), value.capacity());
2500  } else {
2501  ByteBuffer duplicated = value.duplicate();
2502  duplicated.clear();
2503  write(duplicated);
2504  }
2505  }
2506 
2507  @Override
2508  public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
2511  }
2512 
2513  @Override
2514  void writeMessage(final int fieldNumber, final MessageLite value, Schema schema)
2515  throws IOException {
2517  writeMessageNoTag(value, schema);
2518  }
2519 
2520  @Override
2521  public void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
2522  throws IOException {
2524  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
2525  writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value);
2526  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
2527  }
2528 
2529  @Override
2530  public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
2531  throws IOException {
2533  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
2534  writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value);
2535  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
2536  }
2537 
2538  @Override
2539  public void writeMessageNoTag(final MessageLite value) throws IOException {
2540  writeUInt32NoTag(value.getSerializedSize());
2541  value.writeTo(this);
2542  }
2543 
2544  @Override
2545  void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException {
2546  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
2547  schema.writeTo(value, wrapper);
2548  }
2549 
2550  @Override
2551  public void write(byte value) throws IOException {
2552  if (position == limit) {
2553  doFlush();
2554  }
2555 
2556  buffer(value);
2557  }
2558 
2559  @Override
2560  public void writeInt32NoTag(int value) throws IOException {
2561  if (value >= 0) {
2563  } else {
2564  // Must sign-extend.
2566  }
2567  }
2568 
2569  @Override
2570  public void writeUInt32NoTag(int value) throws IOException {
2571  flushIfNotAvailable(MAX_VARINT32_SIZE);
2572  bufferUInt32NoTag(value);
2573  }
2574 
2575  @Override
2576  public void writeFixed32NoTag(final int value) throws IOException {
2577  flushIfNotAvailable(FIXED32_SIZE);
2578  bufferFixed32NoTag(value);
2579  }
2580 
2581  @Override
2582  public void writeUInt64NoTag(long value) throws IOException {
2583  flushIfNotAvailable(MAX_VARINT_SIZE);
2584  bufferUInt64NoTag(value);
2585  }
2586 
2587  @Override
2588  public void writeFixed64NoTag(final long value) throws IOException {
2589  flushIfNotAvailable(FIXED64_SIZE);
2590  bufferFixed64NoTag(value);
2591  }
2592 
2593  @Override
2594  public void writeStringNoTag(String value) throws IOException {
2595  // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()),
2596  // and at most 3 times of it. We take advantage of this in both branches below.
2597  final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
2598  final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
2599 
2600  // If we are streaming and the potential length is too big to fit in our buffer, we take the
2601  // slower path.
2602  if (maxLengthVarIntSize + maxLength > limit) {
2603  // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes()
2604  // does the same internally and then does *another copy* to return a byte[] of exactly the
2605  // right size. We can skip that copy and just writeRawBytes up to the actualLength of the
2606  // UTF-8 encoded bytes.
2607  final byte[] encodedBytes = new byte[maxLength];
2608  int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength);
2609  writeUInt32NoTag(actualLength);
2610  writeLazy(encodedBytes, 0, actualLength);
2611  return;
2612  }
2613 
2614  // Fast path: we have enough space available in our buffer for the string...
2615  if (maxLengthVarIntSize + maxLength > limit - position) {
2616  // Flush to free up space.
2617  doFlush();
2618  }
2619 
2620  final int oldPosition = position;
2621  try {
2622  // Optimize for the case where we know this length results in a constant varint length as
2623  // this saves a pass for measuring the length of the string.
2624  final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
2625 
2626  if (minLengthVarIntSize == maxLengthVarIntSize) {
2627  position = oldPosition + minLengthVarIntSize;
2628  int newPosition = Utf8.encode(value, buffer, position, limit - position);
2629  // Since this class is stateful and tracks the position, we rewind and store the state,
2630  // prepend the length, then reset it back to the end of the string.
2631  position = oldPosition;
2632  int length = newPosition - oldPosition - minLengthVarIntSize;
2633  bufferUInt32NoTag(length);
2634  position = newPosition;
2635  totalBytesWritten += length;
2636  } else {
2637  int length = Utf8.encodedLength(value);
2638  bufferUInt32NoTag(length);
2639  position = Utf8.encode(value, buffer, position, length);
2640  totalBytesWritten += length;
2641  }
2642  } catch (UnpairedSurrogateException e) {
2643  // Roll back the change and convert to an IOException.
2644  totalBytesWritten -= position - oldPosition;
2645  position = oldPosition;
2646 
2647  // TODO(nathanmittler): We should throw an IOException here instead.
2648  inefficientWriteStringNoTag(value, e);
2649  } catch (IndexOutOfBoundsException e) {
2650  throw new OutOfSpaceException(e);
2651  }
2652  }
2653 
2654  @Override
2655  public void flush() throws IOException {
2656  if (position > 0) {
2657  // Flush the buffer.
2658  doFlush();
2659  }
2660  }
2661 
2662  @Override
2663  public void write(byte[] value, int offset, int length) throws IOException {
2664  flush();
2666  totalBytesWritten += length;
2667  }
2668 
2669  @Override
2670  public void writeLazy(byte[] value, int offset, int length) throws IOException {
2671  flush();
2673  totalBytesWritten += length;
2674  }
2675 
2676  @Override
2677  public void write(ByteBuffer value) throws IOException {
2678  flush();
2679  int length = value.remaining();
2680  out.write(value);
2681  totalBytesWritten += length;
2682  }
2683 
2684  @Override
2685  public void writeLazy(ByteBuffer value) throws IOException {
2686  flush();
2687  int length = value.remaining();
2688  out.writeLazy(value);
2689  totalBytesWritten += length;
2690  }
2691 
2692  private void flushIfNotAvailable(int requiredSize) throws IOException {
2693  if (limit - position < requiredSize) {
2694  doFlush();
2695  }
2696  }
2697 
2698  private void doFlush() throws IOException {
2699  out.write(buffer, 0, position);
2700  position = 0;
2701  }
2702  }
2703 
2708  private static final class OutputStreamEncoder extends AbstractBufferedEncoder {
2709  private final OutputStream out;
2710 
2711  OutputStreamEncoder(OutputStream out, int bufferSize) {
2712  super(bufferSize);
2713  if (out == null) {
2714  throw new NullPointerException("out");
2715  }
2716  this.out = out;
2717  }
2718 
2719  @Override
2720  public void writeTag(final int fieldNumber, final int wireType) throws IOException {
2721  writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
2722  }
2723 
2724  @Override
2725  public void writeInt32(final int fieldNumber, final int value) throws IOException {
2726  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2727  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2728  bufferInt32NoTag(value);
2729  }
2730 
2731  @Override
2732  public void writeUInt32(final int fieldNumber, final int value) throws IOException {
2733  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2734  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2735  bufferUInt32NoTag(value);
2736  }
2737 
2738  @Override
2739  public void writeFixed32(final int fieldNumber, final int value) throws IOException {
2740  flushIfNotAvailable(MAX_VARINT_SIZE + FIXED32_SIZE);
2741  bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
2742  bufferFixed32NoTag(value);
2743  }
2744 
2745  @Override
2746  public void writeUInt64(final int fieldNumber, final long value) throws IOException {
2747  flushIfNotAvailable(MAX_VARINT_SIZE * 2);
2748  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2749  bufferUInt64NoTag(value);
2750  }
2751 
2752  @Override
2753  public void writeFixed64(final int fieldNumber, final long value) throws IOException {
2754  flushIfNotAvailable(MAX_VARINT_SIZE + FIXED64_SIZE);
2755  bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
2756  bufferFixed64NoTag(value);
2757  }
2758 
2759  @Override
2760  public void writeBool(final int fieldNumber, final boolean value) throws IOException {
2761  flushIfNotAvailable(MAX_VARINT_SIZE + 1);
2762  bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
2763  buffer((byte) (value ? 1 : 0));
2764  }
2765 
2766  @Override
2767  public void writeString(final int fieldNumber, final String value) throws IOException {
2770  }
2771 
2772  @Override
2773  public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
2776  }
2777 
2778  @Override
2779  public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
2780  writeByteArray(fieldNumber, value, 0, value.length);
2781  }
2782 
2783  @Override
2784  public void writeByteArray(
2785  final int fieldNumber, final byte[] value, final int offset, final int length)
2786  throws IOException {
2789  }
2790 
2791  @Override
2792  public void writeByteBuffer(final int fieldNumber, final ByteBuffer value) throws IOException {
2794  writeUInt32NoTag(value.capacity());
2796  }
2797 
2798  @Override
2799  public void writeBytesNoTag(final ByteString value) throws IOException {
2800  writeUInt32NoTag(value.size());
2801  value.writeTo(this);
2802  }
2803 
2804  @Override
2805  public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
2807  write(value, offset, length);
2808  }
2809 
2810  @Override
2811  public void writeRawBytes(final ByteBuffer value) throws IOException {
2812  if (value.hasArray()) {
2813  write(value.array(), value.arrayOffset(), value.capacity());
2814  } else {
2815  ByteBuffer duplicated = value.duplicate();
2816  duplicated.clear();
2817  write(duplicated);
2818  }
2819  }
2820 
2821  @Override
2822  public void writeMessage(final int fieldNumber, final MessageLite value) throws IOException {
2825  }
2826 
2827  @Override
2828  void writeMessage(final int fieldNumber, final MessageLite value, Schema schema)
2829  throws IOException {
2831  writeMessageNoTag(value, schema);
2832  }
2833 
2834  @Override
2835  public void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
2836  throws IOException {
2838  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
2839  writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value);
2840  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
2841  }
2842 
2843  @Override
2844  public void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
2845  throws IOException {
2847  writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber);
2848  writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value);
2849  writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP);
2850  }
2851 
2852  @Override
2853  public void writeMessageNoTag(final MessageLite value) throws IOException {
2854  writeUInt32NoTag(value.getSerializedSize());
2855  value.writeTo(this);
2856  }
2857 
2858  @Override
2859  void writeMessageNoTag(final MessageLite value, Schema schema) throws IOException {
2860  writeUInt32NoTag(((AbstractMessageLite) value).getSerializedSize(schema));
2861  schema.writeTo(value, wrapper);
2862  }
2863 
2864  @Override
2865  public void write(byte value) throws IOException {
2866  if (position == limit) {
2867  doFlush();
2868  }
2869 
2870  buffer(value);
2871  }
2872 
2873  @Override
2874  public void writeInt32NoTag(int value) throws IOException {
2875  if (value >= 0) {
2877  } else {
2878  // Must sign-extend.
2880  }
2881  }
2882 
2883  @Override
2884  public void writeUInt32NoTag(int value) throws IOException {
2885  flushIfNotAvailable(MAX_VARINT32_SIZE);
2886  bufferUInt32NoTag(value);
2887  }
2888 
2889  @Override
2890  public void writeFixed32NoTag(final int value) throws IOException {
2891  flushIfNotAvailable(FIXED32_SIZE);
2892  bufferFixed32NoTag(value);
2893  }
2894 
2895  @Override
2896  public void writeUInt64NoTag(long value) throws IOException {
2897  flushIfNotAvailable(MAX_VARINT_SIZE);
2898  bufferUInt64NoTag(value);
2899  }
2900 
2901  @Override
2902  public void writeFixed64NoTag(final long value) throws IOException {
2903  flushIfNotAvailable(FIXED64_SIZE);
2904  bufferFixed64NoTag(value);
2905  }
2906 
2907  @Override
2908  public void writeStringNoTag(String value) throws IOException {
2909  try {
2910  // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()),
2911  // and at most 3 times of it. We take advantage of this in both branches below.
2912  final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
2913  final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
2914 
2915  // If we are streaming and the potential length is too big to fit in our buffer, we take the
2916  // slower path.
2917  if (maxLengthVarIntSize + maxLength > limit) {
2918  // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes()
2919  // does the same internally and then does *another copy* to return a byte[] of exactly the
2920  // right size. We can skip that copy and just writeRawBytes up to the actualLength of the
2921  // UTF-8 encoded bytes.
2922  final byte[] encodedBytes = new byte[maxLength];
2923  int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength);
2924  writeUInt32NoTag(actualLength);
2925  writeLazy(encodedBytes, 0, actualLength);
2926  return;
2927  }
2928 
2929  // Fast path: we have enough space available in our buffer for the string...
2930  if (maxLengthVarIntSize + maxLength > limit - position) {
2931  // Flush to free up space.
2932  doFlush();
2933  }
2934 
2935  // Optimize for the case where we know this length results in a constant varint length as
2936  // this saves a pass for measuring the length of the string.
2937  final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
2938  int oldPosition = position;
2939  final int length;
2940  try {
2941  if (minLengthVarIntSize == maxLengthVarIntSize) {
2942  position = oldPosition + minLengthVarIntSize;
2943  int newPosition = Utf8.encode(value, buffer, position, limit - position);
2944  // Since this class is stateful and tracks the position, we rewind and store the
2945  // state, prepend the length, then reset it back to the end of the string.
2946  position = oldPosition;
2947  length = newPosition - oldPosition - minLengthVarIntSize;
2948  bufferUInt32NoTag(length);
2949  position = newPosition;
2950  } else {
2951  length = Utf8.encodedLength(value);
2952  bufferUInt32NoTag(length);
2953  position = Utf8.encode(value, buffer, position, length);
2954  }
2955  totalBytesWritten += length;
2956  } catch (UnpairedSurrogateException e) {
2957  // Be extra careful and restore the original position for retrying the write with the
2958  // less efficient path.
2959  totalBytesWritten -= position - oldPosition;
2960  position = oldPosition;
2961  throw e;
2962  } catch (ArrayIndexOutOfBoundsException e) {
2963  throw new OutOfSpaceException(e);
2964  }
2965  } catch (UnpairedSurrogateException e) {
2966  inefficientWriteStringNoTag(value, e);
2967  }
2968  }
2969 
2970  @Override
2971  public void flush() throws IOException {
2972  if (position > 0) {
2973  // Flush the buffer.
2974  doFlush();
2975  }
2976  }
2977 
2978  @Override
2979  public void write(byte[] value, int offset, int length) throws IOException {
2980  if (limit - position >= length) {
2981  // We have room in the current buffer.
2982  System.arraycopy(value, offset, buffer, position, length);
2983  position += length;
2984  totalBytesWritten += length;
2985  } else {
2986  // Write extends past current buffer. Fill the rest of this buffer and
2987  // flush.
2988  final int bytesWritten = limit - position;
2989  System.arraycopy(value, offset, buffer, position, bytesWritten);
2990  offset += bytesWritten;
2991  length -= bytesWritten;
2992  position = limit;
2993  totalBytesWritten += bytesWritten;
2994  doFlush();
2995 
2996  // Now deal with the rest.
2997  // Since we have an output stream, this is our buffer
2998  // and buffer offset == 0
2999  if (length <= limit) {
3000  // Fits in new buffer.
3001  System.arraycopy(value, offset, buffer, 0, length);
3002  position = length;
3003  } else {
3004  // Write is very big. Let's do it all at once.
3005  out.write(value, offset, length);
3006  }
3007  totalBytesWritten += length;
3008  }
3009  }
3010 
3011  @Override
3012  public void writeLazy(byte[] value, int offset, int length) throws IOException {
3013  write(value, offset, length);
3014  }
3015 
3016  @Override
3017  public void write(ByteBuffer value) throws IOException {
3018  int length = value.remaining();
3019  if (limit - position >= length) {
3020  // We have room in the current buffer.
3021  value.get(buffer, position, length);
3022  position += length;
3023  totalBytesWritten += length;
3024  } else {
3025  // Write extends past current buffer. Fill the rest of this buffer and
3026  // flush.
3027  final int bytesWritten = limit - position;
3028  value.get(buffer, position, bytesWritten);
3029  length -= bytesWritten;
3030  position = limit;
3031  totalBytesWritten += bytesWritten;
3032  doFlush();
3033 
3034  // Now deal with the rest.
3035  // Since we have an output stream, this is our buffer
3036  // and buffer offset == 0
3037  while (length > limit) {
3038  // Copy data into the buffer before writing it to OutputStream.
3039  value.get(buffer, 0, limit);
3040  out.write(buffer, 0, limit);
3041  length -= limit;
3042  totalBytesWritten += limit;
3043  }
3044  value.get(buffer, 0, length);
3045  position = length;
3046  totalBytesWritten += length;
3047  }
3048  }
3049 
3050  @Override
3051  public void writeLazy(ByteBuffer value) throws IOException {
3052  write(value);
3053  }
3054 
3055  private void flushIfNotAvailable(int requiredSize) throws IOException {
3056  if (limit - position < requiredSize) {
3057  doFlush();
3058  }
3059  }
3060 
3061  private void doFlush() throws IOException {
3062  out.write(buffer, 0, position);
3063  position = 0;
3064  }
3065  }
3066 }
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.flush
void flush()
Definition: CodedOutputStream.java:2971
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeByteArray
void writeByteArray(int fieldNumber, byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1958
com.google.protobuf.CodedOutputStream.OutOfSpaceException.MESSAGE
static final String MESSAGE
Definition: CodedOutputStream.java:950
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.write
void write(ByteBuffer value)
Definition: CodedOutputStream.java:2677
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeBytesNoTag
final void writeBytesNoTag(final ByteString value)
Definition: CodedOutputStream.java:1247
com.google.protobuf.ByteOutput.write
abstract void write(byte value)
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeMessageSetExtension
final void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1286
com.google.protobuf.WireFormat.WIRETYPE_VARINT
static final int WIRETYPE_VARINT
Definition: WireFormat.java:55
java::lang
com.google.protobuf.CodedOutputStream.writeBytes
abstract void writeBytes(int fieldNumber, ByteString value)
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeFixed64
void writeFixed64(int fieldNumber, long value)
Definition: CodedOutputStream.java:1929
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeUInt64NoTag
void writeUInt64NoTag(long value)
Definition: CodedOutputStream.java:2088
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeFixed64NoTag
void writeFixed64NoTag(final long value)
Definition: CodedOutputStream.java:2902
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(final byte[] flatArray)
Definition: CodedOutputStream.java:114
com.google.protobuf.CodedOutputStream.computeBoolSizeNoTag
static int computeBoolSizeNoTag(@SuppressWarnings("unused") final boolean unused)
Definition: CodedOutputStream.java:826
com.google.protobuf.CodedOutputStream.computeGroupSize
static int computeGroupSize(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1058
com.google.protobuf.ByteOutput
Definition: ByteOutput.java:50
com.google.protobuf.CodedOutputStream.writeSFixed64NoTag
final void writeSFixed64NoTag(final long value)
Definition: CodedOutputStream.java:431
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeFixed64NoTag
final void writeFixed64NoTag(long value)
Definition: CodedOutputStream.java:1427
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.write
void write(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2663
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeUInt64NoTag
void writeUInt64NoTag(long value)
Definition: CodedOutputStream.java:2582
com.google.protobuf.CodedOutputStream.computeUInt64Size
static int computeUInt64Size(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:556
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeBytes
void writeBytes(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:1613
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeLazy
void writeLazy(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1787
com.google.protobuf.CodedOutputStream.computeSInt32SizeNoTag
static int computeSInt32SizeNoTag(final int value)
Definition: CodedOutputStream.java:744
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeBool
void writeBool(final int fieldNumber, final boolean value)
Definition: CodedOutputStream.java:2446
com.google.protobuf.CodedOutputStream.computeFixed64Size
static int computeFixed64Size(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:572
com.google.protobuf.CodedOutputStream.computeDoubleSize
static int computeDoubleSize(final int fieldNumber, final double value)
Definition: CodedOutputStream.java:596
com.google.protobuf.CodedOutputStream.writeGroupNoTag
final void writeGroupNoTag(final MessageLite value)
Definition: CodedOutputStream.java:1037
com.google.protobuf.Utf8.UnpairedSurrogateException
Definition: Utf8.java:225
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeUInt32NoTag
void writeUInt32NoTag(int value)
Definition: CodedOutputStream.java:2884
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeMessageSetExtension
void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:2835
com.google.protobuf.CodedOutputStream.writeLazy
abstract void writeLazy(byte[] value, int offset, int length)
com.google.protobuf.CodedOutputStream.writeInt64
final void writeInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:255
com.google.protobuf.CodedOutputStream.writeRawBytes
final void writeRawBytes(final ByteString value)
Definition: CodedOutputStream.java:348
com.google.protobuf.CodedOutputStream.writeFixed64
abstract void writeFixed64(int fieldNumber, long value)
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeMessageNoTag
void writeMessageNoTag(MessageLite value)
Definition: CodedOutputStream.java:2000
com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder.getTotalBytesWritten
final int getTotalBytesWritten()
Definition: CodedOutputStream.java:2260
com.google.protobuf.CodedOutputStream.computeRawMessageSetExtensionSize
static int computeRawMessageSetExtensionSize(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:687
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(ByteBuffer buffer)
Definition: CodedOutputStream.java:130
length
GLenum GLuint GLenum GLsizei length
Definition: glcorearb.h:2695
com.google.protobuf.CodedOutputStream.computeInt32Size
static int computeInt32Size(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:508
com.google.protobuf.CodedOutputStream.computeLazyFieldSize
static int computeLazyFieldSize(final int fieldNumber, final LazyFieldLite value)
Definition: CodedOutputStream.java:652
com.google.protobuf.CodedOutputStream.writeRawLittleEndian64
final void writeRawLittleEndian64(final long value)
Definition: CodedOutputStream.java:1143
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeFixed32NoTag
void writeFixed32NoTag(final int value)
Definition: CodedOutputStream.java:2890
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeUInt64
void writeUInt64(int fieldNumber, long value)
Definition: CodedOutputStream.java:1923
com.google.protobuf.CodedOutputStream.computeSFixed32SizeNoTag
static int computeSFixed32SizeNoTag(@SuppressWarnings("unused") final int unused)
Definition: CodedOutputStream.java:754
com.google.protobuf.CodedOutputStream.writeBool
abstract void writeBool(int fieldNumber, boolean value)
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.limit
final long limit
Definition: CodedOutputStream.java:1881
com.google.protobuf.CodedOutputStream.writeBoolNoTag
final void writeBoolNoTag(final boolean value)
Definition: CodedOutputStream.java:446
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeFixed64NoTag
void writeFixed64NoTag(long value)
Definition: CodedOutputStream.java:1767
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.flushIfNotAvailable
void flushIfNotAvailable(int requiredSize)
Definition: CodedOutputStream.java:3055
com.google.protobuf.CodedOutputStream.writeStringNoTag
abstract void writeStringNoTag(String value)
com.google.protobuf.CodedOutputStream.writeSInt32
final void writeSInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:241
com.google.protobuf.WireFormat.WIRETYPE_FIXED64
static final int WIRETYPE_FIXED64
Definition: WireFormat.java:56
com.google.protobuf.CodedOutputStream.writeFixed64NoTag
abstract void writeFixed64NoTag(long value)
com.google.protobuf.CodedOutputStream.getTotalBytesWritten
abstract int getTotalBytesWritten()
com.google.protobuf.CodedOutputStream.HeapNioEncoder.flush
void flush()
Definition: CodedOutputStream.java:1544
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.doFlush
void doFlush()
Definition: CodedOutputStream.java:2698
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.initialPosition
final int initialPosition
Definition: CodedOutputStream.java:1557
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeByteBuffer
void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
Definition: CodedOutputStream.java:1632
com.google.protobuf.CodedOutputStream.encodeZigZag64
static long encodeZigZag64(final long n)
Definition: CodedOutputStream.java:912
com.google.protobuf.CodedOutputStream.computeByteBufferSizeNoTag
static int computeByteBufferSizeNoTag(final ByteBuffer value)
Definition: CodedOutputStream.java:871
com.google.protobuf.CodedOutputStream.writeSFixed32
final void writeSFixed32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:250
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.out
final OutputStream out
Definition: CodedOutputStream.java:2709
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeLazy
final void writeLazy(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1455
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeMessage
final void writeMessage(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1271
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeFixed64NoTag
void writeFixed64NoTag(long value)
Definition: CodedOutputStream.java:2116
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.position
long position
Definition: CodedOutputStream.java:1883
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder
Definition: CodedOutputStream.java:1876
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.flush
void flush()
Definition: CodedOutputStream.java:2209
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.write
void write(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2122
com.google.protobuf.CodedOutputStream.computeByteBufferSize
static int computeByteBufferSize(final int fieldNumber, final ByteBuffer value)
Definition: CodedOutputStream.java:644
com.google.protobuf
Definition: ProtoCaliperBenchmark.java:2
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeTag
void writeTag(final int fieldNumber, final int wireType)
Definition: CodedOutputStream.java:2720
com.google.protobuf.CodedOutputStream.writeFloat
final void writeFloat(final int fieldNumber, final float value)
Definition: CodedOutputStream.java:278
com.google.protobuf.CodedOutputStream.writeInt32NoTag
abstract void writeInt32NoTag(final int value)
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeInt32
void writeInt32(int fieldNumber, int value)
Definition: CodedOutputStream.java:1905
com.google.protobuf.CodedOutputStream.writeGroup
final void writeGroup(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1012
com.google.protobuf.Utf8
Definition: Utf8.java:76
com.google.protobuf.CodedOutputStream.computeMessageSetExtensionSize
static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:677
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value, final int offset, final int length)
Definition: CodedOutputStream.java:2470
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeTag
void writeTag(final int fieldNumber, final int wireType)
Definition: CodedOutputStream.java:1566
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeUInt32
void writeUInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1577
com.google.protobuf.CodedOutputStream.flush
abstract void flush()
com.google.protobuf.CodedOutputStream.computeGroupSizeNoTag
static int computeGroupSizeNoTag(final MessageLite value)
Definition: CodedOutputStream.java:1075
com.google.protobuf.CodedOutputStream.writeSInt64NoTag
final void writeSInt64NoTag(final long value)
Definition: CodedOutputStream.java:422
com.google.protobuf.WireFormat
Definition: WireFormat.java:45
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeBytesNoTag
void writeBytesNoTag(final ByteString value)
Definition: CodedOutputStream.java:2799
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeFixed32NoTag
void writeFixed32NoTag(int value)
Definition: CodedOutputStream.java:2082
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.write
void write(byte value)
Definition: CodedOutputStream.java:2012
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeByteArrayNoTag
void writeByteArrayNoTag(final byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2491
com.google.protobuf.CodedOutputStream.computeEnumSizeNoTag
static int computeEnumSizeNoTag(final int value)
Definition: CodedOutputStream.java:834
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.spaceLeft
int spaceLeft()
Definition: CodedOutputStream.java:2215
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeUInt64NoTag
void writeUInt64NoTag(long value)
Definition: CodedOutputStream.java:1750
com.google.protobuf.CodedOutputStream.ArrayEncoder
Definition: CodedOutputStream.java:1150
com.google.protobuf.CodedOutputStream.computeBytesSizeNoTag
static int computeBytesSizeNoTag(final ByteString value)
Definition: CodedOutputStream.java:861
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.repositionBuffer
void repositionBuffer(long pos)
Definition: CodedOutputStream.java:2224
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.flush
void flush()
Definition: CodedOutputStream.java:2655
com.google.protobuf.CodedOutputStream.ArrayEncoder.spaceLeft
final int spaceLeft()
Definition: CodedOutputStream.java:1516
bytes
uint8 bytes[10]
Definition: coded_stream_unittest.cc:153
com.google.protobuf.CodedOutputStream.computeFixed64SizeNoTag
static int computeFixed64SizeNoTag(@SuppressWarnings("unused") final long unused)
Definition: CodedOutputStream.java:800
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.doFlush
void doFlush()
Definition: CodedOutputStream.java:3061
com.google.protobuf.CodedOutputStream.ArrayEncoder.limit
final int limit
Definition: CodedOutputStream.java:1153
com.google.protobuf.CodedOutputStream.writeInt32
abstract void writeInt32(int fieldNumber, int value)
com.google.protobuf.CodedOutputStream.computeBoolSize
static int computeBoolSize(final int fieldNumber, final boolean value)
Definition: CodedOutputStream.java:603
com.google.protobuf.CodedOutputStream.ByteOutputEncoder
Definition: CodedOutputStream.java:2394
com.google.protobuf.CodedOutputStream.writeRawLittleEndian32
final void writeRawLittleEndian32(final int value)
Definition: CodedOutputStream.java:1133
com.google.protobuf.CodedOutputStream.writeUInt64
abstract void writeUInt64(int fieldNumber, long value)
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeFixed64
void writeFixed64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:1595
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeTag
final void writeTag(final int fieldNumber, final int wireType)
Definition: CodedOutputStream.java:1173
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeMessage
void writeMessage(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1639
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeRawMessageSetExtension
void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:2530
testing::internal::Double
FloatingPoint< double > Double
Definition: gtest-internal.h:429
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeInt32NoTag
void writeInt32NoTag(int value)
Definition: CodedOutputStream.java:1714
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeLazy
final void writeLazy(ByteBuffer value)
Definition: CodedOutputStream.java:1472
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeFixed32NoTag
final void writeFixed32NoTag(int value)
Definition: CodedOutputStream.java:1384
com.google.protobuf.CodedOutputStream.writeString
abstract void writeString(int fieldNumber, String value)
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeLazy
void writeLazy(ByteBuffer value)
Definition: CodedOutputStream.java:2157
com.google.protobuf.CodedOutputStream.spaceLeft
abstract int spaceLeft()
com.google.protobuf.CodedOutputStream.writeByteArrayNoTag
final void writeByteArrayNoTag(final byte[] value)
Definition: CodedOutputStream.java:468
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeByteBuffer
void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
Definition: CodedOutputStream.java:2478
com.google.protobuf.CodedOutputStream.writeFixed32
abstract void writeFixed32(int fieldNumber, int value)
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeUInt64NoTag
void writeUInt64NoTag(long value)
Definition: CodedOutputStream.java:2896
com.google.protobuf.CodedOutputStream.computeMessageSizeNoTag
static int computeMessageSizeNoTag(final MessageLite value)
Definition: CodedOutputStream.java:876
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value)
Definition: CodedOutputStream.java:2465
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.originalBuffer
final ByteBuffer originalBuffer
Definition: CodedOutputStream.java:1877
com.google.protobuf.CodedOutputStream.computeDoubleSizeNoTag
static int computeDoubleSizeNoTag(@SuppressWarnings("unused") final double unused)
Definition: CodedOutputStream.java:821
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeTag
void writeTag(int fieldNumber, int wireType)
Definition: CodedOutputStream.java:1900
com.google.protobuf.CodedOutputStream.encodeZigZag32
static int encodeZigZag32(final int n)
Definition: CodedOutputStream.java:898
com.google.protobuf.CodedOutputStream.writeRawBytes
final void writeRawBytes(final byte[] value, int offset, int length)
Definition: CodedOutputStream.java:343
com.google.protobuf.CodedOutputStream.logger
static final Logger logger
Definition: CodedOutputStream.java:60
com.google.protobuf.CodedOutputStream.writeRawByte
final void writeRawByte(final byte value)
Definition: CodedOutputStream.java:328
com.google.protobuf.CodedOutputStream.computeFixed32Size
static int computeFixed32Size(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:532
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeRawBytes
void writeRawBytes(ByteBuffer value)
Definition: CodedOutputStream.java:2033
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.write
void write(ByteBuffer value)
Definition: CodedOutputStream.java:3017
com.google.protobuf.ExperimentalApi
Definition: ExperimentalApi.java:62
com.google.protobuf.CodedOutputStream.computeFixed32SizeNoTag
static int computeFixed32SizeNoTag(@SuppressWarnings("unused") final int unused)
Definition: CodedOutputStream.java:749
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeMessageSetExtension
void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:1652
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeInt32NoTag
void writeInt32NoTag(int value)
Definition: CodedOutputStream.java:2560
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.buffer
final ByteBuffer buffer
Definition: CodedOutputStream.java:1556
com.google.protobuf.CodedOutputStream.LITTLE_ENDIAN_32_SIZE
static final int LITTLE_ENDIAN_32_SIZE
Definition: CodedOutputStream.java:67
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.oneVarintLimit
final long oneVarintLimit
Definition: CodedOutputStream.java:1882
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeBytesNoTag
void writeBytesNoTag(final ByteString value)
Definition: CodedOutputStream.java:2485
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.bufferPos
int bufferPos(long pos)
Definition: CodedOutputStream.java:2228
testing::internal::Float
FloatingPoint< float > Float
Definition: gtest-internal.h:428
com.google.protobuf.CodedOutputStream.writeFixed32NoTag
abstract void writeFixed32NoTag(int value)
offset
GLintptr offset
Definition: glcorearb.h:2944
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeByteBuffer
void writeByteBuffer(int fieldNumber, ByteBuffer value)
Definition: CodedOutputStream.java:1965
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeFixed32NoTag
void writeFixed32NoTag(int value)
Definition: CodedOutputStream.java:1741
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeFixed32
void writeFixed32(int fieldNumber, int value)
Definition: CodedOutputStream.java:1917
com.google.protobuf.CodedOutputStream.computeEnumSize
static int computeEnumSize(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:612
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeInt32
void writeInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2725
com.google.protobuf.CodedOutputStream.ArrayEncoder.buffer
final byte[] buffer
Definition: CodedOutputStream.java:1151
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeUInt32
void writeUInt32(int fieldNumber, int value)
Definition: CodedOutputStream.java:1911
com.google.protobuf.CodedOutputStream.write
abstract void write(byte value)
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeByteArray
final void writeByteArray(final int fieldNumber, final byte[] value)
Definition: CodedOutputStream.java:1226
com.google.protobuf.CodedOutputStream.checkNoSpaceLeft
final void checkNoSpaceLeft()
Definition: CodedOutputStream.java:937
com.google.protobuf.CodedOutputStream.computeTagSize
static int computeTagSize(final int fieldNumber)
Definition: CodedOutputStream.java:709
com.google.protobuf.CodedOutputStream.computeRawVarint32Size
static int computeRawVarint32Size(final int value)
Definition: CodedOutputStream.java:1113
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeRawBytes
final void writeRawBytes(final ByteBuffer value)
Definition: CodedOutputStream.java:1260
com.google.protobuf.AbstractMessageLite
Definition: AbstractMessageLite.java:49
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeInt32
void writeInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2411
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeFixed32
void writeFixed32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1583
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeLazy
void writeLazy(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2670
com.google.protobuf.CodedOutputStream.HeapNioEncoder
Definition: CodedOutputStream.java:1530
com.google.protobuf.CodedOutputStream.computeInt64SizeNoTag
static int computeInt64SizeNoTag(final long value)
Definition: CodedOutputStream.java:762
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value)
Definition: CodedOutputStream.java:1619
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeRawMessageSetExtension
void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:2844
buffer::length
size_t length
Definition: buffer_processor.h:45
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.address
final long address
Definition: CodedOutputStream.java:1879
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeByteArray
void writeByteArray(int fieldNumber, byte[] value)
Definition: CodedOutputStream.java:1953
com.google.protobuf.CodedOutputStream.ArrayEncoder.write
final void write(ByteBuffer value)
Definition: CodedOutputStream.java:1460
com.google.protobuf.CodedOutputStream.writeMessageSetExtension
abstract void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeBytes
void writeBytes(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:2459
com.google.protobuf.CodedOutputStream.writeDoubleNoTag
final void writeDoubleNoTag(final double value)
Definition: CodedOutputStream.java:441
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeBool
void writeBool(final int fieldNumber, final boolean value)
Definition: CodedOutputStream.java:2760
com.google.protobuf.CodedOutputStream.writeEnum
final void writeEnum(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:295
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.write
void write(ByteBuffer value)
Definition: CodedOutputStream.java:1792
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeString
void writeString(int fieldNumber, String value)
Definition: CodedOutputStream.java:1941
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeLazy
void writeLazy(ByteBuffer value)
Definition: CodedOutputStream.java:2685
com.google.protobuf.CodedOutputStream.writeMessage
abstract void writeMessage(final int fieldNumber, final MessageLite value)
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeUInt64
void writeUInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:2746
com.google.protobuf.CodedOutputStream.writeByteBuffer
abstract void writeByteBuffer(int fieldNumber, ByteBuffer value)
buffer
Definition: buffer_processor.h:43
byte
SETUP_TEARDOWN_TESTCONTEXT typedef uint8_t byte
Definition: test_stream.cpp:12
com.google.protobuf.CodedOutputStream.computeLazyFieldSizeNoTag
static int computeLazyFieldSizeNoTag(final LazyFieldLite value)
Definition: CodedOutputStream.java:856
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeStringNoTag
void writeStringNoTag(String value)
Definition: CodedOutputStream.java:1806
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeBytesNoTag
void writeBytesNoTag(ByteString value)
Definition: CodedOutputStream.java:2021
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeTag
void writeTag(final int fieldNumber, final int wireType)
Definition: CodedOutputStream.java:2406
com.google.protobuf.CodedOutputStream.writeTag
abstract void writeTag(int fieldNumber, int wireType)
position
intern position
Definition: array.c:487
com.google.protobuf.WireFormat.WIRETYPE_END_GROUP
static final int WIRETYPE_END_GROUP
Definition: WireFormat.java:59
com.google.protobuf.CodedOutputStream.computeSFixed64Size
static int computeSFixed64Size(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:580
com.google.protobuf.CodedOutputStream.computeUInt64SizeNoTag
static int computeUInt64SizeNoTag(long value)
Definition: CodedOutputStream.java:770
com.google.protobuf.CodedOutputStream.writeBytesNoTag
abstract void writeBytesNoTag(final ByteString value)
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeMessageNoTag
final void writeMessageNoTag(final MessageLite value)
Definition: CodedOutputStream.java:1304
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeBool
void writeBool(final int fieldNumber, final boolean value)
Definition: CodedOutputStream.java:1601
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeBool
final void writeBool(final int fieldNumber, final boolean value)
Definition: CodedOutputStream.java:1208
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeBytes
void writeBytes(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:2773
com.google.protobuf.LazyFieldLite
Definition: LazyFieldLite.java:56
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeRawBytes
void writeRawBytes(final ByteBuffer value)
Definition: CodedOutputStream.java:2497
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeUInt64
void writeUInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:2432
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeRawBytes
void writeRawBytes(final ByteBuffer value)
Definition: CodedOutputStream.java:2811
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeBytesNoTag
void writeBytesNoTag(final ByteString value)
Definition: CodedOutputStream.java:1691
com.google.protobuf.CodedOutputStream.writeSInt64
final void writeSInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:264
com.google.protobuf.CodedOutputStream.computeRawVarint64Size
static int computeRawVarint64Size(long value)
Definition: CodedOutputStream.java:1123
com.google.protobuf.CodedOutputStream.writeEnumNoTag
final void writeEnumNoTag(final int value)
Definition: CodedOutputStream.java:454
com.google.protobuf.CodedOutputStream.computeSInt32Size
static int computeSInt32Size(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:524
com.google.protobuf.CodedOutputStream.writeSInt32NoTag
final void writeSInt32NoTag(final int value)
Definition: CodedOutputStream.java:399
com.google.protobuf.WireFormat.WIRETYPE_FIXED32
static final int WIRETYPE_FIXED32
Definition: WireFormat.java:60
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeRawMessageSetExtension
void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:1661
com.google.protobuf.CodedOutputStream.CodedOutputStream
CodedOutputStream()
Definition: CodedOutputStream.java:224
com.google.protobuf.CodedOutputStream.computeStringSize
static int computeStringSize(final int fieldNumber, final String value)
Definition: CodedOutputStream.java:620
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeFixed32
void writeFixed32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2425
n
GLdouble n
Definition: glcorearb.h:4153
com.google.protobuf.WireFormat.WIRETYPE_START_GROUP
static final int WIRETYPE_START_GROUP
Definition: WireFormat.java:58
com.google.protobuf.CodedOutputStream.computeInt64Size
static int computeInt64Size(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:548
Level
Level
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.out
final ByteOutput out
Definition: CodedOutputStream.java:2395
com.google.protobuf.CodedOutputStream.computeFloatSizeNoTag
static int computeFloatSizeNoTag(@SuppressWarnings("unused") final float unused)
Definition: CodedOutputStream.java:813
com.google.protobuf.CodedOutputStream.writeRawBytes
final void writeRawBytes(final byte[] value)
Definition: CodedOutputStream.java:338
com.google.protobuf.CodedOutputStream.ArrayEncoder.getTotalBytesWritten
final int getTotalBytesWritten()
Definition: CodedOutputStream.java:1521
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeUInt64NoTag
final void writeUInt64NoTag(long value)
Definition: CodedOutputStream.java:1397
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeString
final void writeString(final int fieldNumber, final String value)
Definition: CodedOutputStream.java:1214
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeLazy
void writeLazy(ByteBuffer value)
Definition: CodedOutputStream.java:1801
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeInt32
void writeInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1571
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeMessage
void writeMessage(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:2822
java
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeByteBuffer
void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
Definition: CodedOutputStream.java:2792
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder
Definition: CodedOutputStream.java:1554
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeMessage
void writeMessage(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:2508
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.write
void write(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1776
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeMessage
void writeMessage(int fieldNumber, MessageLite value)
Definition: CodedOutputStream.java:1972
com.google.protobuf.CodedOutputStream.writeRawByte
final void writeRawByte(final int value)
Definition: CodedOutputStream.java:333
com.google.protobuf.CodedOutputStream.computeByteArraySize
static int computeByteArraySize(final int fieldNumber, final byte[] value)
Definition: CodedOutputStream.java:636
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeInt32
final void writeInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1178
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeUInt32
void writeUInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2418
com.google.protobuf.CodedOutputStream.writeUInt64NoTag
abstract void writeUInt64NoTag(long value)
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeMessageNoTag
void writeMessageNoTag(final MessageLite value)
Definition: CodedOutputStream.java:2853
com.google.protobuf.CodedOutputStream.OutputStreamEncoder
Definition: CodedOutputStream.java:2708
com.google.protobuf.CodedOutputStream.ArrayEncoder.position
int position
Definition: CodedOutputStream.java:1154
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeUInt64
final void writeUInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:1196
com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED
static final int WIRETYPE_LENGTH_DELIMITED
Definition: WireFormat.java:57
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.getTotalBytesWritten
int getTotalBytesWritten()
Definition: CodedOutputStream.java:1859
com.google.protobuf.CodedOutputStream.computeSInt64Size
static int computeSInt64Size(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:564
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeFixed64
void writeFixed64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:2439
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.write
void write(byte value)
Definition: CodedOutputStream.java:2551
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.write
void write(ByteBuffer value)
Definition: CodedOutputStream.java:2145
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeUInt32NoTag
void writeUInt32NoTag(int value)
Definition: CodedOutputStream.java:2570
com.google.protobuf.CodedOutputStream.computeUInt32Size
static int computeUInt32Size(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:516
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeLazy
void writeLazy(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2140
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeByteArrayNoTag
void writeByteArrayNoTag(final byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2805
com.google.protobuf.CodedOutputStream.writeSFixed32NoTag
final void writeSFixed32NoTag(final int value)
Definition: CodedOutputStream.java:408
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeLazy
void writeLazy(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:3012
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value, final int offset, final int length)
Definition: CodedOutputStream.java:2784
com.google.protobuf.CodedOutputStream.computeSFixed32Size
static int computeSFixed32Size(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:540
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.getTotalBytesWritten
int getTotalBytesWritten()
Definition: CodedOutputStream.java:2220
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(ByteBuffer byteBuffer, @SuppressWarnings("unused") int unused)
Definition: CodedOutputStream.java:199
com.google.protobuf.CodedOutputStream.serializationDeterministic
boolean serializationDeterministic
Definition: CodedOutputStream.java:189
com.google.protobuf.CodedOutputStream.useDeterministicSerialization
void useDeterministicSerialization()
Definition: CodedOutputStream.java:181
com.google.protobuf.CodedOutputStream.writeRawVarint32
final void writeRawVarint32(int value)
Definition: CodedOutputStream.java:1092
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeString
void writeString(final int fieldNumber, final String value)
Definition: CodedOutputStream.java:1607
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(final byte[] flatArray, final int offset, final int length)
Definition: CodedOutputStream.java:124
com.google.protobuf.CodedOutputStream.writeInt64NoTag
final void writeInt64NoTag(final long value)
Definition: CodedOutputStream.java:413
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeString
void writeString(final int fieldNumber, final String value)
Definition: CodedOutputStream.java:2767
com.google.protobuf.CodedOutputStream.computeFloatSize
static int computeFloatSize(final int fieldNumber, final float value)
Definition: CodedOutputStream.java:588
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeFixed32
final void writeFixed32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1190
com.google.protobuf.CodedOutputStream.writeUInt32
abstract void writeUInt32(int fieldNumber, int value)
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.encode
void encode(String value)
Definition: CodedOutputStream.java:1863
com.google
com
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeStringNoTag
void writeStringNoTag(String value)
Definition: CodedOutputStream.java:2594
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.initialPosition
final long initialPosition
Definition: CodedOutputStream.java:1880
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(final OutputStream output)
Definition: CodedOutputStream.java:92
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeUInt32
final void writeUInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:1184
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeInt32NoTag
void writeInt32NoTag(int value)
Definition: CodedOutputStream.java:2874
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeMessageNoTag
void writeMessageNoTag(final MessageLite value)
Definition: CodedOutputStream.java:1670
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeFixed32
void writeFixed32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2739
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeByteArrayNoTag
void writeByteArrayNoTag(final byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1697
com.google.protobuf.CodedOutputStream.writeByteArray
abstract void writeByteArray(int fieldNumber, byte[] value)
com.google.protobuf.CodedOutputStream.writeMessageNoTag
abstract void writeMessageNoTag(final MessageLite value)
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.write
void write(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2979
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeStringNoTag
void writeStringNoTag(String value)
Definition: CodedOutputStream.java:2908
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeInt32NoTag
final void writeInt32NoTag(int value)
Definition: CodedOutputStream.java:1326
com.google.protobuf.CodedOutputStream.writeUInt32NoTag
abstract void writeUInt32NoTag(int value)
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeRawMessageSetExtension
final void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:1295
com.google.protobuf.CodedOutputStream.writeSFixed64
final void writeSFixed64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:273
com.google.protobuf.CodedOutputStream.computeSFixed64SizeNoTag
static int computeSFixed64SizeNoTag(@SuppressWarnings("unused") final long unused)
Definition: CodedOutputStream.java:805
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeFixed64
void writeFixed64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:2753
com.google.protobuf.CodedOutputStream.writeRawVarint64
final void writeRawVarint64(long value)
Definition: CodedOutputStream.java:1102
com.google.protobuf.CodedOutputStream.DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZE
Definition: CodedOutputStream.java:70
com.google.protobuf.CodedOutputStream.OutOfSpaceException.serialVersionUID
static final long serialVersionUID
Definition: CodedOutputStream.java:948
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeByteArrayNoTag
void writeByteArrayNoTag(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:2027
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeUInt32NoTag
void writeUInt32NoTag(int value)
Definition: CodedOutputStream.java:1724
com.google.protobuf.Internal
Definition: Internal.java:54
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeInt32NoTag
void writeInt32NoTag(int value)
Definition: CodedOutputStream.java:2044
com.google.protobuf.CodedOutputStream
Definition: CodedOutputStream.java:59
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeBool
void writeBool(int fieldNumber, boolean value)
Definition: CodedOutputStream.java:1935
com.google.protobuf.CodedOutputStream.computeLazyFieldMessageSetExtensionSize
static int computeLazyFieldMessageSetExtensionSize(final int fieldNumber, final LazyFieldLite value)
Definition: CodedOutputStream.java:699
com.google.protobuf.CodedOutputStream.computeInt32SizeNoTag
static int computeInt32SizeNoTag(final int value)
Definition: CodedOutputStream.java:717
com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder
Definition: CodedOutputStream.java:2234
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeString
void writeString(final int fieldNumber, final String value)
Definition: CodedOutputStream.java:2453
com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder.spaceLeft
final int spaceLeft()
Definition: CodedOutputStream.java:2253
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeUInt32NoTag
void writeUInt32NoTag(int value)
Definition: CodedOutputStream.java:2054
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.write
void write(byte value)
Definition: CodedOutputStream.java:1682
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeBytes
void writeBytes(int fieldNumber, ByteString value)
Definition: CodedOutputStream.java:1947
com.google.protobuf.CodedOutputStream.OutOfSpaceException
Definition: CodedOutputStream.java:947
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeRawBytes
void writeRawBytes(final ByteBuffer value)
Definition: CodedOutputStream.java:1703
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeLazy
void writeLazy(ByteBuffer value)
Definition: CodedOutputStream.java:3051
com.google.protobuf.CodedOutputStream.computeStringSizeNoTag
static int computeStringSizeNoTag(final String value)
Definition: CodedOutputStream.java:839
com.google.protobuf.CodedOutputStream.HeapNioEncoder.byteBuffer
final ByteBuffer byteBuffer
Definition: CodedOutputStream.java:1531
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeByteArray
final void writeByteArray(final int fieldNumber, final byte[] value, final int offset, final int length)
Definition: CodedOutputStream.java:1231
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
com.google.protobuf.CodedOutputStream.HeapNioEncoder.initialPosition
int initialPosition
Definition: CodedOutputStream.java:1532
com.google.protobuf.CodedOutputStream.HAS_UNSAFE_ARRAY_OPERATIONS
static final boolean HAS_UNSAFE_ARRAY_OPERATIONS
Definition: CodedOutputStream.java:61
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeFixed64
final void writeFixed64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:1202
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeByteBuffer
final void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
Definition: CodedOutputStream.java:1239
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeMessageNoTag
void writeMessageNoTag(final MessageLite value)
Definition: CodedOutputStream.java:2539
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value, final int offset, final int length)
Definition: CodedOutputStream.java:1624
com.google.protobuf.CodedOutputStream.computeMessageSize
static int computeMessageSize(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:660
com.google.protobuf.CodedOutputStream.writeRawMessageSetExtension
abstract void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
com.google.protobuf.CodedOutputStream.ArrayEncoder.offset
final int offset
Definition: CodedOutputStream.java:1152
com.google.protobuf.CodedOutputStream.ArrayEncoder.flush
void flush()
Definition: CodedOutputStream.java:1511
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.originalBuffer
final ByteBuffer originalBuffer
Definition: CodedOutputStream.java:1555
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeUInt32
void writeUInt32(final int fieldNumber, final int value)
Definition: CodedOutputStream.java:2732
com.google.protobuf.CodedOutputStream.computeUInt32SizeNoTag
static int computeUInt32SizeNoTag(final int value)
Definition: CodedOutputStream.java:727
com.google.protobuf.CodedOutputStream.computeBytesSize
static int computeBytesSize(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:628
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeByteArrayNoTag
final void writeByteArrayNoTag(final byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1253
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.writeByteArray
void writeByteArray(final int fieldNumber, final byte[] value)
Definition: CodedOutputStream.java:2779
com.google.protobuf.CodedOutputStream.newInstance
static CodedOutputStream newInstance(final OutputStream output, final int bufferSize)
Definition: CodedOutputStream.java:104
com.google.protobuf.CodedOutputStream.ArrayEncoder.write
final void write(byte[] value, int offset, int length)
Definition: CodedOutputStream.java:1444
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeStringNoTag
final void writeStringNoTag(String value)
Definition: CodedOutputStream.java:1477
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeBytes
final void writeBytes(final int fieldNumber, final ByteString value)
Definition: CodedOutputStream.java:1220
com.google.protobuf.CodedOutputStream.ArrayEncoder.writeUInt32NoTag
final void writeUInt32NoTag(int value)
Definition: CodedOutputStream.java:1336
com.google.protobuf.CodedOutputStream.computeSInt64SizeNoTag
static int computeSInt64SizeNoTag(final long value)
Definition: CodedOutputStream.java:795
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.buffer
final ByteBuffer buffer
Definition: CodedOutputStream.java:1878
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeStringNoTag
void writeStringNoTag(String value)
Definition: CodedOutputStream.java:2162
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.spaceLeft
int spaceLeft()
Definition: CodedOutputStream.java:1854
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeFixed32NoTag
void writeFixed32NoTag(final int value)
Definition: CodedOutputStream.java:2576
com.google.protobuf.CodedOutputStream.computeByteArraySizeNoTag
static int computeByteArraySizeNoTag(final byte[] value)
Definition: CodedOutputStream.java:866
com.google.protobuf.CodedOutputStream.writeDouble
final void writeDouble(final int fieldNumber, final double value)
Definition: CodedOutputStream.java:283
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.writeUInt64
void writeUInt64(final int fieldNumber, final long value)
Definition: CodedOutputStream.java:1589
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeFixed64NoTag
void writeFixed64NoTag(final long value)
Definition: CodedOutputStream.java:2588
com.google.protobuf.MessageLite
Definition: MessageLite.java:65
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.writeMessageSetExtension
void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
Definition: CodedOutputStream.java:2521
com.google.protobuf.CodedOutputStream.OutputStreamEncoder.write
void write(byte value)
Definition: CodedOutputStream.java:2865
com.google.protobuf.ByteOutput.writeLazy
abstract void writeLazy(byte[] value, int offset, int length)
com.google.protobuf.CodedOutputStream.ByteOutputEncoder.flushIfNotAvailable
void flushIfNotAvailable(int requiredSize)
Definition: CodedOutputStream.java:2692
com.google.protobuf.ByteString
Definition: ByteString.java:67
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeMessageSetExtension
void writeMessageSetExtension(int fieldNumber, MessageLite value)
Definition: CodedOutputStream.java:1984
com.google.protobuf.CodedOutputStream.ArrayEncoder.write
final void write(byte value)
Definition: CodedOutputStream.java:1316
com.google.protobuf.CodedOutputStream.writeFloatNoTag
final void writeFloatNoTag(final float value)
Definition: CodedOutputStream.java:436
com.google.protobuf.CodedOutputStream.SafeDirectNioEncoder.flush
void flush()
Definition: CodedOutputStream.java:1848
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder.writeRawMessageSetExtension
void writeRawMessageSetExtension(int fieldNumber, ByteString value)
Definition: CodedOutputStream.java:1992


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48