| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 if (value == null) return; | 710 if (value == null) return; |
| 711 var bytes = jspb.utils.byteSourceToUint8Array(value); | 711 var bytes = jspb.utils.byteSourceToUint8Array(value); |
| 712 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); | 712 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); |
| 713 this.encoder_.writeUnsignedVarint32(bytes.length); | 713 this.encoder_.writeUnsignedVarint32(bytes.length); |
| 714 this.appendUint8Array_(bytes); | 714 this.appendUint8Array_(bytes); |
| 715 }; | 715 }; |
| 716 | 716 |
| 717 | 717 |
| 718 /** | 718 /** |
| 719 * Writes a message to the buffer. | 719 * Writes a message to the buffer. |
| 720 * @template MessageType | |
| 721 * @param {number} field The field number. | 720 * @param {number} field The field number. |
| 722 * @param {?MessageType} value The message to write. | 721 * @param {?MessageType} value The message to write. |
| 723 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value | 722 * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback |
| 724 * to write and the writer to write it with. | 723 * Will be invoked with the value to write and the writer to write it with. |
| 724 * @template MessageType |
| 725 * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace |
| 726 * the null in blah|null with none. This is necessary because the compiler will |
| 727 * infer MessageType to be nullable if the value parameter is nullable. |
| 728 * @template MessageTypeNonNull := |
| 729 * cond(isUnknown(MessageType), unknown(), |
| 730 * mapunion(MessageType, (X) => |
| 731 * cond(eq(X, 'null'), none(), X))) |
| 732 * =: |
| 725 */ | 733 */ |
| 726 jspb.BinaryWriter.prototype.writeMessage = function( | 734 jspb.BinaryWriter.prototype.writeMessage = function( |
| 727 field, value, writerCallback) { | 735 field, value, writerCallback) { |
| 728 if (value == null) return; | 736 if (value == null) return; |
| 729 var bookmark = this.beginDelimited_(field); | 737 var bookmark = this.beginDelimited_(field); |
| 730 writerCallback(value, this); | 738 writerCallback(value, this); |
| 731 this.endDelimited_(bookmark); | 739 this.endDelimited_(bookmark); |
| 732 }; | 740 }; |
| 733 | 741 |
| 734 | 742 |
| 735 /** | 743 /** |
| 736 * Writes a group message to the buffer. | 744 * Writes a group message to the buffer. |
| 737 * | 745 * |
| 738 * @template MessageType | |
| 739 * @param {number} field The field number. | 746 * @param {number} field The field number. |
| 740 * @param {?MessageType} value The message to write, wrapped with START_GROUP / | 747 * @param {?MessageType} value The message to write, wrapped with START_GROUP / |
| 741 * END_GROUP tags. Will be a no-op if 'value' is null. | 748 * END_GROUP tags. Will be a no-op if 'value' is null. |
| 742 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value | 749 * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback |
| 743 * to write and the writer to write it with. | 750 * Will be invoked with the value to write and the writer to write it with. |
| 751 * @template MessageType |
| 752 * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace |
| 753 * the null in blah|null with none. This is necessary because the compiler will |
| 754 * infer MessageType to be nullable if the value parameter is nullable. |
| 755 * @template MessageTypeNonNull := |
| 756 * cond(isUnknown(MessageType), unknown(), |
| 757 * mapunion(MessageType, (X) => |
| 758 * cond(eq(X, 'null'), none(), X))) |
| 759 * =: |
| 744 */ | 760 */ |
| 745 jspb.BinaryWriter.prototype.writeGroup = function( | 761 jspb.BinaryWriter.prototype.writeGroup = function( |
| 746 field, value, writerCallback) { | 762 field, value, writerCallback) { |
| 747 if (value == null) return; | 763 if (value == null) return; |
| 748 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); | 764 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); |
| 749 writerCallback(value, this); | 765 writerCallback(value, this); |
| 750 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); | 766 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); |
| 751 }; | 767 }; |
| 752 | 768 |
| 753 | 769 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 } | 1131 } |
| 1116 }; | 1132 }; |
| 1117 | 1133 |
| 1118 | 1134 |
| 1119 /** | 1135 /** |
| 1120 * Writes an array of messages to the buffer. | 1136 * Writes an array of messages to the buffer. |
| 1121 * @template MessageType | 1137 * @template MessageType |
| 1122 * @param {number} field The field number. | 1138 * @param {number} field The field number. |
| 1123 * @param {?Array.<MessageType>} value The array of messages to | 1139 * @param {?Array.<MessageType>} value The array of messages to |
| 1124 * write. | 1140 * write. |
| 1125 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value | 1141 * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback |
| 1126 * to write and the writer to write it with. | 1142 * Will be invoked with the value to write and the writer to write it with. |
| 1127 */ | 1143 */ |
| 1128 jspb.BinaryWriter.prototype.writeRepeatedMessage = function( | 1144 jspb.BinaryWriter.prototype.writeRepeatedMessage = function( |
| 1129 field, value, writerCallback) { | 1145 field, value, writerCallback) { |
| 1130 if (value == null) return; | 1146 if (value == null) return; |
| 1131 for (var i = 0; i < value.length; i++) { | 1147 for (var i = 0; i < value.length; i++) { |
| 1132 var bookmark = this.beginDelimited_(field); | 1148 var bookmark = this.beginDelimited_(field); |
| 1133 writerCallback(value[i], this); | 1149 writerCallback(value[i], this); |
| 1134 this.endDelimited_(bookmark); | 1150 this.endDelimited_(bookmark); |
| 1135 } | 1151 } |
| 1136 }; | 1152 }; |
| 1137 | 1153 |
| 1138 | 1154 |
| 1139 /** | 1155 /** |
| 1140 * Writes an array of group messages to the buffer. | 1156 * Writes an array of group messages to the buffer. |
| 1141 * @template MessageType | 1157 * @template MessageType |
| 1142 * @param {number} field The field number. | 1158 * @param {number} field The field number. |
| 1143 * @param {?Array.<MessageType>} value The array of messages to | 1159 * @param {?Array.<MessageType>} value The array of messages to |
| 1144 * write. | 1160 * write. |
| 1145 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value | 1161 * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback |
| 1146 * to write and the writer to write it with. | 1162 * Will be invoked with the value to write and the writer to write it with. |
| 1147 */ | 1163 */ |
| 1148 jspb.BinaryWriter.prototype.writeRepeatedGroup = function( | 1164 jspb.BinaryWriter.prototype.writeRepeatedGroup = function( |
| 1149 field, value, writerCallback) { | 1165 field, value, writerCallback) { |
| 1150 if (value == null) return; | 1166 if (value == null) return; |
| 1151 for (var i = 0; i < value.length; i++) { | 1167 for (var i = 0; i < value.length; i++) { |
| 1152 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); | 1168 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); |
| 1153 writerCallback(value[i], this); | 1169 writerCallback(value[i], this); |
| 1154 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); | 1170 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); |
| 1155 } | 1171 } |
| 1156 }; | 1172 }; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 * @param {?Array.<string>} value The array of hashes to write. | 1568 * @param {?Array.<string>} value The array of hashes to write. |
| 1553 */ | 1569 */ |
| 1554 jspb.BinaryWriter.prototype.writePackedVarintHash64 = function(field, value) { | 1570 jspb.BinaryWriter.prototype.writePackedVarintHash64 = function(field, value) { |
| 1555 if (value == null || !value.length) return; | 1571 if (value == null || !value.length) return; |
| 1556 var bookmark = this.beginDelimited_(field); | 1572 var bookmark = this.beginDelimited_(field); |
| 1557 for (var i = 0; i < value.length; i++) { | 1573 for (var i = 0; i < value.length; i++) { |
| 1558 this.encoder_.writeVarintHash64(value[i]); | 1574 this.encoder_.writeVarintHash64(value[i]); |
| 1559 } | 1575 } |
| 1560 this.endDelimited_(bookmark); | 1576 this.endDelimited_(bookmark); |
| 1561 }; | 1577 }; |
| OLD | NEW |