Help improve this documentation
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
Encoding/Gob operatorsโ
This page lists all operators available in the encoding/gob sub-package of ro.
Installโ
First, import the sub-package in your project:
go get -u github.com/samber/ro/plugins/encoding/gob
Encodeโ
Encodes values to gob binary format.
import (
"github.com/samber/ro"
rogob "github.com/samber/ro/plugins/encoding/gob"
)
obs := ro.Pipe[int, []byte](
ro.Just(42),
rogob.Encode[int](),
)
sub := obs.Subscribe(ro.PrintObserver[[]byte]())
defer sub.Unsubscribe()
// Next: [3 4 0 84]
// CompletedPrototype:func Encode[T any]()Decodeโ
Decodes gob binary format to typed values.
import (
"github.com/samber/ro"
rogob "github.com/samber/ro/plugins/encoding/gob"
)
encoded := []byte{37, 255, 141, 3, 1, 1, 6, 80, 101, 114, 115, 111, 110, 1, 255, 142, 0, 1, 2, 1, 4, 78, 97, 109, 101, 1, 12, 0, 1, 3, 65, 103, 101, 1, 4, 0, 0, 0, 12, 255, 142, 1, 5, 65, 108, 105, 99, 101, 1, 60, 0}
obs := ro.Pipe[[]byte, Person](
ro.Just(encoded),
rogob.Decode[Person](),
)
sub := obs.Subscribe(ro.PrintObserver[Person]())
defer sub.Unsubscribe()
// Next: {Alice 30}
// CompletedPrototype:func Decode[T any]()