mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-05 22:43:10 +00:00
panic handler + construct
This commit is contained in:
parent
47a6842e35
commit
3f5984c93d
10
codec.go
10
codec.go
@ -31,7 +31,15 @@ func StringToBytes(s string) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func BytesToString(b []byte) (string, error) {
|
||||
func BytesToString(b []byte) (ret string, err error) {
|
||||
// panic handler, in case we try accessing bytes incorrectly.
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
ret = ""
|
||||
err = e.(error)
|
||||
}
|
||||
}()
|
||||
|
||||
s := ""
|
||||
|
||||
for ; len(b) > 0 ; {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user