Numeric range not supported?

1,172 views
Skip to first unread message

Marco Tedone

unread,
May 30, 2011, 6:54:19 AM5/30/11
to Protocol Buffers
Hi all,

I'm checking the protobuf language definition and I couldn't find
anywhere support for numeric range. In XSD, for instance, one could
have:

<simpleType name="ZeroToTen">
<restriction base="int">
<minInclusive value="0" />
<maxInclusive value="10" />
</restriction>
</simpleType>

However I couldn't find equivalent translation in the proto language
definition. I could find defaults and enums, but not number ranges.

Regards,

Marco

Pherl Liu

unread,
Jun 2, 2011, 6:41:02 AM6/2/11
to Marco Tedone, Wenbo Zhu, Protocol Buffers
We also have another internal thread talking about the "restriction" support for protobuf. Basically we think the restriction or value validation function of protobuf should be implemented in the upper layer due to various concerns..


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Wenbo Zhu

unread,
Jun 2, 2011, 8:58:41 PM6/2/11
to Protocol Buffers


On Thu, Jun 2, 2011 at 5:55 PM, Wenbo Zhu <wen...@google.com> wrote:

On Thu, Jun 2, 2011 at 3:41 AM, Pherl Liu <liu...@google.com> wrote:
We also have another internal thread talking about the "restriction" support for protobuf. Basically we think the restriction or value validation function of protobuf should be implemented in the upper layer due to various concerns..
Protobuf definition is different than schema for "documents". Constraints may be specified externally or in the form of custom options.

I wonder if there is any standard meta-schema language that could be applied to both XML and non-XML data. UML is probably not a good choice here.

Ben Wright

unread,
Jun 2, 2011, 10:31:34 PM6/2/11
to Protocol Buffers
You can use custom field options to support validation of this type.

Take a look at extending com.google.FieldOptions

You can create an option field like "max_inclusive" and then access it
at run-time from the FieldDescriptor and use the information for
validation.

Unfortunately this is still just a "suggestion" - you will still have
to validate with custom-written code.

PS: I have done this before and it worked out pretty well because the
validation code did not have to have special information about the
data structure, just access to the FieldDescriptor at run time.

amalho...@gmail.com

unread,
Oct 22, 2013, 9:02:58 AM10/22/13
to prot...@googlegroups.com, compuw...@gmail.com
Ben - Could you show some examples on using FieldOptions for this kind of validation? How would you map the actual field name to its validation rules?
Reply all
Reply to author
Forward
0 new messages