pbio

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 4 Imported by: 1

README

PB IO

Test License

Protobuf IO is a Ruby equivalent of https://godoc.org/github.com/gogo/protobuf/io.

Installation

Add gem 'pbio' to your Gemfile.

Usage

File.open("file.txt", "w") do |f|
  pbio = PBIO::Delimited.new(f)
  pbio.write MyProtoMsg.new(title: "Foo")
  pbio.write MyProtoMsg.new(title: "Bar")
end

File.open("file.txt", "r") do |f|
  pbio = PBIO::Delimited.new(f)
  pbio.read MyProtoMsg # => #<MyProtoMsg: title: "Foo">
  pbio.read MyProtoMsg # => #<MyProtoMsg: title: "Bar">
  pbio.read MyProtoMsg # => nil
  f.eof?               # => true
end

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes protobuf messages from an underlying reader.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder inits a new Decoder.

func (*Decoder) Decode

func (d *Decoder) Decode(msg proto.Message) error

Decode decodes a message.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder encodes protobuf messages and writes to the underlying writer.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder inits a new encoder.

func (*Encoder) Encode

func (e *Encoder) Encode(msg proto.Message) error

Encode encodes a message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL