![continuous integration](https://github.com/tokio-rs/prost/workflows/continuous%20integration/badge.svg)
[![Documentation](https://docs.rs/prost/badge.svg)](https://docs.rs/prost/)
[![Crate](https://img.shields.io/crates/v/prost.svg)](https://crates.io/crates/prost)
[![Dependency Status](https://deps.rs/repo/github/tokio-rs/prost/status.svg)](https://deps.rs/repo/github/tokio-rs/prost)
# *PROST!*
`prost` is a [Protocol Buffers](https://developers.google.com/protocol-buffers/)
implementation for the [Rust Language](https://www.rust-lang.org/). `prost`
generates simple, idiomatic Rust code from `proto2` and `proto3` files.
Compared to other Protocol Buffers implementations, `prost`
* Generates simple, idiomatic, and readable Rust types by taking advantage of
Rust `derive` attributes.
* Retains comments from `.proto` files in generated Rust code.
* Allows existing Rust types (not generated from a `.proto`) to be serialized
and deserialized by adding attributes.
* Uses the [`bytes::{Buf, BufMut}`](https://github.com/carllerche/bytes)
abstractions for serialization instead of `std::io::{Read, Write}`.
* Respects the Protobuf `package` specifier when organizing generated code
into Rust modules.
* Preserves unknown enum values during deserialization.
* Does not include support for runtime reflection or message descriptors.
## Using `prost` in a Cargo Project
First, add `prost` and its public dependencies to your `Cargo.toml`:
```
[dependencies]
prost = "0.10"
# Only necessary if using Protobuf well-known types:
prost-types = "0.10"
```
The recommended way to add `.proto` compilation to a Cargo project is to use the
`prost-build` library. See the [`prost-build` documentation](prost-build) for
more details and examples.
See the [snazzy repository](https://github.com/danburkert/snazzy) for a simple
start-to-finish example.
## Generated Code
`prost` generates Rust code from source `.proto` files using the `proto2` or
`proto3` syntax. `prost`'s goal is to make the generated code as simple as
possible.
### `protoc`
It's recommended to install `protoc` locally in your path to improve build times.
Prost uses `protoc` to parse protobuf files and will attempt to compile protobuf
from source requiring a C++ toolchain. For more info checkout the [`prost-build`](prost-build)
docs.
### Packages
Prost can now generate code for `.proto` files that don't have a package spec.
`prost` will translate the Protobuf package into
a Rust module. For example, given the `package` specifier:
[package]: https://developers.google.com/protocol-buffers/docs/proto#packages
```proto
package foo.bar;
```
All Rust types generated from the file will be in the `foo::bar` module.
### Messages
Given a simple message declaration:
```proto
// Sample message.
message Foo {
}
```
`prost` will generate the following Rust struct:
```rust
/// Sample message.
#[derive(Clone, Debug, PartialEq, Message)]
pub struct Foo {
}
```
### Fields
Fields in Protobuf messages are translated into Rust as public struct fields of the
corresponding type.
#### Scalar Values
Scalar value types are converted as follows:
| Protobuf Type | Rust Type |
| --- | --- |
| `double` | `f64` |
| `float` | `f32` |
| `int32` | `i32` |
| `int64` | `i64` |
| `uint32` | `u32` |
| `uint64` | `u64` |
| `sint32` | `i32` |
| `sint64` | `i64` |
| `fixed32` | `u32` |
| `fixed64` | `u64` |
| `sfixed32` | `i32` |
| `sfixed64` | `i64` |
| `bool` | `bool` |
| `string` | `String` |
| `bytes` | `Vec<u8>` |
#### Enumerations
All `.proto` enumeration types convert to the Rust `i32` type. Additionally,
each enumeration type gets a corresponding Rust `enum` type. For example, this
`proto` enum:
```proto
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
```
gets this corresponding Rust enum [1]:
```rust
pub enum PhoneType {
Mobile = 0,
Home = 1,
Work = 2,
}
```
You can convert a `PhoneType` value to an `i32` by doing:
```rust
PhoneType::Mobile as i32
```
The `#[derive(::prost::Enumeration)]` annotation added to the generated
`PhoneType` adds these associated functions to the type:
```rust
impl PhoneType {
pub fn is_valid(value: i32) -> bool { ... }
pub fn from_i32(value: i32) -> Option<PhoneType> { ... }
}
```
so you can convert an `i32` to its corresponding `PhoneType` value by doing,
for example:
```rust
let phone_type = 2i32;
match PhoneType::from_i32(phone_type) {
Some(PhoneType::Mobile) => ...,
Some(PhoneType::Home) => ...,
Some(PhoneType::Work) => ...,
None => ...,
}
```
Additionally, wherever a `proto` enum is used as a field in a `Message`, the
message will have 'accessor' methods to get/set the value of the field as the
Rust enum type. For instance, this proto `PhoneNumber` message that has a field
named `type` of type `PhoneType`:
```proto
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
```
will become the following Rust type [1] with methods `type` and `set_type`:
```rust
pub struct PhoneNumber {
pub number: String,
pub r#type: i32, // the `r#` is needed because `type` is a Rust keyword
}
impl PhoneNumber {
pub fn r#type(&self) -> PhoneType { ... }
pub fn set_type(&mut self, value: PhoneType) { ... }
}
```
Note that the getter methods will return the Rust enum's default value if the
field has an invalid `i32` value.
The `enum` type isn't used directly as a field, because the Protobuf spec
mandates that enumerations values are 'open', and decoding unrecognized
enumeration values must be possible.
[1] Annotations have been elided for clarity. See below for a full example.
#### Field Modifiers
Protobuf scalar value and enumeration message fields can have a modifier
depending on the Protobuf version. Modifiers change the corresponding type of
the Rust field:
| `.proto` Version | Modifier | Rust Type |
| --- | --- | --- |
| `proto2` | `optional` | `Option<T>` |
| `proto2` | `required` | `T` |
| `proto3` | default | `T` for scalar types, `Option<T>` otherwise |
| `proto3` | `optional` | `Option<T>` |
| `proto2`/`proto3` | `repeated` | `Vec<T>` |
Note that in `proto3` the default representation for all user-defined message
types is `Option<T>`, and for scalar types just `T` (during decoding, a missing
value is populated by `T::default()`). If you need a witness of the presence of
a scalar type `T`, use the `optional` modifier to enforce an `Option<T>`
representation in the generated Rust struct.
#### Map Fields
Map fields are converted to a Rust `HashMap` with key and value type converted
from the Protobuf key and value types.
#### Message Fields
Message fields are converted to the corresponding struct type. The table of
field modifiers above applies to message fields, except that `proto3` message
fields without a modifier (the default) will be wrapped in an `Option`.
Typically message fields are unboxed. `prost` will automatically box a message
field if the field type and the parent type are recursively nested in order to
avoid an infinite sized struct.
#### Oneof Fields
Oneof fields convert to a Rust enum. Protobuf `oneof`s types are not named, so
`prost` uses the name of the `oneof` field for the resulting Rust enum, and
defines the enum in a module under the struct. For example, a `proto3` message
such as:
```proto
message Foo {
oneof widget {
int32 quux = 1;
string bar = 2;
}
}
```
generates the following Rust[1]:
```rust
pub struct Foo {
pub widget: Option<foo::Widget>,
}
pub mod foo {
pub enum Widget {
Quux(i32),
Bar(String),
}
}
```
`oneof` fields are always wrapped in an `Option`.
[1] Annotations have been elided for clarity. See below for a full example.
### Services
`prost-build` allows a custom code-generator to be used for processing `service`
definitions. This can be used to output Rust traits according to an
application's specific needs.
### Generated Code Example
Example `.proto` file:
```proto
syntax = "proto3";
package tutorial;
message Pe
没有合适的资源?快使用搜索试试~ 我知道了~
BitBox02硬件钱包 固件代码_C语言_代码_下载
共2225个文件
rs:713个
h:438个
c:217个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 67 浏览量
2022-07-04
23:39:47
上传
评论
收藏 21.33MB ZIP 举报
温馨提示
BitBox02 是一个硬件钱包,通过存储私钥和签署交易来简化加密货币的安全处理。此存储库的内容是设备上使用的引导加载程序和固件。BitBox02 旨在主要与BitBox App一起使用,尽管第三方集成可以通过 BitBox02 API 进行。 固件的主要功能如下: 安全地接收和发送硬币。 通过触摸滑块和显示器与用户交互。 将种子备份到 microSD 卡。 通过在屏幕上显示 BIP39 助记符编码来备份种子。 导入 12、18 或 24 字 BIP39 助记符 从多个强熵源生成随机种子。 保护种子免受攻击者的侵害。 根据 BIP39 和 BIP32 从种子中派生密钥。 返回密钥路径的扩展公钥,以便应用程序可以找到所有未使用的交易输出。 显示密钥路径、硬币和脚本/地址类型的接收地址。 显示接收地址、交易金额和网络费用,并在确认后对每个输入进行签名。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
BitBox02硬件钱包 固件代码_C语言_代码_下载
(2225个子文件)
libarm_cortexM4l_math.a 2.2MB
libqtm_acq_samd51_0x000f.a 9KB
libqtm_touch_key_cm4_0x0002.a 4KB
libqtm_binding_layer_cm4_0x0005.a 4KB
libssp.a 8B
libssp_nonshared.a 8B
jonathancross.asc 205KB
tomasvrba.asc 21KB
TheCharlatan.asc 20KB
nickez.asc 8KB
x1ddos.asc 7KB
stadicus.asc 7KB
offbyn.asc 7KB
benma.asc 6KB
My1.asc 5KB
cstenglein.asc 3KB
strnbrg.asc 3KB
sutterseba.asc 3KB
beerosagos.asc 3KB
sha512_one_million_a.bin 64B
sha256_one_million_a.bin 32B
shake128.blb 161KB
shake256.blb 161KB
mac.blb 65KB
mac.blb 49KB
sha3_512.blb 48KB
sha3_384.blb 44KB
sha3_256.blb 40KB
sha3_224.blb 39KB
keccak_256_full.blb 3KB
sha512.blb 1KB
chacha20-legacy.blb 1KB
sha384.blb 943B
sha256.blb 831B
chacha20.blb 812B
sha224.blb 803B
sha512.blb 292B
md5.blb 245B
sha384.blb 244B
sha256.blb 196B
sha512_256.blb 196B
sha224.blb 184B
sha512_224.blb 184B
fixed.blb 182B
keccak_256.blb 174B
streebog512.blb 117B
streebog256.blb 84B
keccak_512.blb 73B
keccak_384.blb 57B
variable.blb 53B
variable.blb 40B
keccak_224.blb 37B
ffunicode.c 1.88MB
test_app_eth_sighash.c 896KB
eth_params.c 486KB
ff.c 248KB
test_cipher.c 184KB
hpl_sercom.c 82KB
hpl_usb.c 61KB
uECC.c 53KB
startup_samd51.c 44KB
hpl_aes.c 39KB
sd_mmc.c 38KB
test_keystore.c 35KB
bootloader.c 35KB
test_app_btc_common.c 35KB
font_a_17X18.c 33KB
u2f.c 31KB
sha2.c 31KB
qtouch.c 29KB
usbdc.c 27KB
keystore.c 26KB
memory.c 25KB
securechip.c 23KB
ugui.c 22KB
hpl_nvmctrl.c 21KB
test_memory.c 20KB
font_a_15X16.c 20KB
hpl_gclk.c 19KB
trinary_input_string.c 18KB
hpl_sdhc.c 18KB
test_u2f_hid.c 16KB
hal_aes_sync.c 16KB
hal_usb_device.c 16KB
font_a_11X12.c 16KB
password_11X12.c 16KB
btc_common.c 16KB
font_a_13X14.c 15KB
u2f_util_t.c 15KB
usb_processing.c 14KB
test_u2f_standard.c 12KB
font_a_11X10.c 12KB
hal_usart_async.c 11KB
hid.c 11KB
trinary_input_char.c 11KB
factorysetup.c 11KB
test_keystore_functional.c 11KB
test_restore.c 11KB
sd.c 11KB
font_a_9X9.c 11KB
共 2225 条
- 1
- 2
- 3
- 4
- 5
- 6
- 23
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功