Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: third_party/protobuf/js/binary/writer.js

Issue 2600753002: Reverts third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/js/binary/utils.js ('k') | third_party/protobuf/js/commonjs/export.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 * @private 428 * @private
429 */ 429 */
430 jspb.BinaryWriter.prototype.writeZigzagVarint64_ = function(field, value) { 430 jspb.BinaryWriter.prototype.writeZigzagVarint64_ = function(field, value) {
431 if (value == null) return; 431 if (value == null) return;
432 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT); 432 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
433 this.encoder_.writeZigzagVarint64(value); 433 this.encoder_.writeZigzagVarint64(value);
434 }; 434 };
435 435
436 436
437 /** 437 /**
438 * Writes a zigzag varint field to the buffer without range checking.
439 * @param {number} field The field number.
440 * @param {string?} value The value to write.
441 * @private
442 */
443 jspb.BinaryWriter.prototype.writeZigzagVarint64String_ = function(
444 field, value) {
445 if (value == null) return;
446 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
447 this.encoder_.writeZigzagVarint64String(value);
448 };
449
450
451 /**
452 * Writes an int32 field to the buffer. Numbers outside the range [-2^31,2^31) 438 * Writes an int32 field to the buffer. Numbers outside the range [-2^31,2^31)
453 * will be truncated. 439 * will be truncated.
454 * @param {number} field The field number. 440 * @param {number} field The field number.
455 * @param {number?} value The value to write. 441 * @param {number?} value The value to write.
456 */ 442 */
457 jspb.BinaryWriter.prototype.writeInt32 = function(field, value) { 443 jspb.BinaryWriter.prototype.writeInt32 = function(field, value) {
458 if (value == null) return; 444 if (value == null) return;
459 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) && 445 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
460 (value < jspb.BinaryConstants.TWO_TO_31)); 446 (value < jspb.BinaryConstants.TWO_TO_31));
461 this.writeSignedVarint32_(field, value); 447 this.writeSignedVarint32_(field, value);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 */ 568 */
583 jspb.BinaryWriter.prototype.writeSint64 = function(field, value) { 569 jspb.BinaryWriter.prototype.writeSint64 = function(field, value) {
584 if (value == null) return; 570 if (value == null) return;
585 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) && 571 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
586 (value < jspb.BinaryConstants.TWO_TO_63)); 572 (value < jspb.BinaryConstants.TWO_TO_63));
587 this.writeZigzagVarint64_(field, value); 573 this.writeZigzagVarint64_(field, value);
588 }; 574 };
589 575
590 576
591 /** 577 /**
592 * Writes a sint64 field to the buffer. Numbers outside the range [-2^63,2^63)
593 * will be truncated.
594 * @param {number} field The field number.
595 * @param {string?} value The decimal string to write.
596 */
597 jspb.BinaryWriter.prototype.writeSint64String = function(field, value) {
598 if (value == null) return;
599 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
600 (value < jspb.BinaryConstants.TWO_TO_63));
601 this.writeZigzagVarint64String_(field, value);
602 };
603
604
605 /**
606 * Writes a fixed32 field to the buffer. Numbers outside the range [0,2^32) 578 * Writes a fixed32 field to the buffer. Numbers outside the range [0,2^32)
607 * will be truncated. 579 * will be truncated.
608 * @param {number} field The field number. 580 * @param {number} field The field number.
609 * @param {number?} value The value to write. 581 * @param {number?} value The value to write.
610 */ 582 */
611 jspb.BinaryWriter.prototype.writeFixed32 = function(field, value) { 583 jspb.BinaryWriter.prototype.writeFixed32 = function(field, value) {
612 if (value == null) return; 584 if (value == null) return;
613 goog.asserts.assert((value >= 0) && 585 goog.asserts.assert((value >= 0) &&
614 (value < jspb.BinaryConstants.TWO_TO_32)); 586 (value < jspb.BinaryConstants.TWO_TO_32));
615 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32); 587 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
(...skipping 10 matching lines...) Expand all
626 jspb.BinaryWriter.prototype.writeFixed64 = function(field, value) { 598 jspb.BinaryWriter.prototype.writeFixed64 = function(field, value) {
627 if (value == null) return; 599 if (value == null) return;
628 goog.asserts.assert((value >= 0) && 600 goog.asserts.assert((value >= 0) &&
629 (value < jspb.BinaryConstants.TWO_TO_64)); 601 (value < jspb.BinaryConstants.TWO_TO_64));
630 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64); 602 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
631 this.encoder_.writeUint64(value); 603 this.encoder_.writeUint64(value);
632 }; 604 };
633 605
634 606
635 /** 607 /**
636 * Writes a fixed64 field (with value as a string) to the buffer.
637 * @param {number} field The field number.
638 * @param {string?} value The value to write.
639 */
640 jspb.BinaryWriter.prototype.writeFixed64String = function(field, value) {
641 if (value == null) return;
642 var num = jspb.arith.UInt64.fromString(value);
643 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
644 this.encoder_.writeSplitFixed64(num.lo, num.hi);
645 };
646
647
648 /**
649 * Writes a sfixed32 field to the buffer. Numbers outside the range 608 * Writes a sfixed32 field to the buffer. Numbers outside the range
650 * [-2^31,2^31) will be truncated. 609 * [-2^31,2^31) will be truncated.
651 * @param {number} field The field number. 610 * @param {number} field The field number.
652 * @param {number?} value The value to write. 611 * @param {number?} value The value to write.
653 */ 612 */
654 jspb.BinaryWriter.prototype.writeSfixed32 = function(field, value) { 613 jspb.BinaryWriter.prototype.writeSfixed32 = function(field, value) {
655 if (value == null) return; 614 if (value == null) return;
656 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) && 615 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
657 (value < jspb.BinaryConstants.TWO_TO_31)); 616 (value < jspb.BinaryConstants.TWO_TO_31));
658 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32); 617 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
(...skipping 10 matching lines...) Expand all
669 jspb.BinaryWriter.prototype.writeSfixed64 = function(field, value) { 628 jspb.BinaryWriter.prototype.writeSfixed64 = function(field, value) {
670 if (value == null) return; 629 if (value == null) return;
671 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) && 630 goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
672 (value < jspb.BinaryConstants.TWO_TO_63)); 631 (value < jspb.BinaryConstants.TWO_TO_63));
673 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64); 632 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
674 this.encoder_.writeInt64(value); 633 this.encoder_.writeInt64(value);
675 }; 634 };
676 635
677 636
678 /** 637 /**
679 * Writes a sfixed64 string field to the buffer. Numbers outside the range
680 * [-2^63,2^63) will be truncated.
681 * @param {number} field The field number.
682 * @param {string?} value The value to write.
683 */
684 jspb.BinaryWriter.prototype.writeSfixed64String = function(field, value) {
685 if (value == null) return;
686 var num = jspb.arith.Int64.fromString(value);
687 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
688 this.encoder_.writeSplitFixed64(num.lo, num.hi);
689 };
690
691
692 /**
693 * Writes a single-precision floating point field to the buffer. Numbers 638 * Writes a single-precision floating point field to the buffer. Numbers
694 * requiring more than 32 bits of precision will be truncated. 639 * requiring more than 32 bits of precision will be truncated.
695 * @param {number} field The field number. 640 * @param {number} field The field number.
696 * @param {number?} value The value to write. 641 * @param {number?} value The value to write.
697 */ 642 */
698 jspb.BinaryWriter.prototype.writeFloat = function(field, value) { 643 jspb.BinaryWriter.prototype.writeFloat = function(field, value) {
699 if (value == null) return; 644 if (value == null) return;
700 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32); 645 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
701 this.encoder_.writeFloat(value); 646 this.encoder_.writeFloat(value);
702 }; 647 };
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (value == null) return; 710 if (value == null) return;
766 var bytes = jspb.utils.byteSourceToUint8Array(value); 711 var bytes = jspb.utils.byteSourceToUint8Array(value);
767 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 712 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
768 this.encoder_.writeUnsignedVarint32(bytes.length); 713 this.encoder_.writeUnsignedVarint32(bytes.length);
769 this.appendUint8Array_(bytes); 714 this.appendUint8Array_(bytes);
770 }; 715 };
771 716
772 717
773 /** 718 /**
774 * Writes a message to the buffer. 719 * Writes a message to the buffer.
720 * @template MessageType
775 * @param {number} field The field number. 721 * @param {number} field The field number.
776 * @param {?MessageType} value The message to write. 722 * @param {?MessageType} value The message to write.
777 * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback 723 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value
778 * Will be invoked with the value to write and the writer to write it with. 724 * to write and the writer to write it with.
779 * @template MessageType
780 * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace
781 * the null in blah|null with none. This is necessary because the compiler will
782 * infer MessageType to be nullable if the value parameter is nullable.
783 * @template MessageTypeNonNull :=
784 * cond(isUnknown(MessageType), unknown(),
785 * mapunion(MessageType, (X) =>
786 * cond(eq(X, 'null'), none(), X)))
787 * =:
788 */ 725 */
789 jspb.BinaryWriter.prototype.writeMessage = function( 726 jspb.BinaryWriter.prototype.writeMessage = function(
790 field, value, writerCallback) { 727 field, value, writerCallback) {
791 if (value == null) return; 728 if (value == null) return;
792 var bookmark = this.beginDelimited_(field); 729 var bookmark = this.beginDelimited_(field);
793 writerCallback(value, this); 730 writerCallback(value, this);
794 this.endDelimited_(bookmark); 731 this.endDelimited_(bookmark);
795 }; 732 };
796 733
797 734
798 /** 735 /**
799 * Writes a group message to the buffer. 736 * Writes a group message to the buffer.
800 * 737 *
738 * @template MessageType
801 * @param {number} field The field number. 739 * @param {number} field The field number.
802 * @param {?MessageType} value The message to write, wrapped with START_GROUP / 740 * @param {?MessageType} value The message to write, wrapped with START_GROUP /
803 * END_GROUP tags. Will be a no-op if 'value' is null. 741 * END_GROUP tags. Will be a no-op if 'value' is null.
804 * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback 742 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value
805 * Will be invoked with the value to write and the writer to write it with. 743 * to write and the writer to write it with.
806 * @template MessageType
807 * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace
808 * the null in blah|null with none. This is necessary because the compiler will
809 * infer MessageType to be nullable if the value parameter is nullable.
810 * @template MessageTypeNonNull :=
811 * cond(isUnknown(MessageType), unknown(),
812 * mapunion(MessageType, (X) =>
813 * cond(eq(X, 'null'), none(), X)))
814 * =:
815 */ 744 */
816 jspb.BinaryWriter.prototype.writeGroup = function( 745 jspb.BinaryWriter.prototype.writeGroup = function(
817 field, value, writerCallback) { 746 field, value, writerCallback) {
818 if (value == null) return; 747 if (value == null) return;
819 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); 748 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP);
820 writerCallback(value, this); 749 writerCallback(value, this);
821 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); 750 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP);
822 }; 751 };
823 752
824 753
(...skipping 19 matching lines...) Expand all
844 */ 773 */
845 jspb.BinaryWriter.prototype.writeVarintHash64 = function(field, value) { 774 jspb.BinaryWriter.prototype.writeVarintHash64 = function(field, value) {
846 if (value == null) return; 775 if (value == null) return;
847 goog.asserts.assert(value.length == 8); 776 goog.asserts.assert(value.length == 8);
848 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT); 777 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
849 this.encoder_.writeVarintHash64(value); 778 this.encoder_.writeVarintHash64(value);
850 }; 779 };
851 780
852 781
853 /** 782 /**
783 * Writes an array of numbers to the buffer as a repeated varint field.
784 * @param {number} field The field number.
785 * @param {?Array.<number>} value The array of ints to write.
786 * @private
787 */
788 jspb.BinaryWriter.prototype.writeRepeatedUnsignedVarint32_ =
789 function(field, value) {
790 if (value == null) return;
791 for (var i = 0; i < value.length; i++) {
792 this.writeUnsignedVarint32_(field, value[i]);
793 }
794 };
795
796
797 /**
798 * Writes an array of numbers to the buffer as a repeated varint field.
799 * @param {number} field The field number.
800 * @param {?Array.<number>} value The array of ints to write.
801 * @private
802 */
803 jspb.BinaryWriter.prototype.writeRepeatedSignedVarint32_ =
804 function(field, value) {
805 if (value == null) return;
806 for (var i = 0; i < value.length; i++) {
807 this.writeSignedVarint32_(field, value[i]);
808 }
809 };
810
811
812 /**
813 * Writes an array of numbers to the buffer as a repeated varint field.
814 * @param {number} field The field number.
815 * @param {?Array.<number>} value The array of ints to write.
816 * @private
817 */
818 jspb.BinaryWriter.prototype.writeRepeatedUnsignedVarint64_ =
819 function(field, value) {
820 if (value == null) return;
821 for (var i = 0; i < value.length; i++) {
822 this.writeUnsignedVarint64_(field, value[i]);
823 }
824 };
825
826
827 /**
828 * Writes an array of numbers to the buffer as a repeated varint field.
829 * @param {number} field The field number.
830 * @param {?Array.<number>} value The array of ints to write.
831 * @private
832 */
833 jspb.BinaryWriter.prototype.writeRepeatedSignedVarint64_ =
834 function(field, value) {
835 if (value == null) return;
836 for (var i = 0; i < value.length; i++) {
837 this.writeSignedVarint64_(field, value[i]);
838 }
839 };
840
841
842 /**
843 * Writes an array of numbers to the buffer as a repeated zigzag field.
844 * @param {number} field The field number.
845 * @param {?Array.<number>} value The array of ints to write.
846 * @private
847 */
848 jspb.BinaryWriter.prototype.writeRepeatedZigzag32_ = function(field, value) {
849 if (value == null) return;
850 for (var i = 0; i < value.length; i++) {
851 this.writeZigzagVarint32_(field, value[i]);
852 }
853 };
854
855
856 /**
857 * Writes an array of numbers to the buffer as a repeated zigzag field.
858 * @param {number} field The field number.
859 * @param {?Array.<number>} value The array of ints to write.
860 * @private
861 */
862 jspb.BinaryWriter.prototype.writeRepeatedZigzag_ = function(field, value) {
863 if (value == null) return;
864 for (var i = 0; i < value.length; i++) {
865 this.writeZigzagVarint64_(field, value[i]);
866 }
867 };
868
869
870 /**
854 * Writes an array of numbers to the buffer as a repeated 32-bit int field. 871 * Writes an array of numbers to the buffer as a repeated 32-bit int field.
855 * @param {number} field The field number. 872 * @param {number} field The field number.
856 * @param {?Array.<number>} value The array of ints to write. 873 * @param {?Array.<number>} value The array of ints to write.
857 */ 874 */
858 jspb.BinaryWriter.prototype.writeRepeatedInt32 = function(field, value) { 875 jspb.BinaryWriter.prototype.writeRepeatedInt32 =
859 if (value == null) return; 876 jspb.BinaryWriter.prototype.writeRepeatedSignedVarint32_;
860 for (var i = 0; i < value.length; i++) {
861 this.writeSignedVarint32_(field, value[i]);
862 }
863 };
864 877
865 878
866 /** 879 /**
867 * Writes an array of numbers formatted as strings to the buffer as a repeated 880 * Writes an array of numbers formatted as strings to the buffer as a repeated
868 * 32-bit int field. 881 * 32-bit int field.
869 * @param {number} field The field number. 882 * @param {number} field The field number.
870 * @param {?Array.<string>} value The array of ints to write. 883 * @param {?Array.<string>} value The array of ints to write.
871 */ 884 */
872 jspb.BinaryWriter.prototype.writeRepeatedInt32String = function(field, value) { 885 jspb.BinaryWriter.prototype.writeRepeatedInt32String =
886 function(field, value) {
873 if (value == null) return; 887 if (value == null) return;
874 for (var i = 0; i < value.length; i++) { 888 for (var i = 0; i < value.length; i++) {
875 this.writeInt32String(field, value[i]); 889 this.writeInt32String(field, value[i]);
876 } 890 }
877 }; 891 };
878 892
879 893
880 /** 894 /**
881 * Writes an array of numbers to the buffer as a repeated 64-bit int field. 895 * Writes an array of numbers to the buffer as a repeated 64-bit int field.
882 * @param {number} field The field number. 896 * @param {number} field The field number.
883 * @param {?Array.<number>} value The array of ints to write. 897 * @param {?Array.<number>} value The array of ints to write.
884 */ 898 */
885 jspb.BinaryWriter.prototype.writeRepeatedInt64 = function(field, value) { 899 jspb.BinaryWriter.prototype.writeRepeatedInt64 =
886 if (value == null) return; 900 jspb.BinaryWriter.prototype.writeRepeatedSignedVarint64_;
887 for (var i = 0; i < value.length; i++) {
888 this.writeSignedVarint64_(field, value[i]);
889 }
890 };
891 901
892 902
893 /** 903 /**
894 * Writes an array of numbers formatted as strings to the buffer as a repeated 904 * Writes an array of numbers formatted as strings to the buffer as a repeated
895 * 64-bit int field. 905 * 64-bit int field.
896 * @param {number} field The field number. 906 * @param {number} field The field number.
897 * @param {?Array.<string>} value The array of ints to write. 907 * @param {?Array.<string>} value The array of ints to write.
898 */ 908 */
899 jspb.BinaryWriter.prototype.writeRepeatedInt64String = function(field, value) { 909 jspb.BinaryWriter.prototype.writeRepeatedInt64String =
910 function(field, value) {
900 if (value == null) return; 911 if (value == null) return;
901 for (var i = 0; i < value.length; i++) { 912 for (var i = 0; i < value.length; i++) {
902 this.writeInt64String(field, value[i]); 913 this.writeInt64String(field, value[i]);
903 } 914 }
904 }; 915 };
905 916
906 917
907 /** 918 /**
908 * Writes an array numbers to the buffer as a repeated unsigned 32-bit int 919 * Writes an array numbers to the buffer as a repeated unsigned 32-bit int
909 * field. 920 * field.
910 * @param {number} field The field number. 921 * @param {number} field The field number.
911 * @param {?Array.<number>} value The array of ints to write. 922 * @param {?Array.<number>} value The array of ints to write.
912 */ 923 */
913 jspb.BinaryWriter.prototype.writeRepeatedUint32 = function(field, value) { 924 jspb.BinaryWriter.prototype.writeRepeatedUint32 =
914 if (value == null) return; 925 jspb.BinaryWriter.prototype.writeRepeatedUnsignedVarint32_;
915 for (var i = 0; i < value.length; i++) {
916 this.writeUnsignedVarint32_(field, value[i]);
917 }
918 };
919 926
920 927
921 /** 928 /**
922 * Writes an array of numbers formatted as strings to the buffer as a repeated 929 * Writes an array of numbers formatted as strings to the buffer as a repeated
923 * unsigned 32-bit int field. 930 * unsigned 32-bit int field.
924 * @param {number} field The field number. 931 * @param {number} field The field number.
925 * @param {?Array.<string>} value The array of ints to write. 932 * @param {?Array.<string>} value The array of ints to write.
926 */ 933 */
927 jspb.BinaryWriter.prototype.writeRepeatedUint32String = function(field, value) { 934 jspb.BinaryWriter.prototype.writeRepeatedUint32String =
935 function(field, value) {
928 if (value == null) return; 936 if (value == null) return;
929 for (var i = 0; i < value.length; i++) { 937 for (var i = 0; i < value.length; i++) {
930 this.writeUint32String(field, value[i]); 938 this.writeUint32String(field, value[i]);
931 } 939 }
932 }; 940 };
933 941
934 942
935 /** 943 /**
936 * Writes an array numbers to the buffer as a repeated unsigned 64-bit int 944 * Writes an array numbers to the buffer as a repeated unsigned 64-bit int
937 * field. 945 * field.
938 * @param {number} field The field number. 946 * @param {number} field The field number.
939 * @param {?Array.<number>} value The array of ints to write. 947 * @param {?Array.<number>} value The array of ints to write.
940 */ 948 */
941 jspb.BinaryWriter.prototype.writeRepeatedUint64 = function(field, value) { 949 jspb.BinaryWriter.prototype.writeRepeatedUint64 =
942 if (value == null) return; 950 jspb.BinaryWriter.prototype.writeRepeatedUnsignedVarint64_;
943 for (var i = 0; i < value.length; i++) {
944 this.writeUnsignedVarint64_(field, value[i]);
945 }
946 };
947 951
948 952
949 /** 953 /**
950 * Writes an array of numbers formatted as strings to the buffer as a repeated 954 * Writes an array of numbers formatted as strings to the buffer as a repeated
951 * unsigned 64-bit int field. 955 * unsigned 64-bit int field.
952 * @param {number} field The field number. 956 * @param {number} field The field number.
953 * @param {?Array.<string>} value The array of ints to write. 957 * @param {?Array.<string>} value The array of ints to write.
954 */ 958 */
955 jspb.BinaryWriter.prototype.writeRepeatedUint64String = function(field, value) { 959 jspb.BinaryWriter.prototype.writeRepeatedUint64String =
960 function(field, value) {
956 if (value == null) return; 961 if (value == null) return;
957 for (var i = 0; i < value.length; i++) { 962 for (var i = 0; i < value.length; i++) {
958 this.writeUint64String(field, value[i]); 963 this.writeUint64String(field, value[i]);
959 } 964 }
960 }; 965 };
961 966
962 967
963 /** 968 /**
964 * Writes an array numbers to the buffer as a repeated signed 32-bit int field. 969 * Writes an array numbers to the buffer as a repeated signed 32-bit int field.
965 * @param {number} field The field number. 970 * @param {number} field The field number.
966 * @param {?Array.<number>} value The array of ints to write. 971 * @param {?Array.<number>} value The array of ints to write.
967 */ 972 */
968 jspb.BinaryWriter.prototype.writeRepeatedSint32 = function(field, value) { 973 jspb.BinaryWriter.prototype.writeRepeatedSint32 =
969 if (value == null) return; 974 jspb.BinaryWriter.prototype.writeRepeatedZigzag32_;
970 for (var i = 0; i < value.length; i++) {
971 this.writeZigzagVarint32_(field, value[i]);
972 }
973 };
974 975
975 976
976 /** 977 /**
977 * Writes an array numbers to the buffer as a repeated signed 64-bit int field. 978 * Writes an array numbers to the buffer as a repeated signed 64-bit int field.
978 * @param {number} field The field number. 979 * @param {number} field The field number.
979 * @param {?Array.<number>} value The array of ints to write. 980 * @param {?Array.<number>} value The array of ints to write.
980 */ 981 */
981 jspb.BinaryWriter.prototype.writeRepeatedSint64 = function(field, value) { 982 jspb.BinaryWriter.prototype.writeRepeatedSint64 =
982 if (value == null) return; 983 jspb.BinaryWriter.prototype.writeRepeatedZigzag_;
983 for (var i = 0; i < value.length; i++) {
984 this.writeZigzagVarint64_(field, value[i]);
985 }
986 };
987
988
989 /**
990 * Writes an array numbers to the buffer as a repeated signed 64-bit int field.
991 * @param {number} field The field number.
992 * @param {?Array.<string>} value The array of ints to write.
993 */
994 jspb.BinaryWriter.prototype.writeRepeatedSint64String = function(field, value) {
995 if (value == null) return;
996 for (var i = 0; i < value.length; i++) {
997 this.writeZigzagVarint64String_(field, value[i]);
998 }
999 };
1000 984
1001 985
1002 /** 986 /**
1003 * Writes an array of numbers to the buffer as a repeated fixed32 field. This 987 * Writes an array of numbers to the buffer as a repeated fixed32 field. This
1004 * works for both signed and unsigned fixed32s. 988 * works for both signed and unsigned fixed32s.
1005 * @param {number} field The field number. 989 * @param {number} field The field number.
1006 * @param {?Array.<number>} value The array of ints to write. 990 * @param {?Array.<number>} value The array of ints to write.
1007 */ 991 */
1008 jspb.BinaryWriter.prototype.writeRepeatedFixed32 = function(field, value) { 992 jspb.BinaryWriter.prototype.writeRepeatedFixed32 = function(field, value) {
1009 if (value == null) return; 993 if (value == null) return;
(...skipping 11 matching lines...) Expand all
1021 */ 1005 */
1022 jspb.BinaryWriter.prototype.writeRepeatedFixed64 = function(field, value) { 1006 jspb.BinaryWriter.prototype.writeRepeatedFixed64 = function(field, value) {
1023 if (value == null) return; 1007 if (value == null) return;
1024 for (var i = 0; i < value.length; i++) { 1008 for (var i = 0; i < value.length; i++) {
1025 this.writeFixed64(field, value[i]); 1009 this.writeFixed64(field, value[i]);
1026 } 1010 }
1027 }; 1011 };
1028 1012
1029 1013
1030 /** 1014 /**
1031 * Writes an array of numbers to the buffer as a repeated fixed64 field. This
1032 * works for both signed and unsigned fixed64s.
1033 * @param {number} field The field number.
1034 * @param {?Array.<string>} value The array of decimal strings to write.
1035 */
1036 jspb.BinaryWriter.prototype.writeRepeatedFixed64String = function(
1037 field, value) {
1038 if (value == null) return;
1039 for (var i = 0; i < value.length; i++) {
1040 this.writeFixed64String(field, value[i]);
1041 }
1042 };
1043
1044
1045 /**
1046 * Writes an array of numbers to the buffer as a repeated sfixed32 field. 1015 * Writes an array of numbers to the buffer as a repeated sfixed32 field.
1047 * @param {number} field The field number. 1016 * @param {number} field The field number.
1048 * @param {?Array.<number>} value The array of ints to write. 1017 * @param {?Array.<number>} value The array of ints to write.
1049 */ 1018 */
1050 jspb.BinaryWriter.prototype.writeRepeatedSfixed32 = function(field, value) { 1019 jspb.BinaryWriter.prototype.writeRepeatedSfixed32 = function(field, value) {
1051 if (value == null) return; 1020 if (value == null) return;
1052 for (var i = 0; i < value.length; i++) { 1021 for (var i = 0; i < value.length; i++) {
1053 this.writeSfixed32(field, value[i]); 1022 this.writeSfixed32(field, value[i]);
1054 } 1023 }
1055 }; 1024 };
1056 1025
1057 1026
1058 /** 1027 /**
1059 * Writes an array of numbers to the buffer as a repeated sfixed64 field. 1028 * Writes an array of numbers to the buffer as a repeated sfixed64 field.
1060 * @param {number} field The field number. 1029 * @param {number} field The field number.
1061 * @param {?Array.<number>} value The array of ints to write. 1030 * @param {?Array.<number>} value The array of ints to write.
1062 */ 1031 */
1063 jspb.BinaryWriter.prototype.writeRepeatedSfixed64 = function(field, value) { 1032 jspb.BinaryWriter.prototype.writeRepeatedSfixed64 = function(field, value) {
1064 if (value == null) return; 1033 if (value == null) return;
1065 for (var i = 0; i < value.length; i++) { 1034 for (var i = 0; i < value.length; i++) {
1066 this.writeSfixed64(field, value[i]); 1035 this.writeSfixed64(field, value[i]);
1067 } 1036 }
1068 }; 1037 };
1069 1038
1070 1039
1071 /** 1040 /**
1072 * Writes an array of decimal strings to the buffer as a repeated sfixed64
1073 * field.
1074 * @param {number} field The field number.
1075 * @param {?Array.<string>} value The array of decimal strings to write.
1076 */
1077 jspb.BinaryWriter.prototype.writeRepeatedSfixed64String = function(field, value) {
1078 if (value == null) return;
1079 for (var i = 0; i < value.length; i++) {
1080 this.writeSfixed64String(field, value[i]);
1081 }
1082 };
1083
1084
1085 /**
1086 * Writes an array of numbers to the buffer as a repeated float field. 1041 * Writes an array of numbers to the buffer as a repeated float field.
1087 * @param {number} field The field number. 1042 * @param {number} field The field number.
1088 * @param {?Array.<number>} value The array of ints to write. 1043 * @param {?Array.<number>} value The array of ints to write.
1089 */ 1044 */
1090 jspb.BinaryWriter.prototype.writeRepeatedFloat = function(field, value) { 1045 jspb.BinaryWriter.prototype.writeRepeatedFloat = function(field, value) {
1091 if (value == null) return; 1046 if (value == null) return;
1092 for (var i = 0; i < value.length; i++) { 1047 for (var i = 0; i < value.length; i++) {
1093 this.writeFloat(field, value[i]); 1048 this.writeFloat(field, value[i]);
1094 } 1049 }
1095 }; 1050 };
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 } 1115 }
1161 }; 1116 };
1162 1117
1163 1118
1164 /** 1119 /**
1165 * Writes an array of messages to the buffer. 1120 * Writes an array of messages to the buffer.
1166 * @template MessageType 1121 * @template MessageType
1167 * @param {number} field The field number. 1122 * @param {number} field The field number.
1168 * @param {?Array.<MessageType>} value The array of messages to 1123 * @param {?Array.<MessageType>} value The array of messages to
1169 * write. 1124 * write.
1170 * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback 1125 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value
1171 * Will be invoked with the value to write and the writer to write it with. 1126 * to write and the writer to write it with.
1172 */ 1127 */
1173 jspb.BinaryWriter.prototype.writeRepeatedMessage = function( 1128 jspb.BinaryWriter.prototype.writeRepeatedMessage = function(
1174 field, value, writerCallback) { 1129 field, value, writerCallback) {
1175 if (value == null) return; 1130 if (value == null) return;
1176 for (var i = 0; i < value.length; i++) { 1131 for (var i = 0; i < value.length; i++) {
1177 var bookmark = this.beginDelimited_(field); 1132 var bookmark = this.beginDelimited_(field);
1178 writerCallback(value[i], this); 1133 writerCallback(value[i], this);
1179 this.endDelimited_(bookmark); 1134 this.endDelimited_(bookmark);
1180 } 1135 }
1181 }; 1136 };
1182 1137
1183 1138
1184 /** 1139 /**
1185 * Writes an array of group messages to the buffer. 1140 * Writes an array of group messages to the buffer.
1186 * @template MessageType 1141 * @template MessageType
1187 * @param {number} field The field number. 1142 * @param {number} field The field number.
1188 * @param {?Array.<MessageType>} value The array of messages to 1143 * @param {?Array.<MessageType>} value The array of messages to
1189 * write. 1144 * write.
1190 * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback 1145 * @param {!jspb.WriterFunction} writerCallback Will be invoked with the value
1191 * Will be invoked with the value to write and the writer to write it with. 1146 * to write and the writer to write it with.
1192 */ 1147 */
1193 jspb.BinaryWriter.prototype.writeRepeatedGroup = function( 1148 jspb.BinaryWriter.prototype.writeRepeatedGroup = function(
1194 field, value, writerCallback) { 1149 field, value, writerCallback) {
1195 if (value == null) return; 1150 if (value == null) return;
1196 for (var i = 0; i < value.length; i++) { 1151 for (var i = 0; i < value.length; i++) {
1197 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP); 1152 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP);
1198 writerCallback(value[i], this); 1153 writerCallback(value[i], this);
1199 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP); 1154 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP);
1200 } 1155 }
1201 }; 1156 };
(...skipping 23 matching lines...) Expand all
1225 jspb.BinaryWriter.prototype.writeRepeatedVarintHash64 = 1180 jspb.BinaryWriter.prototype.writeRepeatedVarintHash64 =
1226 function(field, value) { 1181 function(field, value) {
1227 if (value == null) return; 1182 if (value == null) return;
1228 for (var i = 0; i < value.length; i++) { 1183 for (var i = 0; i < value.length; i++) {
1229 this.writeVarintHash64(field, value[i]); 1184 this.writeVarintHash64(field, value[i]);
1230 } 1185 }
1231 }; 1186 };
1232 1187
1233 1188
1234 /** 1189 /**
1190 * Writes an array of numbers to the buffer as a packed varint field.
1191 * @param {number} field The field number.
1192 * @param {?Array.<number>} value The array of ints to write.
1193 * @private
1194 */
1195 jspb.BinaryWriter.prototype.writePackedUnsignedVarint32_ = function(
1196 field, value) {
1197 if (value == null || !value.length) return;
1198 var bookmark = this.beginDelimited_(field);
1199 for (var i = 0; i < value.length; i++) {
1200 this.encoder_.writeUnsignedVarint32(value[i]);
1201 }
1202 this.endDelimited_(bookmark);
1203 };
1204
1205
1206 /**
1207 * Writes an array of numbers to the buffer as a packed varint field.
1208 * @param {number} field The field number.
1209 * @param {?Array.<number>} value The array of ints to write.
1210 * @private
1211 */
1212 jspb.BinaryWriter.prototype.writePackedSignedVarint32_ = function(
1213 field, value) {
1214 if (value == null || !value.length) return;
1215 var bookmark = this.beginDelimited_(field);
1216 for (var i = 0; i < value.length; i++) {
1217 this.encoder_.writeSignedVarint32(value[i]);
1218 }
1219 this.endDelimited_(bookmark);
1220 };
1221
1222
1223 /**
1224 * Writes an array of numbers to the buffer as a packed varint field.
1225 * @param {number} field The field number.
1226 * @param {?Array.<number>} value The array of ints to write.
1227 * @private
1228 */
1229 jspb.BinaryWriter.prototype.writePackedUnsignedVarint64_ = function(
1230 field, value) {
1231 if (value == null || !value.length) return;
1232 var bookmark = this.beginDelimited_(field);
1233 for (var i = 0; i < value.length; i++) {
1234 this.encoder_.writeUnsignedVarint64(value[i]);
1235 }
1236 this.endDelimited_(bookmark);
1237 };
1238
1239
1240 /**
1241 * Writes an array of numbers to the buffer as a packed varint field.
1242 * @param {number} field The field number.
1243 * @param {?Array.<number>} value The array of ints to write.
1244 * @private
1245 */
1246 jspb.BinaryWriter.prototype.writePackedSignedVarint64_ = function(
1247 field, value) {
1248 if (value == null || !value.length) return;
1249 var bookmark = this.beginDelimited_(field);
1250 for (var i = 0; i < value.length; i++) {
1251 this.encoder_.writeSignedVarint64(value[i]);
1252 }
1253 this.endDelimited_(bookmark);
1254 };
1255
1256
1257 /**
1258 * Writes an array of numbers to the buffer as a packed zigzag field.
1259 * @param {number} field The field number.
1260 * @param {?Array.<number>} value The array of ints to write.
1261 * @private
1262 */
1263 jspb.BinaryWriter.prototype.writePackedZigzag32_ = function(field, value) {
1264 if (value == null || !value.length) return;
1265 var bookmark = this.beginDelimited_(field);
1266 for (var i = 0; i < value.length; i++) {
1267 this.encoder_.writeZigzagVarint32(value[i]);
1268 }
1269 this.endDelimited_(bookmark);
1270 };
1271
1272
1273 /**
1274 * Writes an array of numbers to the buffer as a packed zigzag field.
1275 * @param {number} field The field number.
1276 * @param {?Array.<number>} value The array of ints to write.
1277 * @private
1278 */
1279 jspb.BinaryWriter.prototype.writePackedZigzag64_ = function(field, value) {
1280 if (value == null || !value.length) return;
1281 var bookmark = this.beginDelimited_(field);
1282 for (var i = 0; i < value.length; i++) {
1283 this.encoder_.writeZigzagVarint64(value[i]);
1284 }
1285 this.endDelimited_(bookmark);
1286 };
1287
1288
1289 /**
1235 * Writes an array of numbers to the buffer as a packed 32-bit int field. 1290 * Writes an array of numbers to the buffer as a packed 32-bit int field.
1236 * @param {number} field The field number. 1291 * @param {number} field The field number.
1237 * @param {?Array.<number>} value The array of ints to write. 1292 * @param {?Array.<number>} value The array of ints to write.
1238 */ 1293 */
1239 jspb.BinaryWriter.prototype.writePackedInt32 = function(field, value) { 1294 jspb.BinaryWriter.prototype.writePackedInt32 =
1240 if (value == null || !value.length) return; 1295 jspb.BinaryWriter.prototype.writePackedSignedVarint32_;
1241 var bookmark = this.beginDelimited_(field);
1242 for (var i = 0; i < value.length; i++) {
1243 this.encoder_.writeSignedVarint32(value[i]);
1244 }
1245 this.endDelimited_(bookmark);
1246 };
1247 1296
1248 1297
1249 /** 1298 /**
1250 * Writes an array of numbers represented as strings to the buffer as a packed 1299 * Writes an array of numbers represented as strings to the buffer as a packed
1251 * 32-bit int field. 1300 * 32-bit int field.
1252 * @param {number} field 1301 * @param {number} field
1253 * @param {?Array.<string>} value 1302 * @param {?Array.<string>} value
1254 */ 1303 */
1255 jspb.BinaryWriter.prototype.writePackedInt32String = function(field, value) { 1304 jspb.BinaryWriter.prototype.writePackedInt32String = function(field, value) {
1256 if (value == null || !value.length) return; 1305 if (value == null || !value.length) return;
1257 var bookmark = this.beginDelimited_(field); 1306 var bookmark = this.beginDelimited_(field);
1258 for (var i = 0; i < value.length; i++) { 1307 for (var i = 0; i < value.length; i++) {
1259 this.encoder_.writeSignedVarint32(parseInt(value[i], 10)); 1308 this.encoder_.writeSignedVarint32(parseInt(value[i], 10));
1260 } 1309 }
1261 this.endDelimited_(bookmark); 1310 this.endDelimited_(bookmark);
1262 }; 1311 };
1263 1312
1264 1313
1265 /** 1314 /**
1266 * Writes an array of numbers to the buffer as a packed 64-bit int field. 1315 * Writes an array of numbers to the buffer as a packed 64-bit int field.
1267 * @param {number} field The field number. 1316 * @param {number} field The field number.
1268 * @param {?Array.<number>} value The array of ints to write. 1317 * @param {?Array.<number>} value The array of ints to write.
1269 */ 1318 */
1270 jspb.BinaryWriter.prototype.writePackedInt64 = function(field, value) { 1319 jspb.BinaryWriter.prototype.writePackedInt64 =
1271 if (value == null || !value.length) return; 1320 jspb.BinaryWriter.prototype.writePackedSignedVarint64_;
1272 var bookmark = this.beginDelimited_(field);
1273 for (var i = 0; i < value.length; i++) {
1274 this.encoder_.writeSignedVarint64(value[i]);
1275 }
1276 this.endDelimited_(bookmark);
1277 };
1278 1321
1279 1322
1280 /** 1323 /**
1281 * Writes an array of numbers represented as strings to the buffer as a packed 1324 * Writes an array of numbers represented as strings to the buffer as a packed
1282 * 64-bit int field. 1325 * 64-bit int field.
1283 * @param {number} field 1326 * @param {number} field
1284 * @param {?Array.<string>} value 1327 * @param {?Array.<string>} value
1285 */ 1328 */
1286 jspb.BinaryWriter.prototype.writePackedInt64String = function(field, value) { 1329 jspb.BinaryWriter.prototype.writePackedInt64String =
1330 function(field, value) {
1287 if (value == null || !value.length) return; 1331 if (value == null || !value.length) return;
1288 var bookmark = this.beginDelimited_(field); 1332 var bookmark = this.beginDelimited_(field);
1289 for (var i = 0; i < value.length; i++) { 1333 for (var i = 0; i < value.length; i++) {
1290 var num = jspb.arith.Int64.fromString(value[i]); 1334 var num = jspb.arith.Int64.fromString(value[i]);
1291 this.encoder_.writeSplitVarint64(num.lo, num.hi); 1335 this.encoder_.writeSplitVarint64(num.lo, num.hi);
1292 } 1336 }
1293 this.endDelimited_(bookmark); 1337 this.endDelimited_(bookmark);
1294 };
1295
1296
1297 /**
1298 * Writes an array numbers to the buffer as a packed unsigned 32-bit int field.
1299 * @param {number} field The field number.
1300 * @param {?Array.<number>} value The array of ints to write.
1301 */
1302 jspb.BinaryWriter.prototype.writePackedUint32 = function(field, value) {
1303 if (value == null || !value.length) return;
1304 var bookmark = this.beginDelimited_(field);
1305 for (var i = 0; i < value.length; i++) {
1306 this.encoder_.writeUnsignedVarint32(value[i]);
1307 }
1308 this.endDelimited_(bookmark);
1309 };
1310
1311
1312 /**
1313 * Writes an array of numbers represented as strings to the buffer as a packed
1314 * unsigned 32-bit int field.
1315 * @param {number} field
1316 * @param {?Array.<string>} value
1317 */
1318 jspb.BinaryWriter.prototype.writePackedUint32String =
1319 function(field, value) {
1320 if (value == null || !value.length) return;
1321 var bookmark = this.beginDelimited_(field);
1322 for (var i = 0; i < value.length; i++) {
1323 this.encoder_.writeUnsignedVarint32(parseInt(value[i], 10));
1324 }
1325 this.endDelimited_(bookmark);
1326 };
1327
1328
1329 /**
1330 * Writes an array numbers to the buffer as a packed unsigned 64-bit int field.
1331 * @param {number} field The field number.
1332 * @param {?Array.<number>} value The array of ints to write.
1333 */
1334 jspb.BinaryWriter.prototype.writePackedUint64 = function(field, value) {
1335 if (value == null || !value.length) return;
1336 var bookmark = this.beginDelimited_(field);
1337 for (var i = 0; i < value.length; i++) {
1338 this.encoder_.writeUnsignedVarint64(value[i]);
1339 }
1340 this.endDelimited_(bookmark);
1341 };
1342
1343
1344 /**
1345 * Writes an array of numbers represented as strings to the buffer as a packed
1346 * unsigned 64-bit int field.
1347 * @param {number} field
1348 * @param {?Array.<string>} value
1349 */
1350 jspb.BinaryWriter.prototype.writePackedUint64String =
1351 function(field, value) {
1352 if (value == null || !value.length) return;
1353 var bookmark = this.beginDelimited_(field);
1354 for (var i = 0; i < value.length; i++) {
1355 var num = jspb.arith.UInt64.fromString(value[i]);
1356 this.encoder_.writeSplitVarint64(num.lo, num.hi);
1357 }
1358 this.endDelimited_(bookmark);
1359 }; 1338 };
1360 1339
1361 1340
1362 /** 1341 /**
1342 * Writes an array numbers to the buffer as a packed unsigned 32-bit int field.
1343 * @param {number} field The field number.
1344 * @param {?Array.<number>} value The array of ints to write.
1345 */
1346 jspb.BinaryWriter.prototype.writePackedUint32 =
1347 jspb.BinaryWriter.prototype.writePackedUnsignedVarint32_;
1348
1349
1350 /**
1351 * Writes an array of numbers represented as strings to the buffer as a packed
1352 * unsigned 32-bit int field.
1353 * @param {number} field
1354 * @param {?Array.<string>} value
1355 */
1356 jspb.BinaryWriter.prototype.writePackedUint32String =
1357 function(field, value) {
1358 if (value == null || !value.length) return;
1359 var bookmark = this.beginDelimited_(field);
1360 for (var i = 0; i < value.length; i++) {
1361 this.encoder_.writeUnsignedVarint32(parseInt(value[i], 10));
1362 }
1363 this.endDelimited_(bookmark);
1364 };
1365
1366
1367 /**
1368 * Writes an array numbers to the buffer as a packed unsigned 64-bit int field.
1369 * @param {number} field The field number.
1370 * @param {?Array.<number>} value The array of ints to write.
1371 */
1372 jspb.BinaryWriter.prototype.writePackedUint64 =
1373 jspb.BinaryWriter.prototype.writePackedUnsignedVarint64_;
1374
1375
1376 /**
1377 * Writes an array of numbers represented as strings to the buffer as a packed
1378 * unsigned 64-bit int field.
1379 * @param {number} field
1380 * @param {?Array.<string>} value
1381 */
1382 jspb.BinaryWriter.prototype.writePackedUint64String =
1383 function(field, value) {
1384 if (value == null || !value.length) return;
1385 var bookmark = this.beginDelimited_(field);
1386 for (var i = 0; i < value.length; i++) {
1387 var num = jspb.arith.UInt64.fromString(value[i]);
1388 this.encoder_.writeSplitVarint64(num.lo, num.hi);
1389 }
1390 this.endDelimited_(bookmark);
1391 };
1392
1393
1394 /**
1363 * Writes an array numbers to the buffer as a packed signed 32-bit int field. 1395 * Writes an array numbers to the buffer as a packed signed 32-bit int field.
1364 * @param {number} field The field number. 1396 * @param {number} field The field number.
1365 * @param {?Array.<number>} value The array of ints to write. 1397 * @param {?Array.<number>} value The array of ints to write.
1366 */ 1398 */
1367 jspb.BinaryWriter.prototype.writePackedSint32 = function(field, value) { 1399 jspb.BinaryWriter.prototype.writePackedSint32 =
1368 if (value == null || !value.length) return; 1400 jspb.BinaryWriter.prototype.writePackedZigzag32_;
1369 var bookmark = this.beginDelimited_(field);
1370 for (var i = 0; i < value.length; i++) {
1371 this.encoder_.writeZigzagVarint32(value[i]);
1372 }
1373 this.endDelimited_(bookmark);
1374 };
1375 1401
1376 1402
1377 /** 1403 /**
1378 * Writes an array of numbers to the buffer as a packed signed 64-bit int field. 1404 * Writes an array numbers to the buffer as a packed signed 64-bit int field.
1379 * @param {number} field The field number. 1405 * @param {number} field The field number.
1380 * @param {?Array.<number>} value The array of ints to write. 1406 * @param {?Array.<number>} value The array of ints to write.
1381 */ 1407 */
1382 jspb.BinaryWriter.prototype.writePackedSint64 = function(field, value) { 1408 jspb.BinaryWriter.prototype.writePackedSint64 =
1383 if (value == null || !value.length) return; 1409 jspb.BinaryWriter.prototype.writePackedZigzag64_;
1384 var bookmark = this.beginDelimited_(field);
1385 for (var i = 0; i < value.length; i++) {
1386 this.encoder_.writeZigzagVarint64(value[i]);
1387 }
1388 this.endDelimited_(bookmark);
1389 };
1390 1410
1391 1411
1392 /** 1412 /**
1393 * Writes an array of decimal strings to the buffer as a packed signed 64-bit
1394 * int field.
1395 * @param {number} field The field number.
1396 * @param {?Array.<string>} value The array of decimal strings to write.
1397 */
1398 jspb.BinaryWriter.prototype.writePackedSint64String = function(field, value) {
1399 if (value == null || !value.length) return;
1400 var bookmark = this.beginDelimited_(field);
1401 for (var i = 0; i < value.length; i++) {
1402 // TODO(haberman): make lossless
1403 this.encoder_.writeZigzagVarint64(parseInt(value[i], 10));
1404 }
1405 this.endDelimited_(bookmark);
1406 };
1407
1408
1409 /**
1410 * Writes an array of numbers to the buffer as a packed fixed32 field. 1413 * Writes an array of numbers to the buffer as a packed fixed32 field.
1411 * @param {number} field The field number. 1414 * @param {number} field The field number.
1412 * @param {?Array.<number>} value The array of ints to write. 1415 * @param {?Array.<number>} value The array of ints to write.
1413 */ 1416 */
1414 jspb.BinaryWriter.prototype.writePackedFixed32 = function(field, value) { 1417 jspb.BinaryWriter.prototype.writePackedFixed32 = function(field, value) {
1415 if (value == null || !value.length) return; 1418 if (value == null || !value.length) return;
1416 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 1419 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1417 this.encoder_.writeUnsignedVarint32(value.length * 4); 1420 this.encoder_.writeUnsignedVarint32(value.length * 4);
1418 for (var i = 0; i < value.length; i++) { 1421 for (var i = 0; i < value.length; i++) {
1419 this.encoder_.writeUint32(value[i]); 1422 this.encoder_.writeUint32(value[i]);
(...skipping 10 matching lines...) Expand all
1430 if (value == null || !value.length) return; 1433 if (value == null || !value.length) return;
1431 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 1434 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1432 this.encoder_.writeUnsignedVarint32(value.length * 8); 1435 this.encoder_.writeUnsignedVarint32(value.length * 8);
1433 for (var i = 0; i < value.length; i++) { 1436 for (var i = 0; i < value.length; i++) {
1434 this.encoder_.writeUint64(value[i]); 1437 this.encoder_.writeUint64(value[i]);
1435 } 1438 }
1436 }; 1439 };
1437 1440
1438 1441
1439 /** 1442 /**
1440 * Writes an array of numbers represented as strings to the buffer as a packed
1441 * fixed64 field.
1442 * @param {number} field The field number.
1443 * @param {?Array.<string>} value The array of strings to write.
1444 */
1445 jspb.BinaryWriter.prototype.writePackedFixed64String = function(field, value) {
1446 if (value == null || !value.length) return;
1447 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1448 this.encoder_.writeUnsignedVarint32(value.length * 8);
1449 for (var i = 0; i < value.length; i++) {
1450 var num = jspb.arith.UInt64.fromString(value[i]);
1451 this.encoder_.writeSplitFixed64(num.lo, num.hi);
1452 }
1453 };
1454
1455
1456 /**
1457 * Writes an array of numbers to the buffer as a packed sfixed32 field. 1443 * Writes an array of numbers to the buffer as a packed sfixed32 field.
1458 * @param {number} field The field number. 1444 * @param {number} field The field number.
1459 * @param {?Array.<number>} value The array of ints to write. 1445 * @param {?Array.<number>} value The array of ints to write.
1460 */ 1446 */
1461 jspb.BinaryWriter.prototype.writePackedSfixed32 = function(field, value) { 1447 jspb.BinaryWriter.prototype.writePackedSfixed32 = function(field, value) {
1462 if (value == null || !value.length) return; 1448 if (value == null || !value.length) return;
1463 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 1449 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1464 this.encoder_.writeUnsignedVarint32(value.length * 4); 1450 this.encoder_.writeUnsignedVarint32(value.length * 4);
1465 for (var i = 0; i < value.length; i++) { 1451 for (var i = 0; i < value.length; i++) {
1466 this.encoder_.writeInt32(value[i]); 1452 this.encoder_.writeInt32(value[i]);
(...skipping 10 matching lines...) Expand all
1477 if (value == null || !value.length) return; 1463 if (value == null || !value.length) return;
1478 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 1464 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1479 this.encoder_.writeUnsignedVarint32(value.length * 8); 1465 this.encoder_.writeUnsignedVarint32(value.length * 8);
1480 for (var i = 0; i < value.length; i++) { 1466 for (var i = 0; i < value.length; i++) {
1481 this.encoder_.writeInt64(value[i]); 1467 this.encoder_.writeInt64(value[i]);
1482 } 1468 }
1483 }; 1469 };
1484 1470
1485 1471
1486 /** 1472 /**
1487 * Writes an array of numbers to the buffer as a packed sfixed64 field.
1488 * @param {number} field The field number.
1489 * @param {?Array.<string>} value The array of decimal strings to write.
1490 */
1491 jspb.BinaryWriter.prototype.writePackedSfixed64String = function(field, value) {
1492 if (value == null || !value.length) return;
1493 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1494 this.encoder_.writeUnsignedVarint32(value.length * 8);
1495 for (var i = 0; i < value.length; i++) {
1496 this.encoder_.writeInt64String(value[i]);
1497 }
1498 };
1499
1500
1501 /**
1502 * Writes an array of numbers to the buffer as a packed float field. 1473 * Writes an array of numbers to the buffer as a packed float field.
1503 * @param {number} field The field number. 1474 * @param {number} field The field number.
1504 * @param {?Array.<number>} value The array of ints to write. 1475 * @param {?Array.<number>} value The array of ints to write.
1505 */ 1476 */
1506 jspb.BinaryWriter.prototype.writePackedFloat = function(field, value) { 1477 jspb.BinaryWriter.prototype.writePackedFloat = function(field, value) {
1507 if (value == null || !value.length) return; 1478 if (value == null || !value.length) return;
1508 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED); 1479 this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
1509 this.encoder_.writeUnsignedVarint32(value.length * 4); 1480 this.encoder_.writeUnsignedVarint32(value.length * 4);
1510 for (var i = 0; i < value.length; i++) { 1481 for (var i = 0; i < value.length; i++) {
1511 this.encoder_.writeFloat(value[i]); 1482 this.encoder_.writeFloat(value[i]);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 * @param {?Array.<string>} value The array of hashes to write. 1552 * @param {?Array.<string>} value The array of hashes to write.
1582 */ 1553 */
1583 jspb.BinaryWriter.prototype.writePackedVarintHash64 = function(field, value) { 1554 jspb.BinaryWriter.prototype.writePackedVarintHash64 = function(field, value) {
1584 if (value == null || !value.length) return; 1555 if (value == null || !value.length) return;
1585 var bookmark = this.beginDelimited_(field); 1556 var bookmark = this.beginDelimited_(field);
1586 for (var i = 0; i < value.length; i++) { 1557 for (var i = 0; i < value.length; i++) {
1587 this.encoder_.writeVarintHash64(value[i]); 1558 this.encoder_.writeVarintHash64(value[i]);
1588 } 1559 }
1589 this.endDelimited_(bookmark); 1560 this.endDelimited_(bookmark);
1590 }; 1561 };
OLDNEW
« no previous file with comments | « third_party/protobuf/js/binary/utils.js ('k') | third_party/protobuf/js/commonjs/export.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698