How to define a user defined MessageField like DateTimeField

24 views
Skip to first unread message

tevin joseph

unread,
Jul 16, 2013, 6:38:38 AM7/16/13
to google-prot...@googlegroups.com
Hi,

I would like to create a user defined MessageField like DateTimeField. I have created one as follows:

class ErrorMessage(Message):
    code = StringField(1, required=True)
    message = StringField(2, required=True)
    reference = StringField(3, required=True)

class ErrorField(MessageField):
    message_type = ErrorMessage

    @util.positional(3)
    def __init__(self, number, **kwargs):
        super(ErrorField, self).__init__(self.message_type, number, **kwargs)

Is it sound right? I have used this ErrorField  as one of the field in response class of Google cloud endpoints. It works well with JS client but when used with android, error object  gets in the format error="".  Thanks in advance.

         return  MyResponse(
            isSaved=False,
            error=ErrorMessage(code="200", message=simplejson.dumps(form.errors), reference="form validation error")
           )

         from protorpc.messages import Message, StringField, MessageField

         class MyResponse(Message):
            isSaved = StringField(1, required=True)
            error = ErrorField(2, required = False)


Danny Hermes

unread,
Jul 16, 2013, 1:04:24 PM7/16/13
to google-prot...@googlegroups.com
Why do you need this for Cloud Endpoints? Can you post this on Stack Overflow?


--
You received this message because you are subscribed to the Google Groups "ProtoRPC Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-protorpc-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Danny Hermes
Developer Programs Engineer

tevin joseph

unread,
Jul 23, 2013, 6:34:24 AM7/23/13
to google-prot...@googlegroups.com

Hi,

I have posted this on stack overflow. Please advice.

Thanks,

Tevin
To unsubscribe from this group and stop receiving emails from it, send an email to google-protorpc-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

alex

unread,
Dec 30, 2013, 6:19:55 AM12/30/13
to google-prot...@googlegroups.com, google-a...@googlegroups.com
(CCing google-appengine).

Here's another usecase for custom message field:


from google.appengine.datastore.datastore_query import Cursor

class CursorMessage(messages.Message):
  encoded = messages.StringField(1)

class CursorField(messages.MessageField):
  message_type = CursorMessage

  def value_from_message(self, message):
    """Converts CursorMessage to a datastore_query.Cursor."""
    return Cursor(urlsafe=message.encoded)

  def message_from_value(self, value):
    """Converts datastore_query.Cursor to a CursorMessage."""
    return CursorMessage(encoded=value.urlsafe())


What do you guys think, makes sense?

Thanks,
Alex.

To unsubscribe from this group and stop receiving emails from it, send an email to google-protorpc-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages