google-app-enginepython-2.7google-cloud-endpointsprotorpc

protorpc reading list from caller with FieldList


I have a webservice that is supposed to read a list from a caller, do some work, and then return a response.

  @endpoints.method(ARequestMessage, AResponseMessage,
                    name="call", path="call")
  def call(self, request):
    aList = request.in_list
    for stuff in aList:
       "do work here"
    return when I am done

Will the following ARequestMessage class work?

class ARequestMessage(messages.Message):
  name = messages.StringField(1, required=True)
  in_list = messages.FieldList(2, required=True)

I am not sure about my usage of FieldList in structure or in context. Please include a bit of code in response.


Solution

  • FieldList is not meant to be used, what you want is the repeated=True argument to your field:

    class ARequestMessage(messages.Message):
      name = messages.StringField(1, required=True)
      in_list = messages.StringField(2, repeated=True)