Skip to content

Commit

Permalink
Replace ctype=CORD with rust.blob extension field (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie authored Jan 18, 2024
1 parent 366a3ae commit 0553be4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pb-jelly-gen/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
EnumDescriptorProto,
EnumValueDescriptorProto,
FieldDescriptorProto,
FieldOptions,
FileDescriptorProto,
OneofDescriptorProto,
SourceCodeInfo,
Expand Down Expand Up @@ -324,7 +323,7 @@ def is_grpc_slices(self) -> bool:
def is_blob(self) -> bool:
return (
self.field.type == FieldDescriptorProto.TYPE_BYTES
and self.field.options.ctype == FieldOptions.CORD
and self.field.options.Extensions[extensions_pb2.blob]
)

def is_lazy_bytes(self) -> bool:
Expand Down Expand Up @@ -1786,7 +1785,7 @@ def calc_impls(

# If we use a Blob type, or GRPC Slice
if typ == FieldDescriptorProto.TYPE_BYTES and (
field.options.ctype == FieldOptions.CORD
field.options.Extensions[extensions_pb2.blob]
or field.options.Extensions[extensions_pb2.grpc_slices]
):
(impls_eq, impls_copy) = (False, False) # Blob is not eq/copy
Expand Down
3 changes: 2 additions & 1 deletion pb-jelly-gen/codegen/proto/rust/extensions_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pb-jelly-gen/codegen/rust/extensions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
// Generate this field in a Box as opposed to inline Option
optional bool box_it = 50000;
// Generates a `Lazy<VecSlice>`
optional bool grpc_slices = 50003;
// Generates a `Lazy<WrappedBlob>`
optional bool blob = 50010;
// Use a different Rust type which implements `pb::Message` to represent the field.
// All paths must be fully qualified, as in `::my_crate::full::path::to::type`.
// This only works with proto3.
Expand Down
2 changes: 1 addition & 1 deletion pb-jelly/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! of copying large buffers during serialization and deserialization.
//!
//! To support this, messages may contain zerocopy fields using the [`Lazy`] type.
//! `pb-jelly-gen` may generate these using the `CORD`, `grpc_slices`, or `zero_copy` options; they
//! `pb-jelly-gen` may generate these using the `blob`, `grpc_slices`, or `zero_copy` options; they
//! use different underlying types, which must implement [PbBuffer], but they all behave similarly.
//!
//! [PbBufferReader] and a [PbBufferWriter] have the opportunity to recognize [Lazy] fields.
Expand Down
3 changes: 3 additions & 0 deletions pb-test/proto/includes/rust/extensions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
// Generate this field in a Box as opposed to inline Option
optional bool box_it = 50000;
// Generates a `Lazy<VecSlice>`
optional bool grpc_slices = 50003;
// Generates a `Lazy<WrappedBlob>`
optional bool blob = 50010;
// Use a different Rust type which implements `pb::Message` to represent the field.
// All paths must be fully qualified, as in `::my_crate::full::path::to::type`.
// This only works with proto3.
Expand Down

0 comments on commit 0553be4

Please sign in to comment.