Skip to main content
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
  • Encodes values to gob binary format.

    import (
    "github.com/samber/ro"
    rogob "github.com/samber/ro/plugins/encoding/gob"
    )

    obs := ro.Pipe(
    ro.Just(42),
    rogob.Encode[int](),
    )

    sub := obs.Subscribe(ro.PrintObserver[[]byte]())
    defer sub.Unsubscribe()

    // Next: [3 4 0 84]
    // Completed
    Prototype:
    func Encode[T any]()
  • 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(
    ro.Just(encoded),
    rogob.Decode[Person](),
    )

    sub := obs.Subscribe(ro.PrintObserver[Person]())
    defer sub.Unsubscribe()

    // Next: {Alice 30}
    // Completed
    Prototype:
    func Decode[T any]()