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