-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse extensions correctly. Allow options more. #242
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -781,6 +781,16 @@ fn get_modules(module: &str, imported: bool, desc: &FileDescriptor) -> String { | |
.collect() | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Extend { | ||
/// The message being extended. | ||
pub name: String, | ||
/// All fields that are being added to the extended message. | ||
pub fields: Vec<Field>, | ||
} | ||
|
||
impl Extend {} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Message { | ||
pub name: String, | ||
|
@@ -796,6 +806,8 @@ pub struct Message { | |
pub path: PathBuf, | ||
pub import: PathBuf, | ||
pub index: MessageIndex, | ||
/// Allowed extensions for this message, None if no extensions. | ||
pub extensions: Option<Extensions>, | ||
} | ||
|
||
impl Message { | ||
|
@@ -885,13 +897,10 @@ impl Message { | |
writeln!(w, "use std::borrow::Cow;")?; | ||
} | ||
} | ||
} else if config.nostd { | ||
if messages | ||
} else if config.nostd && messages | ||
.iter() | ||
.any(|m| m.all_fields().any(|f| (f.typ.has_bytes_and_string()))) | ||
{ | ||
writeln!(w, "use alloc::borrow::ToOwned;")?; | ||
} | ||
.any(|m| m.all_fields().any(|f| (f.typ.has_bytes_and_string()))) { | ||
writeln!(w, "use alloc::borrow::ToOwned;")?; | ||
} | ||
|
||
if config.nostd | ||
|
@@ -1476,6 +1485,22 @@ impl RpcService { | |
|
||
pub type RpcGeneratorFunction = Box<dyn Fn(&RpcService, &mut dyn Write) -> Result<()>>; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Extensions { | ||
pub from: i32, | ||
/// Max number is 536,870,911 (2^29 - 1), as defined in the | ||
/// protobuf docs | ||
pub to: i32, | ||
} | ||
|
||
impl Extensions { | ||
/// The max field number that can be used as an extension. | ||
pub fn max() -> i32 { | ||
536870911 | ||
} | ||
|
||
} | ||
Comment on lines
+1488
to
+1502
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear this is related, but orthogonal functionality to
This is the functionality for
|
||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Enumerator { | ||
pub name: String, | ||
|
@@ -1841,6 +1866,7 @@ pub struct FileDescriptor { | |
pub package: String, | ||
pub syntax: Syntax, | ||
pub messages: Vec<Message>, | ||
pub message_extends: Vec<Extend>, | ||
pub enums: Vec<Enumerator>, | ||
pub module: String, | ||
pub rpc_services: Vec<RpcService>, | ||
|
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Automatically generated rust module for 'data_types_import.proto' file | ||
|
||
#![allow(non_snake_case)] | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(unused_imports)] | ||
#![allow(unknown_lints)] | ||
#![allow(clippy::all)] | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
||
|
||
use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; | ||
use core::convert::{TryFrom, TryInto}; | ||
use quick_protobuf::sizeofs::*; | ||
use super::super::*; | ||
|
||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Debug, Default, PartialEq, Clone)] | ||
pub struct ImportedMessage { | ||
pub i: bool, | ||
} | ||
|
||
impl<'a> MessageRead<'a> for ImportedMessage { | ||
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> { | ||
let mut msg = Self::default(); | ||
while !r.is_eof() { | ||
match r.next_tag(bytes) { | ||
Ok(8) => msg.i = r.read_bool(bytes)?, | ||
Ok(t) => { r.read_unknown(bytes, t)?; } | ||
Err(e) => return Err(e), | ||
} | ||
} | ||
Ok(msg) | ||
} | ||
} | ||
|
||
impl MessageWrite for ImportedMessage { | ||
fn get_size(&self) -> usize { | ||
0 | ||
+ if self.i == false { 0 } else { 1 + sizeof_varint(*(&self.i) as u64) } | ||
} | ||
|
||
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> { | ||
if self.i != false { w.write_with_tag(8, |w| w.write_bool(*&self.i))?; } | ||
Ok(()) | ||
} | ||
} | ||
|
||
|
||
impl TryFrom<&[u8]> for ImportedMessage { | ||
type Error=quick_protobuf::Error; | ||
|
||
fn try_from(buf: &[u8]) -> Result<Self> { | ||
let mut reader = BytesReader::from_bytes(&buf); | ||
Ok(ImportedMessage::from_reader(&mut reader, &buf)?) | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Automatically generated mod.rs | ||
pub mod b; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this extend struct, which hopefully will be incorporated into the compiler eventually (possibly by me), but we may want to switch to #235 first.