aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/bytes.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-27 23:15:44 +0800
committerobscuren <geffobscura@gmail.com>2014-04-27 23:16:53 +0800
commit338b6980915c990c6e6287a7249ddd98e6be20eb (patch)
treed5c33a03c473dab1de0daade37a2d12986084faa /ethutil/bytes.go
parent16e52327a4baa5547c38965fce53b3ff40b98173 (diff)
downloadgo-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.gz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.bz2
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.lz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.xz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.zst
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.zip
Refactoring and added documentation comments
Diffstat (limited to 'ethutil/bytes.go')
-rw-r--r--ethutil/bytes.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index 40903a5f1..957fa254a 100644
--- a/ethutil/bytes.go
+++ b/ethutil/bytes.go
@@ -6,6 +6,9 @@ import (
"fmt"
)
+// Number to bytes
+//
+// Returns the number in bytes with the specified base
func NumberToBytes(num interface{}, bits int) []byte {
buf := new(bytes.Buffer)
err := binary.Write(buf, binary.BigEndian, num)
@@ -16,6 +19,9 @@ func NumberToBytes(num interface{}, bits int) []byte {
return buf.Bytes()[buf.Len()-(bits/8):]
}
+// Bytes to number
+//
+// Attempts to cast a byte slice to a unsigned integer
func BytesToNumber(b []byte) uint64 {
var number uint64
@@ -32,7 +38,9 @@ func BytesToNumber(b []byte) uint64 {
return number
}
-// Read variable integer in big endian
+// Read variable int
+//
+// Read a variable length number in big endian byte order
func ReadVarint(reader *bytes.Reader) (ret uint64) {
if reader.Len() == 8 {
var num uint64
@@ -55,6 +63,9 @@ func ReadVarint(reader *bytes.Reader) (ret uint64) {
return ret
}
+// Binary length
+//
+// Returns the true binary length of the given number
func BinaryLength(num int) int {
if num == 0 {
return 0