diff options
| author | onur1 <onur1@onurgunduz.com> | 2022-01-08 00:11:20 +0100 |
|---|---|---|
| committer | onur1 <onur1@onurgunduz.com> | 2022-01-08 00:11:20 +0100 |
| commit | b4609bd07acf106df3fe9fb67856d9ae781200e0 (patch) | |
| tree | 9113c626efe4f382d173eb1be87571dc0a4eb80c /varint.go | |
| download | muxer-b4609bd07acf106df3fe9fb67856d9ae781200e0.tar.gz muxer-b4609bd07acf106df3fe9fb67856d9ae781200e0.zip | |
Init
Diffstat (limited to 'varint.go')
| -rw-r--r-- | varint.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/varint.go b/varint.go new file mode 100644 index 0000000..923f490 --- /dev/null +++ b/varint.go @@ -0,0 +1,38 @@ +package binproto + +import "math" + +var ( + n1 = uint64(math.Pow(2, 7)) + n2 = uint64(math.Pow(2, 14)) + n3 = uint64(math.Pow(2, 21)) + n4 = uint64(math.Pow(2, 28)) + n5 = uint64(math.Pow(2, 35)) + n6 = uint64(math.Pow(2, 42)) + n7 = uint64(math.Pow(2, 49)) + n8 = uint64(math.Pow(2, 56)) + n9 = uint64(math.Pow(2, 63)) +) + +func encodingLength(i uint64) int { + if i < n1 { + return 1 + } else if i < n2 { + return 2 + } else if i < n3 { + return 3 + } else if i < n4 { + return 4 + } else if i < n5 { + return 5 + } else if i < n6 { + return 6 + } else if i < n7 { + return 7 + } else if i < n8 { + return 8 + } else if i < n9 { + return 9 + } + return 10 +} |
