libpurple/protocols/facebook/thrift.c

branch
facebook
changeset 37327
68220e4ccb15
parent 37268
2d85594bb9ee
child 37331
9cd963f45997
equal deleted inserted replaced
37326:c768f27357ec 37327:68220e4ccb15
75 75
76 if (bytes != NULL) { 76 if (bytes != NULL) {
77 priv->bytes = bytes; 77 priv->bytes = bytes;
78 priv->offset = offset; 78 priv->offset = offset;
79 } else { 79 } else {
80 priv->bytes = g_byte_array_new();
80 priv->flags |= FB_THRIFT_FLAG_INTERNAL; 81 priv->flags |= FB_THRIFT_FLAG_INTERNAL;
81 } 82 }
82 83
83 if (compact) { 84 if (compact) {
84 priv->flags |= FB_THRIFT_FLAG_COMPACT; 85 priv->flags |= FB_THRIFT_FLAG_COMPACT;
85 } 86 }
86 87
87 priv->pos = priv->offset; 88 priv->pos = priv->offset;
88 return thft; 89 return thft;
90 }
91
92 const GByteArray *
93 fb_thrift_get_bytes(FbThrift *thft)
94 {
95 FbThriftPrivate *priv;
96
97 g_return_val_if_fail(FB_IS_THRIFT(thft), NULL);
98 priv = thft->priv;
99 return priv->bytes;
89 } 100 }
90 101
91 guint 102 guint
92 fb_thrift_get_pos(FbThrift *thft) 103 fb_thrift_get_pos(FbThrift *thft)
93 { 104 {
726 } 737 }
727 738
728 void 739 void
729 fb_thrift_write_vi16(FbThrift *thft, guint16 u16) 740 fb_thrift_write_vi16(FbThrift *thft, guint16 u16)
730 { 741 {
731 fb_thrift_write_vi32(thft, u16); 742 fb_thrift_write_vi64(thft, u16);
732 } 743 }
733 744
734 void 745 void
735 fb_thrift_write_i32(FbThrift *thft, gint32 i32) 746 fb_thrift_write_i32(FbThrift *thft, gint32 i32)
736 { 747 {
753 fb_thrift_write_vi32(FbThrift *thft, guint32 u32) 764 fb_thrift_write_vi32(FbThrift *thft, guint32 u32)
754 { 765 {
755 fb_thrift_write_vi64(thft, u32); 766 fb_thrift_write_vi64(thft, u32);
756 } 767 }
757 768
758
759 void 769 void
760 fb_thrift_write_i64(FbThrift *thft, gint64 i64) 770 fb_thrift_write_i64(FbThrift *thft, gint64 i64)
761 { 771 {
762 FbThriftPrivate *priv; 772 FbThriftPrivate *priv;
763 773
788 return; 798 return;
789 } 799 }
790 800
791 do { 801 do {
792 last = (u64 & ~0x7F) == 0; 802 last = (u64 & ~0x7F) == 0;
793 byte = !last ? ((u64 & 0x7F) | 0x80) : (u64 & 0x0F); 803 byte = u64 & 0x7F;
804
805 if (!last) {
806 byte |= 0x80;
807 u64 >>= 7;
808 }
794 809
795 fb_thrift_write_byte(thft, byte); 810 fb_thrift_write_byte(thft, byte);
796 u64 >>= 7;
797 } while (!last); 811 } while (!last);
798 } 812 }
799 813
800 void 814 void
801 fb_thrift_write_str(FbThrift *thft, const gchar *str) 815 fb_thrift_write_str(FbThrift *thft, const gchar *str)

mercurial