Skip to content

Commit 21a7f5f

Browse files
brillstfx-copybara
authored andcommitted
Disallow the string_view optimization if message format is not "binary".
PiperOrigin-RevId: 354168926
1 parent 202d7ff commit 21a7f5f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

struct2tensor/expression_impl/proto.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ def calculate(
507507
needed_fields = _get_needed_fields(destinations)
508508
backing_str_tensor = None
509509
if options.use_string_view:
510+
assert self._message_format == "binary", (
511+
"`options.use_string_view` is only compatible with 'binary' message "
512+
"format. Please create the root expression with "
513+
"message_format='binary'.")
510514
backing_str_tensor = self._tensor_of_protos
511515
fields = parse_message_level_ex.parse_message_level_ex(
512516
self._tensor_of_protos,

struct2tensor/ops/struct2tensor_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def parse_message_level(
160160
# TODO(b/172576749): Once we allow sufficient bake in time for the kernel
161161
# change, switch to using V3 only.
162162
if backing_str_tensor:
163+
assert message_format == "binary", (
164+
"message_format must be 'binary' if a backing_str_tensor is provided")
163165
values, indices = gen_decode_proto_sparse.decode_proto_sparse_v3(
164166
tensor_of_protos,
165167
backing_str_tensor,

0 commit comments

Comments
 (0)