Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Commit

Permalink
added Encode and Decode examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dchenk committed Apr 20, 2018
1 parent 5467229 commit a7bba7c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions msgp/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package msgp_test

import (
"fmt"
"os"

"github.com/dchenk/msgp/msgp"
)

func ExampleEncode() {
// Write out a message to a file:
file, err := os.Create("my-message")
if err != nil {
panic(err)
}
var theMessage msgp.Number
theMessage.AsInt(457)
err = msgp.Encode(file, &theMessage)
if err != nil {
panic(err)
}
}

func ExampleDecode() {
// Read the message in a file:
file, err := os.Open("my-message")
if err != nil {
panic(err)
}
var theMessage msgp.Number
err = msgp.Decode(file, &theMessage)
if err != nil {
panic(err)
}
fmt.Print(theMessage.Int())
}

0 comments on commit a7bba7c

Please sign in to comment.