Standard library / math/big
big.Int.GobEncode()
Encode signed integer data for gob serialization; check errors and use GobDecode to reconstruct the value. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Int) GobEncode() ([]byte, error)Return Value
([]byte, error)
Returns the result described above; see the example for the observed behavior.
Working Example
Example Snippetgo
package main
import ( "fmt" "math/big")
func check(err error) { if err != nil { panic(err) }}func main() { b, e := big.NewInt(-42).GobEncode() check(e) z := new(big.Int) check(z.GobDecode(b)) fmt.Println(z.Cmp(big.NewInt(-42)) == 0)}