diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-21 00:09:10 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-21 00:09:10 +0800 |
commit | 3b45fedb81dade6fc65c663c76856a07261f30d0 (patch) | |
tree | 94c9d0a98b625ca5a8be59f5b780fd3bd54254c7 /common/bytes.go | |
parent | 76025cc4245f0abc0749f4d1e433be865107bf24 (diff) | |
parent | 36ec42e50c9367e86621ff58b8e3d835abbbad79 (diff) | |
download | dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar.gz dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar.bz2 dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar.lz dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar.xz dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.tar.zst dexon-3b45fedb81dade6fc65c663c76856a07261f30d0.zip |
Merge branch 'ethersphere-frontier/natspec' into develop
Diffstat (limited to 'common/bytes.go')
-rw-r--r-- | common/bytes.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/common/bytes.go b/common/bytes.go index 5bdacd810..5d1245107 100644 --- a/common/bytes.go +++ b/common/bytes.go @@ -147,6 +147,23 @@ func Hex2Bytes(str string) []byte { return h } +func Hex2BytesFixed(str string, flen int) []byte { + + h, _ := hex.DecodeString(str) + if len(h) == flen { + return h + } else { + if len(h) > flen { + return h[len(h)-flen : len(h)] + } else { + hh := make([]byte, flen) + copy(hh[flen-len(h):flen], h[:]) + return hh + } + } + +} + func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { ret = Hex2Bytes(str[2:]) |