slidge-whatsapp 0.2.7__cp311-cp311-manylinux_2_36_aarch64.whl → 0.3.0__cp311-cp311-manylinux_2_36_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of slidge-whatsapp might be problematic. Click here for more details.

Files changed (212) hide show
  1. slidge_whatsapp/contact.py +15 -3
  2. slidge_whatsapp/event.go +144 -48
  3. slidge_whatsapp/gateway.go +7 -63
  4. slidge_whatsapp/gateway.py +2 -3
  5. slidge_whatsapp/generated/_whatsapp.cpython-311-aarch64-linux-gnu.h +178 -161
  6. slidge_whatsapp/generated/_whatsapp.cpython-311-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +148 -134
  8. slidge_whatsapp/generated/whatsapp.c +1612 -1340
  9. slidge_whatsapp/generated/whatsapp.go +995 -884
  10. slidge_whatsapp/generated/whatsapp.py +1169 -1044
  11. slidge_whatsapp/generated/whatsapp_go.h +178 -161
  12. slidge_whatsapp/go.mod +18 -15
  13. slidge_whatsapp/go.sum +38 -26
  14. slidge_whatsapp/group.py +34 -30
  15. slidge_whatsapp/media/media.go +1 -1
  16. slidge_whatsapp/session.go +34 -17
  17. slidge_whatsapp/session.py +46 -14
  18. slidge_whatsapp/vendor/github.com/beeper/argo-go/LICENSE +9 -0
  19. slidge_whatsapp/vendor/github.com/beeper/argo-go/block/blockreader.go +329 -0
  20. slidge_whatsapp/vendor/github.com/beeper/argo-go/block/blockwriter.go +417 -0
  21. slidge_whatsapp/vendor/github.com/beeper/argo-go/codec/decoder.go +652 -0
  22. slidge_whatsapp/vendor/github.com/beeper/argo-go/codec/encoder.go +985 -0
  23. slidge_whatsapp/vendor/github.com/beeper/argo-go/header/header.go +135 -0
  24. slidge_whatsapp/vendor/github.com/beeper/argo-go/internal/util/util.go +133 -0
  25. slidge_whatsapp/vendor/github.com/beeper/argo-go/label/label.go +384 -0
  26. slidge_whatsapp/vendor/github.com/beeper/argo-go/label/wiremarkers.go +37 -0
  27. slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/bitset/bitset.go +197 -0
  28. slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/buf/buf.go +420 -0
  29. slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/varint/varint.go +246 -0
  30. slidge_whatsapp/vendor/github.com/beeper/argo-go/wire/wire.go +614 -0
  31. slidge_whatsapp/vendor/github.com/beeper/argo-go/wirecodec/decode.go +341 -0
  32. slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/LICENSE +21 -0
  33. slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/list.go +95 -0
  34. slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/orderedmap.go +187 -0
  35. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz.go +1 -0
  36. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz_cgo.go +3 -0
  37. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz_nocgo.go +4 -5
  38. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_darwin.go +11 -1
  39. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_linux.go +10 -0
  40. slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_windows.go +12 -0
  41. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/.gitignore +0 -2
  42. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/CHANGELOG.md +30 -0
  43. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/COPYRIGHT.txt +6 -1
  44. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/README.md +14 -17
  45. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi.go +1 -1
  46. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi2.go +7 -0
  47. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/LICENSE +21 -0
  48. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/darwin_amd64/libffi.8.dylib +0 -0
  49. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/darwin_arm64/libffi.8.dylib +0 -0
  50. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/windows_amd64/libffi-8.dll +0 -0
  51. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/cif.go +15 -0
  52. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/cif_arm64.go +16 -0
  53. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed.go +49 -0
  54. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_darwin_amd64.go +10 -0
  55. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_darwin_arm64.go +10 -0
  56. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_windows_amd64.go +10 -0
  57. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/ffi.go +51 -13
  58. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/init.go +22 -9
  59. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/README.md +2 -0
  60. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c +3096 -1651
  61. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h +188 -128
  62. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_userauth.go +13 -140
  63. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h +4 -0
  64. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.23.go +2 -2
  65. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.25.go +37 -0
  66. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/LICENSE +19 -0
  67. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/argmap.go +37 -0
  68. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/collections.go +148 -0
  69. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/comment.go +31 -0
  70. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/decode.go +216 -0
  71. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/definition.go +110 -0
  72. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/directive.go +43 -0
  73. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/document.go +89 -0
  74. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/dumper.go +159 -0
  75. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/fragment.go +41 -0
  76. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/operation.go +32 -0
  77. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/path.go +72 -0
  78. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/selection.go +41 -0
  79. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/source.go +19 -0
  80. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/type.go +68 -0
  81. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/value.go +122 -0
  82. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/handleerrors.go +60 -26
  83. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/networkerror.go +2 -1
  84. slidge_whatsapp/vendor/go.mau.fi/util/exstrings/stringutil.go +28 -0
  85. slidge_whatsapp/vendor/go.mau.fi/util/exsync/event.go +19 -3
  86. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/.pre-commit-config.yaml +3 -3
  87. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/decode.go +1 -1
  88. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/hash.go +1 -1
  89. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +5 -1
  90. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/argo-wire-type-store.argo +63 -0
  91. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/argo.go +62 -0
  92. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/name-to-queryids.json +306 -0
  93. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/armadillomessage.go +3 -2
  94. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +1 -0
  95. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +15 -18
  96. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +5 -0
  97. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +4 -0
  98. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/errors.go +3 -0
  99. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +97 -25
  100. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +22 -10
  101. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +10 -9
  102. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/msgsecret.go +2 -14
  103. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/newsletter.go +83 -7
  104. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +5 -1
  105. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +2 -2
  106. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +15 -6
  107. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waBotMetadata/WABotMetadata.pb.go +5156 -0
  108. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waBotMetadata/WABotMetadata.proto +516 -0
  109. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.pb.go +30 -3
  110. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.proto +3 -0
  111. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +8532 -11526
  112. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +132 -438
  113. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +52 -23
  114. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.proto +3 -0
  115. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +225 -73
  116. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +21 -5
  117. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +884 -441
  118. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +40 -0
  119. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +60 -38
  120. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +3 -0
  121. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +8 -1
  122. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +6 -4
  123. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +1 -1
  124. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/noop.go +3 -2
  125. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go +25 -5
  126. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +3 -1
  127. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/call.go +1 -0
  128. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/events.go +8 -0
  129. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/jid.go +2 -1
  130. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/user.go +2 -0
  131. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +12 -8
  132. slidge_whatsapp/vendor/golang.org/x/crypto/curve25519/curve25519.go +1 -1
  133. slidge_whatsapp/vendor/golang.org/x/net/http2/config.go +44 -2
  134. slidge_whatsapp/vendor/golang.org/x/net/http2/gotrack.go +14 -3
  135. slidge_whatsapp/vendor/golang.org/x/net/http2/http2.go +7 -29
  136. slidge_whatsapp/vendor/golang.org/x/net/http2/server.go +53 -71
  137. slidge_whatsapp/vendor/golang.org/x/net/http2/transport.go +20 -74
  138. slidge_whatsapp/vendor/golang.org/x/sys/unix/affinity_linux.go +1 -3
  139. slidge_whatsapp/vendor/golang.org/x/sys/unix/mkerrors.sh +3 -0
  140. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_darwin.go +1 -55
  141. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_solaris.go +1 -1
  142. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux.go +47 -16
  143. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +3 -0
  144. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +3 -0
  145. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +3 -0
  146. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +3 -0
  147. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +3 -0
  148. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +3 -0
  149. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +3 -0
  150. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +3 -0
  151. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +3 -0
  152. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +3 -0
  153. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +3 -0
  154. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +3 -0
  155. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +3 -0
  156. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +3 -0
  157. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +3 -0
  158. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +4 -4
  159. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go +1 -0
  160. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +1 -0
  161. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +1 -0
  162. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +1 -0
  163. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +1 -0
  164. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +1 -0
  165. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +1 -0
  166. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +1 -0
  167. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +1 -0
  168. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +1 -0
  169. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +1 -0
  170. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +1 -0
  171. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +1 -0
  172. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +1 -0
  173. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +1 -0
  174. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux.go +168 -12
  175. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_386.go +17 -1
  176. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +16 -0
  177. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go +18 -2
  178. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +16 -0
  179. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +16 -0
  180. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go +17 -1
  181. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +16 -0
  182. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +16 -0
  183. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +17 -1
  184. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +18 -2
  185. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +16 -0
  186. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +16 -0
  187. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +16 -0
  188. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +16 -0
  189. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +16 -0
  190. slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +6 -0
  191. slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +483 -483
  192. slidge_whatsapp/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +25 -1
  193. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb +0 -0
  194. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/filedesc/editions.go +10 -5
  195. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/filedesc/presence.go +33 -0
  196. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +6 -0
  197. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +68 -22
  198. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/codec_message_opaque.go +2 -1
  199. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/message_opaque.go +8 -37
  200. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/presence.go +0 -3
  201. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/version/version.go +1 -1
  202. slidge_whatsapp/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +8 -0
  203. slidge_whatsapp/vendor/modules.txt +43 -23
  204. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/METADATA +5 -4
  205. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/RECORD +208 -161
  206. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/WHEEL +1 -1
  207. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi_amd64.go +0 -7
  208. slidge_whatsapp/vendor/golang.org/x/net/http2/config_go124.go +0 -61
  209. slidge_whatsapp/vendor/golang.org/x/net/http2/config_pre_go124.go +0 -16
  210. slidge_whatsapp/vendor/golang.org/x/net/http2/timer.go +0 -20
  211. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/entry_points.txt +0 -0
  212. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,246 @@
1
+ // Package varint implements ULEB128 (Unsigned Little Endian Base 128)
2
+ // and ZigZag encoding/decoding for arbitrary-precision integers (*big.Int)
3
+ // and standard integer types (uint64, int64).
4
+ // ULEB128 is a variable-length encoding for unsigned integers.
5
+ // ZigZag encoding maps signed integers to unsigned integers so they
6
+ // can be efficiently encoded using ULEB128.
7
+ package varint
8
+
9
+ import (
10
+ "errors"
11
+ "math/big"
12
+ )
13
+
14
+ // Pre-allocate common big.Int values to reduce allocations in loops/checks.
15
+ var (
16
+ big0 = big.NewInt(0)
17
+ big1 = big.NewInt(1)
18
+ big7f = big.NewInt(0x7f) // 127
19
+ big80 = big.NewInt(0x80) // 128
20
+ bigNeg1 = big.NewInt(-1) // Used for ~0 equivalent in Xor
21
+
22
+ // Constants for BytesNeeded
23
+ uMax1 = big.NewInt(0x7f)
24
+ uMax2 = big.NewInt(0x3fff)
25
+ uMax3 = big.NewInt(0x1fffff)
26
+ uMax4 = big.NewInt(0xfffffff)
27
+ uMax5 = big.NewInt(0x7ffffffff)
28
+ uMax6 = big.NewInt(0x3ffffffffff)
29
+ uMax7 = big.NewInt(0x1ffffffffffff)
30
+ uMax8 = big.NewInt(0xffffffffffffff)
31
+ uMax9 = big.NewInt(0x7fffffffffffffff) // This is MaxInt64, last one before needing more than 9 bytes for typical uint64 range
32
+ )
33
+
34
+ // UnsignedBytesNeeded calculates the number of bytes required to ULEB128 encode n.
35
+ func UnsignedBytesNeeded(n *big.Int) int {
36
+ if n.Cmp(uMax1) <= 0 {
37
+ return 1
38
+ }
39
+ if n.Cmp(uMax2) <= 0 {
40
+ return 2
41
+ }
42
+ if n.Cmp(uMax3) <= 0 {
43
+ return 3
44
+ }
45
+ if n.Cmp(uMax4) <= 0 {
46
+ return 4
47
+ }
48
+ if n.Cmp(uMax5) <= 0 {
49
+ return 5
50
+ }
51
+ if n.Cmp(uMax6) <= 0 {
52
+ return 6
53
+ }
54
+ if n.Cmp(uMax7) <= 0 {
55
+ return 7
56
+ }
57
+ if n.Cmp(uMax8) <= 0 {
58
+ return 8
59
+ }
60
+ if n.Cmp(uMax9) <= 0 {
61
+ return 9
62
+ } // Max value for 9 bytes is 2^63-1
63
+
64
+ // General case for numbers larger than 2^63-1
65
+ needed := 0
66
+ // Create a copy to avoid modifying the input n
67
+ tempN := new(big.Int).Set(n)
68
+ for tempN.Cmp(big0) > 0 {
69
+ needed++
70
+ tempN.Rsh(tempN, 7)
71
+ }
72
+ return needed
73
+ }
74
+
75
+ // UnsignedEncode ULEB128 encodes n into a new byte slice.
76
+ func UnsignedEncode(n *big.Int) []byte {
77
+ length := UnsignedBytesNeeded(n)
78
+ buf := make([]byte, length)
79
+ UnsignedEncodeInto(n, buf, 0)
80
+ return buf
81
+ }
82
+
83
+ // UnsignedEncodeInto ULEB128 encodes n into the provided buffer buf starting at offset.
84
+ // It returns the number of bytes written.
85
+ // Panics if the buffer is too small. Callers should ensure buf has enough space,
86
+ // e.g., by using UnsignedBytesNeeded.
87
+ func UnsignedEncodeInto(n *big.Int, buf []byte, offset int) int {
88
+ // Create a copy to avoid modifying the input n
89
+ tempN := new(big.Int).Set(n)
90
+ pos := offset
91
+
92
+ // Use a temporary big.Int for calculations to avoid allocations in the loop
93
+ octet := new(big.Int)
94
+
95
+ for {
96
+ octet.And(tempN, big7f) // octet = tempN & 0x7f
97
+ tempN.Rsh(tempN, 7) // tempN = tempN >> 7
98
+
99
+ if pos >= len(buf) {
100
+ panic("varint: buffer too small for UnsignedEncodeInto")
101
+ }
102
+
103
+ if tempN.Cmp(big0) == 0 { // No more bits to encode
104
+ buf[pos] = byte(octet.Uint64()) // No continuation bit
105
+ pos++
106
+ break
107
+ } else {
108
+ // There are more bits, so set the continuation bit (0x80)
109
+ octet.Or(octet, big80)
110
+ buf[pos] = byte(octet.Uint64())
111
+ pos++
112
+ }
113
+ }
114
+ return pos - offset
115
+ }
116
+
117
+ // UnsignedDecode ULEB128 decodes a number from buf starting at offset.
118
+ // It returns the decoded number, the number of bytes read, and an error if any.
119
+ func UnsignedDecode(buf []byte, offset int) (result *big.Int, length int, err error) {
120
+ result = big.NewInt(0)
121
+ var shift uint = 0
122
+ pos := offset
123
+
124
+ // Use a temporary big.Int for calculations to avoid allocations in the loop
125
+ octetVal := new(big.Int)
126
+
127
+ for {
128
+ if pos >= len(buf) {
129
+ return nil, 0, errors.New("varint: buffer too short for UnsignedDecode")
130
+ }
131
+ octet := buf[pos]
132
+ pos++
133
+
134
+ // Get the 7-bit value part
135
+ octetVal.SetInt64(int64(octet & 0x7F))
136
+
137
+ // Shift it and OR into the result
138
+ octetVal.Lsh(octetVal, shift)
139
+ result.Or(result, octetVal)
140
+
141
+ if (octet & 0x80) == 0 { // Check continuation bit
142
+ return result, pos - offset, nil
143
+ }
144
+
145
+ shift += 7
146
+ // Protect against varints that are too long for a 256-bit number (max 37 bytes).
147
+ // Max shift for data in the 37th byte is (37-1)*7 = 252.
148
+ // shift > 252 indicates processing beyond the 37th byte.
149
+ // (pos - offset) > 37 indicates more than 37 bytes read.
150
+ if shift > 63 && (pos-offset) > 9 {
151
+ return nil, 0, errors.New("varint: varint too large for 64-bit")
152
+ }
153
+ }
154
+ }
155
+
156
+ // --- ZigZag Encoding ---
157
+
158
+ // toZigZag converts a signed integer n to an unsigned integer suitable for ULEB128 encoding.
159
+ func toZigZag(n *big.Int) *big.Int {
160
+ if n.BitLen() > 63 { // keep parity with Erlang’s 64-bit limit
161
+ panic("varint: value out of int64 range")
162
+ }
163
+ res := new(big.Int).Lsh(n, 1)
164
+ if n.Sign() < 0 {
165
+ res.Xor(res, bigNeg1)
166
+ }
167
+ return res.And(res, big.NewInt(0).SetUint64(^uint64(0))) // mask 64 bits
168
+ }
169
+
170
+ // fromZigZag converts an unsigned integer n (decoded from ULEB128) back to a signed integer.
171
+ func fromZigZag(n *big.Int) *big.Int {
172
+ res := new(big.Int)
173
+ temp := new(big.Int).And(n, big1)
174
+
175
+ res.Rsh(n, 1)
176
+ if temp.Cmp(big1) == 0 { // If the last bit of n is 1 (sign bit for negative original)
177
+ // ^ (~0) which is XOR with -1 for big.Int
178
+ res.Xor(res, bigNeg1)
179
+ }
180
+ return res
181
+ }
182
+
183
+ // ZigZagEncode encodes a signed integer n using ZigZag and ULEB128.
184
+ func ZigZagEncode(n *big.Int) []byte {
185
+ zz := toZigZag(n)
186
+ return UnsignedEncode(zz)
187
+ }
188
+
189
+ // ZigZagEncodeInto encodes a signed integer n into buf using ZigZag and ULEB128.
190
+ // Returns the number of bytes written.
191
+ // Panics if the buffer is too small.
192
+ func ZigZagEncodeInto(n *big.Int, buf []byte, offset int) int {
193
+ zz := toZigZag(n)
194
+ return UnsignedEncodeInto(zz, buf, offset)
195
+ }
196
+
197
+ // ZigZagDecode decodes a ZigZag-ULEB128 encoded number from buf.
198
+ // Returns the decoded signed number, bytes read, and an error.
199
+ func ZigZagDecode(buf []byte, offset int) (result *big.Int, length int, err error) {
200
+ unsignedVal, l, err := UnsignedDecode(buf, offset)
201
+ if err != nil {
202
+ return nil, 0, err
203
+ }
204
+ return fromZigZag(unsignedVal), l, nil
205
+ }
206
+
207
+ // --- Convenience functions for int64/uint64 if needed ---
208
+ // These are often useful as big.Int can be overkill for common integer sizes.
209
+
210
+ // UnsignedEncodeUint64 ULEB128 encodes a uint64.
211
+ func UnsignedEncodeUint64(val uint64) []byte {
212
+ n := new(big.Int).SetUint64(val)
213
+ return UnsignedEncode(n)
214
+ }
215
+
216
+ // UnsignedDecodeToUint64 ULEB128 decodes to a uint64.
217
+ // Returns an error if the decoded value overflows uint64.
218
+ func UnsignedDecodeToUint64(buf []byte, offset int) (result uint64, length int, err error) {
219
+ bn, l, err := UnsignedDecode(buf, offset)
220
+ if err != nil {
221
+ return 0, 0, err
222
+ }
223
+ if !bn.IsUint64() {
224
+ return 0, l, errors.New("varint: value overflows uint64")
225
+ }
226
+ return bn.Uint64(), l, nil
227
+ }
228
+
229
+ // ZigZagEncodeInt64 encodes an int64 using ZigZag and ULEB128.
230
+ func ZigZagEncodeInt64(val int64) []byte {
231
+ n := big.NewInt(val)
232
+ return ZigZagEncode(n)
233
+ }
234
+
235
+ // ZigZagDecodeToInt64 decodes a ZigZag-ULEB128 encoded number to int64.
236
+ // Returns an error if the decoded value overflows int64.
237
+ func ZigZagDecodeToInt64(buf []byte, offset int) (result int64, length int, err error) {
238
+ bn, l, err := ZigZagDecode(buf, offset)
239
+ if err != nil {
240
+ return 0, 0, err
241
+ }
242
+ if !bn.IsInt64() {
243
+ return 0, l, errors.New("varint: value overflows int64")
244
+ }
245
+ return bn.Int64(), l, nil
246
+ }