From 7bd2b92a6250201f431a92fee9900809536c81c0 Mon Sep 17 00:00:00 2001 From: William Vu Date: Thu, 23 Jan 2025 22:27:30 -0600 Subject: [PATCH] Add transform.PackBigInt64 And a test for it. --- transform/encode.go | 12 ++++++++++++ transform/encode_test.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/transform/encode.go b/transform/encode.go index 561bc29..2732990 100644 --- a/transform/encode.go +++ b/transform/encode.go @@ -197,3 +197,15 @@ func PackBigInt32(n int) string { return packed.String() } + +// PackBigInt64 packs a big-endian 64-bit integer as a string. +func PackBigInt64(n int) string { + var packed strings.Builder + + err := binary.Write(&packed, binary.BigEndian, int64(n)) + if err != nil { + output.PrintFrameworkError(err.Error()) + } + + return packed.String() +} diff --git a/transform/encode_test.go b/transform/encode_test.go index dd4356e..509fedd 100644 --- a/transform/encode_test.go +++ b/transform/encode_test.go @@ -174,6 +174,16 @@ func TestPackBigInt32(t *testing.T) { t.Log(packed) } +func TestPackBigInt64(t *testing.T) { + packed := PackBigInt64(0x4142434445464748) + + if packed != "ABCDEFGH" { + t.Fatal(packed) + } + + t.Log(packed) +} + func TestInflate(t *testing.T) { compressed := "\x1f\x8b\x08\x08\xf4\xe9\x97\x66\x00\x03\x77\x61\x74\x00\x2b\x2b\xcd\xc9\x4b\xce\x48\x4d\xce\xe6\x02\x00\x3d\xf1\xb3\xf9\x0a\x00\x00\x00" inflated, ok := Inflate([]byte(compressed))