Standard library / math/big
big.Rat.GobDecode()
Decode gob rational representation into the receiver, checking errors. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '-2/3\n'.
Formal Syntax & Structure
go syntaxgo
func (z *Rat) GobDecode(buf []byte) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| buf | []byte | Byte buffer or encoded data, as specified in the method contract. |
Return Value
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.NewRat(-2, 3).GobEncode() check(e) z := new(big.Rat) check(z.GobDecode(b)) fmt.Println(z)}