laconicd-deprecated/utils/int.go
Federico Kunze 66d19188f6
update tools configs (#611)
* update tools configs

* minor updates
2020-11-24 16:43:08 +01:00

48 lines
942 B
Go

package utils
import "math/big"
// MarshalBigInt marshalls big int into text string for consistent encoding
func MarshalBigInt(i *big.Int) (string, error) {
bz, err := i.MarshalText()
if err != nil {
return "", err
}
return string(bz), nil
}
// MustMarshalBigInt marshalls big int into text string for consistent encoding.
// It panics if an error is encountered.
func MustMarshalBigInt(i *big.Int) string {
str, err := MarshalBigInt(i)
if err != nil {
panic(err)
}
return str
}
// UnmarshalBigInt unmarshalls string from *big.Int
func UnmarshalBigInt(s string) (*big.Int, error) {
ret := new(big.Int)
err := ret.UnmarshalText([]byte(s))
if err != nil {
return nil, err
}
return ret, nil
}
// MustUnmarshalBigInt unmarshalls string from *big.Int.
// It panics if an error is encountered.
func MustUnmarshalBigInt(s string) *big.Int {
ret, err := UnmarshalBigInt(s)
if err != nil {
panic(err)
}
return ret
}