<div dir="ltr">Sorry if this is a duplicate, I am having trouble with gmail.<br><div><div class="gmail_quote"><div class="HOEnZb"><div class="h5"><br>
On 10/20/2015 12:38 AM, Bryce Harrington wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Oct 20, 2015 at 12:01:14AM -0700, Bryce Harrington wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Oct 19, 2015 at 11:21:23PM +0100, Auke Booij wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Introduce the enum and bitfield attributes, which allow you to refer to the enum<br>
you are expecting in an argument, and specify which enums are to be thought of<br>
as bitfields.<br>
<br>
+ Additionally, the protocol can specify <type>enum</type>s. These are used<br>
+ to list options for <type>int</type> and <type>uint</type> type arguments.<br>
+ Arguments can refer to the specific enumeration that is semantically<br>
+ implied. Only in the case that the argument is of type <type>uint</type>,<br>
+ it can be specified that the primary interface to its numeric value deals<br>
+ with bitwise operations, for example when arbitrarily many choices of the<br>
+ enum can be ORed together.<br>
+ </para><br>
+ <para><br>
+ The purpose of the <type>enum</type> and <type>bitfield</type> attributes<br>
+ is to document what arguments refer to which enums, and to document which<br>
+ numeric enum values are primarily accessed using bitwise operations.<br>
+ Additionally, the enum and bitfield attributes may be used by other code,<br>
+ such as bindings to other languages, for example to enhance type safety of<br>
+ code. However, such usage is only supported if the following property is<br>
+ satisfied: code written prior to the specification of these attributes<br>
+ still works after their specification. In other words, specifying an<br>
+ attribute for an argument, that previously did not have an enum or<br>
+ bitfield attribute, should not break API. Code that does not satisfy this<br>
+ rule is not guaranteed to obey backwards compatibility.<br>
</blockquote>
This next chunk gets a bit too jarringly technical too quickly. I think<br>
your second paragraph gives a better intro to these attributes, but it<br>
doesn't work to simply swap them. Let me take a shot at copyediting<br>
this a bit:<br>
<br>
I think this is clearer, and hopefully hasn't lost any meaning. I'm not<br>
sure it's improved the technicality of this prose... perhaps this<br>
section would be better promoted to its own section, with maybe just a<br>
reference sentence included here? Not sure.<br>
</blockquote>
I'm noticing now that I've misunderstood what the bitfield attribute is;<br>
so the above text is incorrect. Let me try again.<br>
Additionally, the protocol can specify <type>enum</type>s which<br>
associate specific numeric enumeration values. These are<br>
primarily just description in nature: at the wire format level<br>
enums are just integers. But they also serve a secondary purpose<br>
to enhance type safety or otherwise add context for use in<br>
language bindings or other such code. This latter usage is only<br>
supported so long as code written before these attributes were<br>
introduced still works after; in other words, adding an enum<br>
should not break API, otherwise it puts backwards compatibility<br>
at risk.<br>
<br>
<type>enum</type>s can be defined as bitfields or just a set of<br>
integers. This is specified via the <type>bitfield</type><br>
boolean attribute in the <type>enum</type> definition. If this<br>
attribute is true, the enum is intended to be accessed primarily<br>
using bitwise operations, for example when arbitrarily many<br>
choices of the enum can be ORed together; if it is false, or the<br>
attribute is omitted, then the enum arguments are a just a<br>
sequence of numerical values.<br>
<br>
The <type>enum</type> attribute can be used on either<br>
<type>uint</type> or <type>int</type> arguments, however if the<br>
<type>enum</type> is defined as a <type>bitfield</type>, it can<br>
only be used on <type>uint</type> args.<br>
</blockquote>
<br></div></div>
This version definitely better, though you might be able to skip the "This is specified via..." sentence since it is describing low-level xml syntax that it seems the rest is skipping (for instance there is no description of the syntax to actually assign name-value pairs).<br>
<br>
I'm not really certain about the back-compatiblity section. Does this mean that if previously somebody was able to pass 42 unchanged to a message, that it still has to work? Or are we allowed to assume that previously people used the enumeration names and not raw numbers? I think it might be best to delete this. Treatment of back-compatibility is probably something that the language binding writers can decide.<br>
<br>
Bitfields also allow certain values to be tested somehow, ie there is a test(v, enum_constant) function of some type that returns true/false. It is ok if this only works for enum_constants whose value is a power of 2. Not sure how to word this...<br>
<br>
"sequence" might also be misleading. The values do not have to be consecutive. In particular there may be more than one name for the same value. Maybe use "set" instead.<br>
<br>
May also want to indicate that despite the support for int, I think negative enum values are not allowed.<br>
<br>
My attempt:<span class=""><br>
<br>
Additionally, the protocol can specify <type>enum</type>s which<br></span>
associate a set of names with numeric values and indicate that<br>
only those names should be used for this argument. These are<span class=""><br>
primarily just description in nature: at the wire format level<br></span>
enums are just integers. But a language binding can use<br>
them to enhance type safety and provide descriptive context.<span class=""><br>
<br>
<type>enum</type>s can be defined as bitfields or just a set of<br></span>
integers. A bitfield enum must support the ability to 'or' together<br>
multiple named values to produce a value that can be put in a message,<br>
and the ability to test a value from an event against any value that<br>
is a power of two. A non-bitfield enum does not<br>
have to support this and it may be desirable to prohibit it.<br>
<br>
In a few cases there will be the need to pass arbitrary numbers<br>
for an enum value. A language binding will need to provide some<br>
way to convert an arbitrary number to the enum value, and to compare<br>
an enum value to an arbitrary number.<br>
A <type>uint</type> argument should be used (this is provided for<br>
back-compatibility with parsers that predate the enum attribute).<br>
For historic reasons, non-bitfield attributes can use a<br>
<type>int</type> instead of <type>uint</type> but this should<br>
not be done for any new protocol.<br>
<br>
</div><br></div></div>