def StructuredPropertyToProto(prop, index):
  """Converts a structured property to the corresponding message field.

  Args:
    prop: The NDB property to be converted.
    index: The index of the property within the message.

  Returns:
    A message field with attributes corresponding to those in prop, index
        corresponding to that which was passed in and with underlying message
        class equal to the message class produced by the model class, which
        should be a subclass of EndpointsModel.

  Raises:
    TypeError if the model class of the property does not have a callable
        ProtoModel method. This is because we expected a subclass of
        EndpointsModel set on the structured property.
  """
  modelclass = prop._modelclass
  try:
    property_proto_method = modelclass.ProtoModel
    property_proto = property_proto_method()
  except (AttributeError, __HOLE__):
    error_msg = ('Structured properties must receive a model class with a '
                 'callable ProtoModel attribute. The class %s has no such '
                 'attribute.' % (modelclass.__name__,))
    raise TypeError(error_msg)

  # No default for {MessageField}s
  kwargs = GetKeywordArgs(prop, include_default=False)
  return messages.MessageField(property_proto, index, **kwargs)
dataset/ETHPy150Open GoogleCloudPlatform/endpoints-proto-datastore/endpoints_proto_datastore/ndb/utils.py/StructuredPropertyToProto