forked from protocolbuffers/upb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated some docs and removed/rearranged some obsolete stuff.
- Loading branch information
Showing
20 changed files
with
89 additions
and
3,719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
## <a name="cla"></a> Signing the CLA | ||
|
||
Please sign the [Google Contributor License Agreement | ||
(CLA)](https://cla.developers.google.com/) | ||
before sending pull requests. For any code changes to be | ||
accepted, the CLA must be signed. It's a quick process, I | ||
promise! | ||
# How to Contribute | ||
|
||
We'd love to accept your patches and contributions to this project. There are | ||
just a few small guidelines you need to follow. | ||
|
||
## Get in touch | ||
|
||
If your idea will take you more than, say, 30 minutes to | ||
implement, please get in touch first via the issue tracker | ||
to touch base about your plan. That will give an | ||
opportunity for early feedback and help avoid wasting your | ||
time. | ||
|
||
## Contributor License Agreement | ||
|
||
Contributions to this project must be accompanied by a Contributor License | ||
Agreement. You (or your employer) retain the copyright to your contribution; | ||
this simply gives us permission to use and redistribute your contributions as | ||
part of the project. Head over to <https://cla.developers.google.com/> to see | ||
your current agreements on file or to sign a new one. | ||
|
||
You generally only need to submit a CLA once, so if you've already submitted one | ||
(even if it was for a different project), you probably don't need to do it | ||
again. | ||
|
||
## Code Reviews | ||
|
||
All submissions, including submissions by project members, require review. We | ||
use GitHub pull requests for this purpose. Consult | ||
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||
information on using pull requests. | ||
|
||
## Community Guidelines | ||
|
||
This project follows [Google's Open Source Community | ||
Guidelines](https://opensource.google/conduct/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,62 @@ | ||
|
||
# μpb - a small protobuf implementation in C | ||
|
||
|Platform|Build Status| | ||
|--------|------------| | ||
|macOS|[](https://fusion.corp.google.com/projectanalysis/summary/KOKORO/prod%3Aupb%2Fmacos%2Fcontinuous)| | ||
|ubuntu|[](https://fusion.corp.google.com/projectanalysis/summary/KOKORO/prod%3Aupb%2Fubuntu%2Fcontinuous)| | ||
|
||
μpb (often written 'upb') is a small protobuf implementation written in C. | ||
|
||
upb generates a C API for creating, parsing, and serializing messages | ||
as declared in `.proto` files. upb is heavily arena-based: all | ||
messages always live in an arena (note: the arena can live in stack or | ||
static memory if desired). Here is a simple example: | ||
|
||
```c | ||
#include "conformance/conformance.upb.h" | ||
|
||
void foo(const char* data, size_t size) { | ||
upb_arena *arena; | ||
|
||
/* Generated message type. */ | ||
conformance_ConformanceRequest *request; | ||
conformance_ConformanceResponse *response; | ||
|
||
arena = upb_arena_new(); | ||
request = conformance_ConformanceRequest_parse(data, size, arena); | ||
response = conformance_ConformanceResponse_new(arena); | ||
|
||
switch (conformance_ConformanceRequest_payload_case(request)) { | ||
case conformance_ConformanceRequest_payload_protobuf_payload: { | ||
upb_strview payload = conformance_ConformanceRequest_protobuf_payload(request); | ||
// ... | ||
break; | ||
} | ||
|
||
case conformance_ConformanceRequest_payload_NOT_SET: | ||
fprintf(stderr, "conformance_upb: Request didn't have payload.\n"); | ||
break; | ||
|
||
default: { | ||
static const char msg[] = "Unsupported input format."; | ||
conformance_ConformanceResponse_set_skipped( | ||
response, upb_strview_make(msg, sizeof(msg))); | ||
break; | ||
} | ||
} | ||
|
||
/* Frees all messages on the arena. */ | ||
upb_arena_free(arena); | ||
} | ||
``` | ||
# μpb: small, fast C protos | ||
|
||
API and ABI are both subject to change! Please do not distribute | ||
as a shared library for this reason (for now at least). | ||
μpb (often written 'upb') is a small | ||
[protobuf](https://github.com/protocolbuffers/protobuf) implementation written | ||
in C. | ||
|
||
## Using upb in your project | ||
upb is the core runtime for protobuf languages extensions in | ||
[Ruby](https://github.com/protocolbuffers/protobuf/tree/master/ruby), | ||
[PHP](https://github.com/protocolbuffers/protobuf/tree/master/php), and (soon) | ||
Python. | ||
|
||
Currently only Bazel is supported (CMake support is partial and incomplete | ||
but full CMake support is an eventual goal). | ||
While upb offers a C API, the C API & ABI **are not stable**. For this reason, | ||
upb is not generally offered as a C library for direct consumption, and there | ||
are no releases. | ||
|
||
To use upb in your Bazel project, first add upb to your `WORKSPACE` file, | ||
either as a `git_repository()` or as a `new_local_repository()` with a | ||
Git Submodule. (For an example, see `examples/bazel/ in this repo). | ||
## Features | ||
|
||
```python | ||
# Add this to your WORKSPACE file. | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
upb has comparable speed to protobuf C++, but is an order of magnitude smaller | ||
in code size. | ||
|
||
git_repository( | ||
name = "upb", | ||
remote = "https://github.com/protocolbuffers/upb.git", | ||
commit = "d16bf99ac4658793748cda3251226059892b3b7b", | ||
) | ||
Like the main protobuf implementation in C++, it supports: | ||
|
||
load("@upb//bazel:workspace_deps.bzl", "upb_deps") | ||
- a generated API (in C) | ||
- reflection | ||
- binary & JSON wire formats | ||
- text format serialization | ||
- all standard features of protobufs (oneofs, maps, unknown fields, etc.) | ||
- full conformance with the protobuf conformance tests | ||
|
||
upb_deps() | ||
``` | ||
upb also supports some features that C++ does not: | ||
|
||
Then in your BUILD file you can add `upb_proto_library()` rules that | ||
generate code for a corresponding `proto_library()` rule. For | ||
example: | ||
|
||
```python | ||
# Add this to your BUILD file. | ||
load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library") | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
) | ||
|
||
upb_proto_library( | ||
name = "foo_upbproto", | ||
deps = [":foo_proto"], | ||
) | ||
|
||
cc_binary( | ||
name = "test_binary", | ||
srcs = ["test_binary.c"], | ||
deps = [":foo_upbproto"], | ||
) | ||
``` | ||
- **optional reflection:** generated messages are agnostic to whether | ||
reflection will be linked in or not. | ||
- **no global state:** no pre-main registration or other global state. | ||
- **fast reflection-based parsing:** messages loaded at runtime parse | ||
just as fast as compiled-in messages. | ||
|
||
However there are some features it does not support: | ||
|
||
Then in your `.c` file you can #include the generated header: | ||
- proto2 extensions (coming soon!) | ||
- text format parsing | ||
- deep descriptor verification: upb's descriptor validation is not is exhaustive | ||
as `protoc`. | ||
|
||
```c | ||
#include "foo.upb.h" | ||
## Install | ||
|
||
/* Insert code that uses generated types. */ | ||
For Ruby, use [RubyGems](https://rubygems.org/gems/google-protobuf): | ||
|
||
``` | ||
$ gem install google-protobuf | ||
``` | ||
|
||
## Lua bindings | ||
For PHP, use [PECL](https://pecl.php.net/package/protobuf): | ||
|
||
This repo has some Lua bindings for the core library. These are | ||
experimental and very incomplete. These are currently included in | ||
order to validate that the C API is suitable for wrapping. As the | ||
project matures these Lua bindings may become publicly available. | ||
``` | ||
$ sudo pecl install protobuf | ||
``` | ||
|
||
## Contact | ||
## Contributing | ||
|
||
Author: Josh Haberman ([[email protected]](mailto:[email protected]), | ||
[[email protected]](mailto:[email protected])) | ||
Please see [CONTRIBUTING.md](CONTRIBUTING.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.