示例#1
0
 def test_parse_external_extension(self):
   user_info = test_pb2.UserInfo()
   user_info.Extensions[
       test_extension_pb2.MyExternalExtension.ext].special = "shhh"
   expected_value = test_extension_pb2.MyExternalExtension()
   expected_value.special = "shhh"
   tensor_of_protos = tf.constant([user_info.SerializeToString()])
   [field_tuple] = struct2tensor_ops.parse_message_level(
       tensor_of_protos,
       test_pb2.UserInfo().DESCRIPTOR,
       ["(struct2tensor.test.MyExternalExtension.ext)"])
   self.assertAllEqual(field_tuple.index, [0])
   self.assertAllEqual(field_tuple.value, [expected_value.SerializeToString()])
def _create_any_protos():
    my_value_0 = test_pb2.AllSimple()
    my_value_0.optional_int32 = 0
    my_value_1 = test_pb2.UserInfo()
    my_value_2 = test_pb2.AllSimple()
    my_value_2.optional_int32 = 20
    return [_create_any(x) for x in [my_value_0, my_value_1, my_value_2]]
示例#3
0
def _get_user_info_with_extension():
    my_user_info = test_pb2.UserInfo()
    my_user_info.Extensions[
        test_extension_pb2.MyExternalExtension.ext].special = "shhh"

    serialized = [my_user_info.SerializeToString()]
    return proto.create_expression_from_proto(
        serialized, test_any_pb2.MessageWithAny.DESCRIPTOR)
示例#4
0
def _get_expression_with_any():
  my_any_0 = test_any_pb2.MessageWithAny()
  my_value_0 = test_pb2.AllSimple()
  my_value_0.optional_int32 = 0
  my_any_0.my_any.Pack(my_value_0)
  my_any_1 = test_any_pb2.MessageWithAny()
  my_value_1 = test_pb2.UserInfo()
  my_any_1.my_any.Pack(my_value_1)
  my_any_2 = test_any_pb2.MessageWithAny()
  my_value_2 = test_pb2.AllSimple()
  my_value_2.optional_int32 = 20
  my_any_2.my_any.Pack(my_value_2)
  serialized = [x.SerializeToString() for x in [my_any_0, my_any_1, my_any_2]]
  return proto.create_expression_from_proto(
      serialized, test_any_pb2.MessageWithAny.DESCRIPTOR)