1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![doc(html_root_url = "https://docs.rs/prost/0.9.0")]
#![cfg_attr(not(feature = "std"), no_std)]
#[doc(hidden)]
pub extern crate alloc;
#[doc(hidden)]
pub use bytes;
mod error;
mod message;
mod types;
#[doc(hidden)]
pub mod encoding;
pub use crate::error::{DecodeError, EncodeError};
pub use crate::message::Message;
use bytes::{Buf, BufMut};
use crate::encoding::{decode_varint, encode_varint, encoded_len_varint};
#[cfg(not(feature = "no-recursion-limit"))]
const RECURSION_LIMIT: u32 = 100;
pub fn encode_length_delimiter<B>(length: usize, buf: &mut B) -> Result<(), EncodeError>
where
B: BufMut,
{
let length = length as u64;
let required = encoded_len_varint(length);
let remaining = buf.remaining_mut();
if required > remaining {
return Err(EncodeError::new(required, remaining));
}
encode_varint(length, buf);
Ok(())
}
pub fn length_delimiter_len(length: usize) -> usize {
encoded_len_varint(length as u64)
}
pub fn decode_length_delimiter<B>(mut buf: B) -> Result<usize, DecodeError>
where
B: Buf,
{
let length = decode_varint(&mut buf)?;
if length > usize::max_value() as u64 {
return Err(DecodeError::new(
"length delimiter exceeds maximum usize value",
));
}
Ok(length as usize)
}
#[cfg(feature = "prost-derive")]
#[allow(unused_imports)]
#[macro_use]
extern crate prost_derive;
#[cfg(feature = "prost-derive")]
#[doc(hidden)]
pub use prost_derive::*;