slidge-whatsapp 0.2.7__cp312-cp312-manylinux_2_36_aarch64.whl → 0.3.0b0__cp312-cp312-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.
Files changed (212) hide show
  1. slidge_whatsapp/contact.py +13 -3
  2. slidge_whatsapp/event.go +107 -37
  3. slidge_whatsapp/gateway.go +7 -63
  4. slidge_whatsapp/gateway.py +2 -3
  5. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.h +186 -169
  6. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +148 -134
  8. slidge_whatsapp/generated/whatsapp.c +1652 -1380
  9. slidge_whatsapp/generated/whatsapp.go +798 -687
  10. slidge_whatsapp/generated/whatsapp.py +1169 -1044
  11. slidge_whatsapp/generated/whatsapp_go.h +186 -169
  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 +33 -16
  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.0b0.dist-info}/METADATA +2 -2
  205. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0b0.dist-info}/RECORD +208 -161
  206. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi_amd64.go +0 -7
  207. slidge_whatsapp/vendor/golang.org/x/net/http2/config_go124.go +0 -61
  208. slidge_whatsapp/vendor/golang.org/x/net/http2/config_pre_go124.go +0 -16
  209. slidge_whatsapp/vendor/golang.org/x/net/http2/timer.go +0 -20
  210. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0b0.dist-info}/LICENSE +0 -0
  211. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0b0.dist-info}/WHEEL +0 -0
  212. {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0b0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,197 @@
1
+ // Package bitset provides a BitSet data structure backed by *big.Int,
2
+ // along with helpers for reading and writing bitsets in variable-length
3
+ // (self-delimiting) and fixed-length formats.
4
+ package bitset
5
+
6
+ import (
7
+ "fmt"
8
+ "math/big"
9
+
10
+ "github.com/beeper/argo-go/pkg/buf"
11
+ )
12
+
13
+ // BitSet implements a growable set of bits, backed by a *big.Int.
14
+ // It provides methods to get, set, and unset individual bits.
15
+ // The zero value of a BitSet is not ready for use; always use NewBitSet.
16
+ type BitSet struct {
17
+ val *big.Int
18
+ }
19
+
20
+ // NewBitSet creates and initializes a new BitSet to zero.
21
+ func NewBitSet() *BitSet {
22
+ return &BitSet{val: big.NewInt(0)}
23
+ }
24
+
25
+ // GetBit returns the boolean value of the bit at the given index.
26
+ // It panics if the index is negative.
27
+ func (bs *BitSet) GetBit(index int) bool {
28
+ if index < 0 {
29
+ panic("Bitset index must be positive")
30
+ }
31
+ return bs.val.Bit(index) == 1
32
+ }
33
+
34
+ // SetBit sets the bit at the given index to 1 (true).
35
+ // It panics if the index is negative.
36
+ // Returns the BitSet pointer for chaining.
37
+ func (bs *BitSet) SetBit(index int) *BitSet {
38
+ if index < 0 {
39
+ panic("Bitset index must be positive")
40
+ }
41
+ bs.val.SetBit(bs.val, index, 1)
42
+ return bs
43
+ }
44
+
45
+ // UnsetBit sets the bit at the given index to 0 (false).
46
+ // It panics if the index is negative.
47
+ // Returns the BitSet pointer for chaining.
48
+ func (bs *BitSet) UnsetBit(index int) *BitSet {
49
+ if index < 0 {
50
+ panic("Bitset index must be positive")
51
+ }
52
+ bs.val.SetBit(bs.val, index, 0)
53
+ return bs
54
+ }
55
+
56
+ // Bytes returns the raw byte representation of the BitSet's underlying *big.Int.
57
+ // The bytes are in big-endian order. Returns nil if the BitSet or its internal value is nil.
58
+ func (bs *BitSet) Bytes() []byte {
59
+ if bs == nil || bs.val == nil {
60
+ return nil
61
+ }
62
+ return bs.val.Bytes()
63
+ }
64
+
65
+ // VarBitSet provides methods for reading and writing variable-length, self-delimiting bitsets.
66
+ // In this format, each byte encodes 7 bits of data, with the least significant bit (LSB)
67
+ // acting as a continuation flag (1 means more bytes follow, 0 means this is the last byte).
68
+ type VarBitSet struct{}
69
+
70
+ // Read reads a variable-length, self-delimiting bitset from a buf.Read.
71
+ // It reconstructs the BitSet from bytes where each byte contributes 7 data bits
72
+ // and 1 continuation bit. It returns the number of bytes read, the resulting BitSet,
73
+ // and any error encountered during reading.
74
+ func (v *VarBitSet) Read(buf buf.Read) (int, *BitSet, error) {
75
+ bytesRead := 0
76
+ bitset := NewBitSet()
77
+ more := true
78
+ bitPos := 0
79
+ for more {
80
+ byteVal, err := buf.ReadByte()
81
+ if err != nil {
82
+ return bytesRead, nil, fmt.Errorf("failed to read byte for var bitset: %w", err)
83
+ }
84
+ bytesRead++
85
+ // byteVal is already a byte, no need to check if <0 or >255
86
+ shiftedVal := new(big.Int).Lsh(big.NewInt(int64((byteVal&0xff)>>1)), uint(bitPos))
87
+ bitset.val.Or(bitset.val, shiftedVal)
88
+ bitPos += 7
89
+ more = (byteVal & 1) == 1
90
+ }
91
+ return bytesRead, bitset, nil
92
+ }
93
+
94
+ // Write encodes a BitSet into a variable-length, self-delimiting byte slice.
95
+ // Each byte in the output slice contains 7 bits of data from the BitSet and one
96
+ // continuation bit (LSB). If the LSB is 1, more bytes follow; if 0, it's the last byte.
97
+ // The 'padToLength' argument ensures the output byte slice has at least that many bytes,
98
+ // padding with zero bytes (0x00, which represents zero value and no continuation) if necessary.
99
+ // Returns an error if the BitSet contains negative values (which is not typical for bitsets).
100
+ func (v *VarBitSet) Write(bs *BitSet, padToLength int) ([]byte, error) {
101
+ if bs.val.Sign() < 0 {
102
+ return nil, fmt.Errorf("Bitsets must only contain positive values")
103
+ }
104
+ var bytes []byte
105
+ // Make a copy to avoid modifying the original
106
+ valCopy := new(big.Int).Set(bs.val)
107
+ more := valCopy.Sign() > 0
108
+
109
+ for more {
110
+ byteValBig := new(big.Int).And(valCopy, big.NewInt(0x7f)) // Get the lowest 7 bits
111
+ byteVal := byteValBig.Int64() << 1 // Shift left to make space for the 'more' bit
112
+
113
+ valCopy.Rsh(valCopy, 7) // Shift right by 7 bits
114
+ more = valCopy.Sign() > 0
115
+ if more {
116
+ byteVal = byteVal | 1 // Set the 'more' bit
117
+ }
118
+ bytes = append(bytes, byte(byteVal))
119
+ }
120
+
121
+ if len(bytes) == 0 { // If original value was 0, loop didn't run.
122
+ bytes = append(bytes, 0x00)
123
+ }
124
+
125
+ if padToLength > len(bytes) {
126
+ padding := make([]byte, padToLength-len(bytes))
127
+ bytes = append(bytes, padding...)
128
+ }
129
+ return bytes, nil
130
+ }
131
+
132
+ // FixedBitSet provides methods for reading and writing fixed-length, undelimited bitsets.
133
+ // In this format, all 8 bits of each byte are used for data.
134
+ // The total length of the bitset in bytes must be known beforehand for reading.
135
+ type FixedBitSet struct{}
136
+
137
+ // Write encodes a BitSet into a fixed-length, undelimited byte slice.
138
+ // All 8 bits of each byte in the output are used for data from the BitSet.
139
+ // The 'padToLength' argument ensures the output byte slice has at least that many bytes,
140
+ // padding with zero bytes if necessary. The least significant bytes of the BitSet appear first.
141
+ // Returns an error if the BitSet contains negative values.
142
+ func (f *FixedBitSet) Write(bs *BitSet, padToLength int) ([]byte, error) {
143
+ if bs.val.Sign() < 0 {
144
+ return nil, fmt.Errorf("Bitsets must only contain positive values")
145
+ }
146
+ var bytes []byte
147
+ valCopy := new(big.Int).Set(bs.val)
148
+ more := valCopy.Sign() > 0
149
+
150
+ for more {
151
+ byteValBig := new(big.Int).And(valCopy, big.NewInt(0xff)) // Get the lowest 8 bits
152
+ byteVal := byteValBig.Uint64()
153
+ valCopy.Rsh(valCopy, 8) // Shift right by 8 bits
154
+ more = valCopy.Sign() > 0
155
+ bytes = append(bytes, byte(byteVal))
156
+ }
157
+
158
+ if len(bytes) == 0 && padToLength > 0 { // Handle case where bitset is 0
159
+ bytes = append(bytes, 0)
160
+ }
161
+
162
+ if padToLength > len(bytes) {
163
+ padding := make([]byte, padToLength-len(bytes))
164
+ bytes = append(bytes, padding...)
165
+ }
166
+ return bytes, nil
167
+ }
168
+
169
+ // Read reconstructs a BitSet from a fixed-length, undelimited sequence of bytes
170
+ // within a larger byte slice. 'pos' specifies the starting position in 'bytes',
171
+ // and 'length' specifies how many bytes to read to form the bitset.
172
+ // All 8 bits of each read byte contribute to the BitSet.
173
+ func (f *FixedBitSet) Read(bytes []byte, pos int, length int) (*BitSet, error) {
174
+ if pos+length > len(bytes) {
175
+ return nil, fmt.Errorf("not enough bytes to read fixed bitset of length %d from pos %d", length, pos)
176
+ }
177
+
178
+ bitset := NewBitSet()
179
+ bitPos := 0
180
+ for i := 0; i < length; i++ {
181
+ byteVal := bytes[pos+i]
182
+ shiftedVal := new(big.Int).Lsh(big.NewInt(int64(byteVal&0xff)), uint(bitPos))
183
+ bitset.val.Or(bitset.val, shiftedVal)
184
+ bitPos += 8
185
+ }
186
+ return bitset, nil
187
+ }
188
+
189
+ // BytesNeededForNumBits calculates the minimum number of bytes required to store
190
+ // a fixed-length bitset containing 'numBits' of information.
191
+ // This is equivalent to ceil(numBits / 8).
192
+ func (f *FixedBitSet) BytesNeededForNumBits(numBits int) int {
193
+ if numBits <= 0 {
194
+ return 0
195
+ }
196
+ return (numBits + 7) / 8 // Equivalent to Math.ceil(numBits / 8)
197
+ }
@@ -0,0 +1,420 @@
1
+ package buf
2
+
3
+ import (
4
+ "errors"
5
+ "io"
6
+ )
7
+
8
+ // BufPosition defines an interface for types that track a position.
9
+ type BufPosition interface {
10
+ Position() int64
11
+ SetPosition(position int64)
12
+ IncrementPosition(numBytes int64)
13
+ }
14
+
15
+ // Read defines an interface for readable buffers.
16
+ type Read interface {
17
+ BufPosition
18
+ io.Reader
19
+ io.ByteReader
20
+ Get(position int64) (byte, error)
21
+ Bytes() []byte
22
+ Len() int
23
+ Peek(n int) ([]byte, error)
24
+ }
25
+
26
+ // Write defines an interface for writable buffers.
27
+ type Write interface {
28
+ BufPosition
29
+ io.Writer
30
+ io.ByteWriter
31
+ Cap() int
32
+ }
33
+
34
+ // Buf is a dynamically-sized byte buffer, wrapping a []byte.
35
+ // It manages its own position, logical length, and capacity growth.
36
+ type Buf struct {
37
+ data []byte // Underlying byte slice
38
+ pos int64 // Current read/write position
39
+ length int64 // Logical length of the data written (number of valid bytes in data)
40
+ }
41
+
42
+ const defaultInitialBufferSize = 32 // Or a reasonable default like 16, 32, etc.
43
+
44
+ // NewBuf creates a new Buf with an initial capacity.
45
+ func NewBuf(initialCapacity int) *Buf {
46
+ if initialCapacity < 0 {
47
+ initialCapacity = defaultInitialBufferSize
48
+ }
49
+ return &Buf{
50
+ data: make([]byte, 0, initialCapacity),
51
+ pos: 0,
52
+ length: 0,
53
+ }
54
+ }
55
+
56
+ // Reset resets the buffer to be empty,
57
+ // but it retains the underlying storage for use by future writes by slicing data to zero length.
58
+ // Reset also resets the position and logical length to 0.
59
+ func (b *Buf) Reset() {
60
+ b.data = b.data[:0] // Keeps capacity, sets len to 0
61
+ b.pos = 0
62
+ b.length = 0
63
+ }
64
+
65
+ // Position returns the current position in the buffer.
66
+ func (b *Buf) Position() int64 {
67
+ return b.pos
68
+ }
69
+
70
+ // SetPosition sets the current position in the buffer.
71
+ // No bounds checking is performed on the position value itself,
72
+ // but subsequent operations (Read/Write) will handle boundaries.
73
+ func (b *Buf) SetPosition(position int64) {
74
+ b.pos = position
75
+ }
76
+
77
+ // IncrementPosition increments the current position by numBytes.
78
+ func (b *Buf) IncrementPosition(numBytes int64) {
79
+ b.pos += numBytes
80
+ }
81
+
82
+ // ensureCapacity ensures that the buffer has at least minCapacity.
83
+ // If the current capacity is insufficient, it grows the buffer,
84
+ // preserving the existing content up to b.length.
85
+ // After this call, cap(b.data) will be at least minCapacity,
86
+ // and len(b.data) will remain b.length (the old logical length).
87
+ func (b *Buf) ensureCapacity(minCapacity int64) {
88
+ currentCap := int64(cap(b.data))
89
+ if currentCap >= minCapacity {
90
+ return
91
+ }
92
+
93
+ newActualCap := currentCap
94
+ if newActualCap == 0 {
95
+ // If starting from zero capacity, choose a small default or minCapacity.
96
+ // Using a small default (e.g., 16) avoids too many small allocations
97
+ // if minCapacity is also very small.
98
+ if minCapacity < 16 {
99
+ newActualCap = 16
100
+ } else {
101
+ newActualCap = minCapacity
102
+ }
103
+ }
104
+
105
+ // Grow similar to Go's append strategy: double capacity until it's sufficient.
106
+ for newActualCap < minCapacity {
107
+ if newActualCap == 0 { // Should have been handled by initial assignment if currentCap was 0
108
+ newActualCap = minCapacity // Fallback if somehow 0
109
+ break
110
+ }
111
+ newActualCap *= 2
112
+ if newActualCap < 0 { // Overflow check
113
+ newActualCap = minCapacity // Max possible if overflow
114
+ break
115
+ }
116
+ }
117
+ // Final check if doubling overshot significantly but minCapacity is larger.
118
+ if newActualCap < minCapacity {
119
+ newActualCap = minCapacity
120
+ }
121
+
122
+ // Create new slice with new capacity, copy content up to current logical length (b.length).
123
+ // len of newData will be b.length.
124
+ newData := make([]byte, b.length, newActualCap)
125
+ if b.length > 0 {
126
+ copy(newData, b.data[:b.length])
127
+ }
128
+ b.data = newData
129
+ }
130
+
131
+ // Read reads up to len(p) bytes into p from the current position.
132
+ // It returns the number of bytes read and any error encountered.
133
+ // EOF is returned when no more bytes are available from the current position within the logical length.
134
+ func (b *Buf) Read(p []byte) (n int, err error) {
135
+ if b.pos < 0 {
136
+ // Reading from a negative position is invalid.
137
+ return 0, io.EOF // Or a specific error like "invalid position"
138
+ }
139
+
140
+ // Per io.Reader contract, if len(p) == 0, Read should return n == 0 and err == nil.
141
+ if len(p) == 0 {
142
+ return 0, nil
143
+ }
144
+
145
+ if b.pos >= b.length {
146
+ // Position is at or beyond the logical end of the buffer.
147
+ return 0, io.EOF
148
+ }
149
+
150
+ readableBytes := b.length - b.pos
151
+ numToRead := int64(len(p))
152
+
153
+ if numToRead > readableBytes {
154
+ numToRead = readableBytes
155
+ }
156
+
157
+ // This check is now effectively for numToRead > 0 after potentially being capped by readableBytes.
158
+ // If readableBytes was 0, b.pos >= b.length would have caught it.
159
+ // If len(p) was initially > 0 but numToRead became 0 due to readableBytes, it implies EOF.
160
+ if numToRead <= 0 {
161
+ return 0, io.EOF
162
+ }
163
+
164
+ copy(p, b.data[b.pos:b.pos+numToRead])
165
+ b.pos += numToRead
166
+ return int(numToRead), nil
167
+ }
168
+
169
+ // WriteBuf writes the content of bb into b at the current position.
170
+ // It updates b's position and length accordingly.
171
+ // Returns the number of bytes written from bb and any error encountered.
172
+ func (b *Buf) WriteBuf(bb *Buf) (n int, err error) {
173
+ return b.Write(bb.Bytes())
174
+ }
175
+
176
+ // Write writes len(p) bytes from p to the buffer at the current position.
177
+ // It returns the number of bytes written and any error encountered.
178
+ // If the write extends beyond the current logical length, the buffer's logical length is updated.
179
+ // If the write starts beyond the current logical length, the gap is filled with zeros.
180
+ func (b *Buf) Write(p []byte) (n int, err error) {
181
+ numBytesToWrite := len(p)
182
+ if numBytesToWrite == 0 {
183
+ return 0, nil
184
+ }
185
+
186
+ if b.pos < 0 {
187
+ // Writing to a negative position is invalid.
188
+ // Consider returning an error or panicking, as this indicates misuse.
189
+ return 0, errors.New("argo.Buf.Write: negative position")
190
+ }
191
+
192
+ endPos := b.pos + int64(numBytesToWrite)
193
+
194
+ newLogicalLength := b.length
195
+ if endPos > newLogicalLength {
196
+ newLogicalLength = endPos
197
+ }
198
+
199
+ if newLogicalLength > int64(cap(b.data)) {
200
+ b.ensureCapacity(newLogicalLength)
201
+ // After ensureCapacity, cap(b.data) >= newLogicalLength,
202
+ // and len(b.data) == b.length (the old logical length).
203
+ }
204
+
205
+ // Ensure len(b.data) is sufficient for the newLogicalLength.
206
+ // Reslicing b.data up to newLogicalLength will zero-fill any new bytes
207
+ // between the old b.length and newLogicalLength if newLogicalLength > len(b.data).
208
+ // This handles padding if b.pos > old b.length.
209
+ if newLogicalLength > int64(len(b.data)) {
210
+ b.data = b.data[:newLogicalLength]
211
+ }
212
+ // Now len(b.data) == newLogicalLength, and any extended parts are zero-initialized.
213
+
214
+ copy(b.data[b.pos:], p)
215
+
216
+ b.length = newLogicalLength
217
+ b.pos = endPos
218
+
219
+ return numBytesToWrite, nil
220
+ }
221
+
222
+ // ReadByte reads and returns the next byte from the current position.
223
+ // If no byte is available, it returns error io.EOF.
224
+ func (b *Buf) ReadByte() (byte, error) {
225
+ if b.pos < 0 {
226
+ return 0, io.EOF
227
+ }
228
+ if b.pos >= b.length {
229
+ return 0, io.EOF
230
+ }
231
+ val := b.data[b.pos]
232
+ b.pos++
233
+ return val, nil
234
+ }
235
+
236
+ // WriteByte writes a single byte to the buffer at the current position.
237
+ func (b *Buf) WriteByte(c byte) error {
238
+ if b.pos < 0 {
239
+ return errors.New("argo.Buf.WriteByte: negative position")
240
+ }
241
+
242
+ endPos := b.pos + 1
243
+ newLogicalLength := b.length
244
+ if endPos > newLogicalLength {
245
+ newLogicalLength = endPos
246
+ }
247
+
248
+ if newLogicalLength > int64(cap(b.data)) {
249
+ b.ensureCapacity(newLogicalLength)
250
+ }
251
+ if newLogicalLength > int64(len(b.data)) {
252
+ b.data = b.data[:newLogicalLength]
253
+ }
254
+
255
+ b.data[b.pos] = c
256
+
257
+ b.length = newLogicalLength
258
+ b.pos = endPos
259
+ return nil
260
+ }
261
+
262
+ // Get returns the byte at the given absolute position in the buffer,
263
+ // without advancing the current position.
264
+ // Position is relative to the start of the buffer's logical content.
265
+ func (b *Buf) Get(position int64) (byte, error) {
266
+ if position < 0 || position >= b.length {
267
+ return 0, io.EOF
268
+ }
269
+ return b.data[position], nil
270
+ }
271
+
272
+ // Bytes returns a slice of all logical bytes currently in the buffer.
273
+ // The returned slice is valid until the next write operation that might cause reallocation.
274
+ func (b *Buf) Bytes() []byte {
275
+ return b.data[:b.length]
276
+ }
277
+
278
+ // Len returns the current logical length of the buffer (number of bytes written).
279
+ func (b *Buf) Len() int {
280
+ return int(b.length)
281
+ }
282
+
283
+ // Cap returns the current capacity of the buffer's underlying storage.
284
+ func (b *Buf) Cap() int {
285
+ return cap(b.data)
286
+ }
287
+
288
+ // Peek returns the next n bytes from the current position without advancing the reader.
289
+ // The returned slice shares the underlying array of the buffer.
290
+ // If n is larger than the available bytes, Peek returns all available bytes.
291
+ func (b *Buf) Peek(n int) ([]byte, error) {
292
+ if n < 0 {
293
+ return nil, errors.New("argo.Buf.Peek: count cannot be negative")
294
+ }
295
+ if n == 0 {
296
+ return []byte{}, nil
297
+ }
298
+
299
+ if b.pos < 0 || b.pos >= b.length {
300
+ return nil, io.EOF // No bytes to peek if position is invalid or at/past end.
301
+ }
302
+
303
+ available := b.length - b.pos
304
+
305
+ if int64(n) > available {
306
+ return b.data[b.pos : b.pos+available], nil
307
+ }
308
+ return b.data[b.pos : b.pos+int64(n)], nil
309
+ }
310
+
311
+ // BufReadonly is a read-only wrapper around a byte slice.
312
+ // It's analogous to TypeScript's BufReadonly class.
313
+ type BufReadonly struct {
314
+ bytes []byte
315
+ pos int64
316
+ }
317
+
318
+ // NewBufReadonly creates a new BufReadonly wrapping the given byte slice.
319
+ // The provided slice is used directly and should not be modified externally
320
+ // if read-only behavior is to be guaranteed.
321
+ func NewBufReadonly(data []byte) *BufReadonly {
322
+ return &BufReadonly{bytes: data, pos: 0} // Initialize pos to 0
323
+ }
324
+
325
+ // Position returns the current position in the buffer.
326
+ func (br *BufReadonly) Position() int64 {
327
+ return br.pos
328
+ }
329
+
330
+ // SetPosition sets the current position in the buffer.
331
+ func (br *BufReadonly) SetPosition(position int64) {
332
+ br.pos = position
333
+ }
334
+
335
+ // IncrementPosition increments the current position by numBytes.
336
+ func (br *BufReadonly) IncrementPosition(numBytes int64) {
337
+ br.pos += numBytes
338
+ }
339
+
340
+ // Read reads up to len(p) bytes into p. It returns the number of bytes
341
+ // read (0 <= n <= len(p)) and any error encountered.
342
+ // If the buffer's read position is negative, it returns (0, io.EOF).
343
+ func (br *BufReadonly) Read(p []byte) (n int, err error) {
344
+ if br.pos < 0 {
345
+ return 0, io.EOF
346
+ }
347
+ if br.pos >= int64(len(br.bytes)) {
348
+ return 0, io.EOF
349
+ }
350
+ copied := copy(p, br.bytes[br.pos:])
351
+ br.pos += int64(copied)
352
+ return copied, nil
353
+ }
354
+
355
+ // ReadByte reads and returns the next byte from the buffer.
356
+ // If no byte is available, it returns error io.EOF.
357
+ // If the buffer's read position is negative, it returns (0, io.EOF).
358
+ func (br *BufReadonly) ReadByte() (byte, error) {
359
+ if br.pos < 0 {
360
+ return 0, io.EOF
361
+ }
362
+ if br.pos >= int64(len(br.bytes)) {
363
+ return 0, io.EOF
364
+ }
365
+ val := br.bytes[br.pos]
366
+ br.pos++
367
+ return val, nil
368
+ }
369
+
370
+ // Get returns the byte at the given absolute position in the buffer,
371
+ // without advancing the current position.
372
+ func (br *BufReadonly) Get(position int64) (byte, error) {
373
+ if position < 0 || position >= int64(len(br.bytes)) {
374
+ return 0, io.EOF
375
+ }
376
+ return br.bytes[position], nil
377
+ }
378
+
379
+ // Bytes returns all bytes in the buffer, regardless of position.
380
+ func (br *BufReadonly) Bytes() []byte {
381
+ return br.bytes
382
+ }
383
+
384
+ // Len returns the total length of the underlying byte slice.
385
+ func (br *BufReadonly) Len() int {
386
+ return len(br.bytes)
387
+ }
388
+
389
+ // Peek returns the next n bytes without advancing the reader.
390
+ // If n is negative, an error is returned. If n is 0, Peek returns an empty slice and no error.
391
+ // If the buffer's read position is out of bounds (negative or >= len(br.bytes)), it returns (nil, io.EOF).
392
+ // If n is larger than the available bytes from br.pos, Peek returns all available bytes and no error.
393
+ func (br *BufReadonly) Peek(n int) ([]byte, error) {
394
+ if n < 0 {
395
+ return nil, errors.New("argo.BufReadonly.Peek: count cannot be negative")
396
+ }
397
+ if n == 0 {
398
+ return []byte{}, nil
399
+ }
400
+ if br.pos < 0 || br.pos >= int64(len(br.bytes)) {
401
+ return nil, io.EOF
402
+ }
403
+
404
+ available := int64(len(br.bytes)) - br.pos
405
+ if available <= 0 { // Should be covered by above check, but good for safety.
406
+ return nil, io.EOF
407
+ }
408
+
409
+ if int64(n) > available {
410
+ return br.bytes[br.pos : br.pos+available], nil
411
+ }
412
+ return br.bytes[br.pos : br.pos+int64(n)], nil
413
+ }
414
+
415
+ // Make sure Buf implements Read and Write
416
+ var _ Read = (*Buf)(nil)
417
+ var _ Write = (*Buf)(nil)
418
+
419
+ // Make sure BufReadonly implements Read
420
+ var _ Read = (*BufReadonly)(nil)