forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Translate between different versions of prost-types #3
Merged
+164
−7
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
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 |
---|---|---|
|
@@ -271,4 +271,3 @@ fn main() { | |
// Emit the aforementioned stanzas. | ||
tracker.emit_rerun_stanzas(); | ||
} | ||
|
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,10 +1,10 @@ | ||
use bytes::BytesMut; | ||
use vector_lib::codecs::encoding::ProtobufSerializer; | ||
use prost::Message; | ||
use std::num::NonZeroUsize; | ||
use tokio_util::codec::Encoder; | ||
use vector_lib::request_metadata::RequestMetadata; | ||
use vector_lib::codecs::encoding::ProtobufSerializer; | ||
use vector_lib::event::Finalizable; | ||
use vector_lib::request_metadata::RequestMetadata; | ||
|
||
use super::proto::third_party::google::cloud::bigquery::storage::v1 as proto; | ||
use super::service::BigqueryRequest; | ||
|
@@ -48,7 +48,9 @@ | |
) -> (NonZeroUsize, proto::append_rows_request::ProtoData) { | ||
let proto_data = proto::append_rows_request::ProtoData { | ||
writer_schema: Some(proto::ProtoSchema { | ||
proto_descriptor: Some(self.protobuf_serializer.descriptor_proto().clone()), | ||
proto_descriptor: Some(translate_descriptor_proto( | ||
self.protobuf_serializer.descriptor_proto().clone(), | ||
)), | ||
}), | ||
rows: Some(proto::ProtoRows { serialized_rows }), | ||
}; | ||
|
@@ -136,6 +138,160 @@ | |
} | ||
} | ||
|
||
/// Convert from `prost_reflect::prost_types::DescriptorProto` to `prost_types::DescriptorProto` | ||
/// | ||
/// Someone upgraded `prost_reflect` without upgrading the other prost crates, | ||
/// so the `prost_types` version used by `prost_reflect` is newer than the version used by vector. | ||
/// | ||
/// This function discards any `UninterpretedOption`s. | ||
/// | ||
/// "Why don't you just upgrade `prost_types` to match the version used by `prost_reflect`? | ||
/// Ha. Hahaha. Hahahahahahaha. My branches are littered with the corpses of such attempts. | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
Hahahahahahaha is not a recognized word. (unrecognized-spelling)
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.
im sorry |
||
fn translate_descriptor_proto( | ||
old_descriptor: prost_reflect::prost_types::DescriptorProto, | ||
) -> prost_types::DescriptorProto { | ||
prost_types::DescriptorProto { | ||
name: old_descriptor.name, | ||
field: old_descriptor | ||
.field | ||
.into_iter() | ||
.map(|field| prost_types::FieldDescriptorProto { | ||
name: field.name, | ||
number: field.number, | ||
label: field.label, | ||
r#type: field.r#type, | ||
type_name: field.type_name, | ||
extendee: field.extendee, | ||
default_value: field.default_value, | ||
oneof_index: field.oneof_index, | ||
json_name: field.json_name, | ||
options: field.options.map(|options| prost_types::FieldOptions { | ||
ctype: options.ctype, | ||
packed: options.packed, | ||
jstype: options.jstype, | ||
lazy: options.lazy, | ||
deprecated: options.deprecated, | ||
weak: options.weak, | ||
uninterpreted_option: Default::default(), | ||
}), | ||
proto3_optional: field.proto3_optional, | ||
}) | ||
.collect(), | ||
extension: old_descriptor | ||
.extension | ||
.into_iter() | ||
.map(|field| prost_types::FieldDescriptorProto { | ||
name: field.name, | ||
number: field.number, | ||
label: field.label, | ||
r#type: field.r#type, | ||
type_name: field.type_name, | ||
extendee: field.extendee, | ||
default_value: field.default_value, | ||
oneof_index: field.oneof_index, | ||
json_name: field.json_name, | ||
options: field.options.map(|options| prost_types::FieldOptions { | ||
ctype: options.ctype, | ||
packed: options.packed, | ||
jstype: options.jstype, | ||
lazy: options.lazy, | ||
deprecated: options.deprecated, | ||
weak: options.weak, | ||
uninterpreted_option: Default::default(), | ||
}), | ||
proto3_optional: field.proto3_optional, | ||
}) | ||
.collect(), | ||
nested_type: old_descriptor | ||
.nested_type | ||
.into_iter() | ||
.map(translate_descriptor_proto) | ||
.collect(), | ||
enum_type: old_descriptor | ||
.enum_type | ||
.into_iter() | ||
.map(|enum_descriptor| prost_types::EnumDescriptorProto { | ||
name: enum_descriptor.name, | ||
value: enum_descriptor | ||
.value | ||
.into_iter() | ||
.map(|value| prost_types::EnumValueDescriptorProto { | ||
name: value.name, | ||
number: value.number, | ||
options: value.options.map(|options| prost_types::EnumValueOptions { | ||
deprecated: options.deprecated, | ||
uninterpreted_option: Default::default(), | ||
}), | ||
}) | ||
.collect(), | ||
options: enum_descriptor | ||
.options | ||
.map(|options| prost_types::EnumOptions { | ||
allow_alias: options.allow_alias, | ||
deprecated: options.deprecated, | ||
uninterpreted_option: Default::default(), | ||
}), | ||
reserved_range: enum_descriptor | ||
.reserved_range | ||
.into_iter() | ||
.map( | ||
|reserved_range| prost_types::enum_descriptor_proto::EnumReservedRange { | ||
start: reserved_range.start, | ||
end: reserved_range.end, | ||
}, | ||
) | ||
.collect(), | ||
reserved_name: enum_descriptor.reserved_name, | ||
}) | ||
.collect(), | ||
extension_range: old_descriptor | ||
.extension_range | ||
.into_iter() | ||
.map( | ||
|extension_range| prost_types::descriptor_proto::ExtensionRange { | ||
start: extension_range.start, | ||
end: extension_range.end, | ||
options: extension_range | ||
.options | ||
.map(|_| prost_types::ExtensionRangeOptions { | ||
uninterpreted_option: Default::default(), | ||
}), | ||
}, | ||
) | ||
.collect(), | ||
oneof_decl: old_descriptor | ||
.oneof_decl | ||
.into_iter() | ||
.map(|oneof| prost_types::OneofDescriptorProto { | ||
name: oneof.name, | ||
options: oneof.options.map(|_| prost_types::OneofOptions { | ||
uninterpreted_option: Default::default(), | ||
}), | ||
}) | ||
.collect(), | ||
options: old_descriptor | ||
.options | ||
.map(|options| prost_types::MessageOptions { | ||
message_set_wire_format: options.message_set_wire_format, | ||
no_standard_descriptor_accessor: options.no_standard_descriptor_accessor, | ||
deprecated: options.deprecated, | ||
map_entry: options.map_entry, | ||
uninterpreted_option: Default::default(), | ||
}), | ||
reserved_range: old_descriptor | ||
.reserved_range | ||
.into_iter() | ||
.map( | ||
|reserved_range| prost_types::descriptor_proto::ReservedRange { | ||
start: reserved_range.start, | ||
end: reserved_range.end, | ||
}, | ||
) | ||
.collect(), | ||
reserved_name: old_descriptor.reserved_name, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use bytes::{BufMut, Bytes, BytesMut}; | ||
|
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.
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.
Check failure
Code scanning / check-spelling
Unrecognized Spelling Error