aboutsummaryrefslogtreecommitdiff
path: root/network/protocol/sideband64k/helpers_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-25 16:22:03 +0000
committerGravatar Runxi Yu2026-03-25 16:22:03 +0000
commit311edcd50f3a84f4b860bde3cb887451d74eaa11 (patch)
treebe7aa5e9a51e636358f33b1c90637b5024b70dc3 /network/protocol/sideband64k/helpers_test.go
parentREADME: Split off contrib, benchmarks, remove history for now I guess, etc. (diff)
signatureNo signature
network/protocol: Rename from protocol v0.1.110
Diffstat (limited to 'network/protocol/sideband64k/helpers_test.go')
-rw-r--r--network/protocol/sideband64k/helpers_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/network/protocol/sideband64k/helpers_test.go b/network/protocol/sideband64k/helpers_test.go
new file mode 100644
index 00000000..f9b2608f
--- /dev/null
+++ b/network/protocol/sideband64k/helpers_test.go
@@ -0,0 +1,46 @@
+package sideband64k_test
+
+import (
+ "bytes"
+ "io"
+)
+
+type limitWriter struct {
+ buf bytes.Buffer
+ maxPerWrite int
+ flushes int
+ shortWrite bool
+}
+
+func (w *limitWriter) Write(p []byte) (int, error) {
+ if w.shortWrite {
+ return 0, nil
+ }
+
+ if w.maxPerWrite > 0 && len(p) > w.maxPerWrite {
+ p = p[:w.maxPerWrite]
+ }
+
+ return w.buf.Write(p)
+}
+
+func (w *limitWriter) Flush() error {
+ w.flushes++
+
+ return nil
+}
+
+type byteReader struct {
+ data []byte
+}
+
+func (r *byteReader) Read(p []byte) (int, error) {
+ if len(r.data) == 0 {
+ return 0, io.EOF
+ }
+
+ p[0] = r.data[0]
+ r.data = r.data[1:]
+
+ return 1, nil
+}