Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

beefcake

> 编程语言
Open source

A sane Google Protocol Buffers library for Ruby

274 stars0 likes0 views
WebsiteGitHub

About

A sane Google Protocol Buffers library for Ruby

Beefcake

A pure-Ruby Google Protocol Buffers library. It's all about being Buf; ProtoBuf.

Installation

bash
gem install beefcake

Usage

…

Encoding

Any object responding to ` 1, :y => 2)

For example, you can encode into a String:

s = "" x.encode(s) s # => "\b\x01\x10\x02)\0"

If you don't encode into anything, a new Beefcake::Buffer will be returned:

x.encode # => #

And that buffer can be converted to a String:

x.encode.to_s # => "\b\x01\x10\x02)\0"


### Decoding

```ruby
# see code example above for the definition of Variety
x = Variety.new(:x => 1, :y => 2)

# You can decode from a Beefcake::Buffer
encoded = x.encode
Variety.decode(encoded) # => 

# Decoding from a String works the same way:
Variety.decode(encoded.to_s) # => 

# You can update a Beefcake::Message instance with new data too:
new_data = Variety.new(x: 12345, y: 2).encode
Variety.decoded(new_data, x)
x # => 

Generate code from .proto file

bash
protoc --beefcake_out output/path -I path/to/proto/files/dir path/to/file.proto

You can set the BEEFCAKE_NAMESPACE variable to generate the classes under a desired namespace. (i.e. App::Foo::Bar)

About

Ruby deserves and needs first-class ProtoBuf support. Other libs didn't feel very "Ruby" to me and were hard to parse.

This library was built with EventMachine in mind. Not just blocking-IO.

Source: https://github.com/protobuf-ruby/beefcake

Support Features

  • Optional fields
  • Required fields
  • Repeated fields
  • Packed Repeated Fields
  • Varint fields
  • 32-bit fields
  • 64-bit fields
  • Length-delimited fields
  • Embedded Messages
  • Unknown fields are ignored (as per spec)
  • Enums
  • Defaults (i.e. optional :foo, :string, :default => "bar")
  • Varint-encoded length-delimited message streams

Future

  • Imports
  • Use package in generation
  • Groups (would be nice for accessing older protos)

Further Reading

http://code.google.com/apis/protocolbuffers/docs/encoding.html

Testing

rake test

Beefcake conducts continuous integration on Travis CI. The current build status for HEAD is .

All pull requests automatically trigger a build request. Please ensure that tests succeed.

Currently Beefcake is tested and working on:

  • Ruby 1.9.3
  • Ruby 2.0.0
  • Ruby 2.1.0
  • Ruby 2.1.1
  • Ruby 2.1.2
  • JRuby in 1.9 mode

Thank You

  • Keith Rarick (kr) for help with encoding/decoding.
  • Aman Gupta (tmm1) for help with cross VM support and performance enhancements.

Issues· 8 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言