将对象转换为协议缓冲区时,都会忽略ShouldSerialize *和* Specified方法。
鉴于使用-p:detectMissing
标志生成以下请求:
message RpbIndexReq {
enum IndexQueryType {
eq = 0;
range = 1;
}
required bytes bucket = 1;
required bytes index = 2;
required IndexQueryType qtype = 3;
optional bytes key = 4; // key here means equals value for index?
optional bytes range_min = 5;
optional bytes range_max = 6;
optional bool return_terms = 7;
optional bool stream = 8;
optional uint32 max_results = 9;
optional bytes continuation = 10;
}
max_results
初始化为0并通过电汇发送。
RpbIndexReq的生成如下:
private RiakResult<IList<string>> IndexGetRange(string bucket, string indexName, string minValue, string maxValue, RiakIndexGetOptions options = null)
{
var message = new RpbIndexReq
{
bucket = bucket.ToRiakString(),
index = indexName.ToRiakString(),
qtype = RpbIndexReq.IndexQueryType.range,
range_min = minValue.ToRiakString(),
range_max = maxValue.ToRiakString()
};
options = options ?? new RiakIndexGetOptions();
options.Populate(message);
/* at this point, message.max_results is 0 */
var result = UseConnection(conn => conn.PbcWriteRead<RpbIndexReq, RpbIndexResp>(message));
if (result.IsSuccess)
{
return RiakResult<IList<string>>.Success(result.Value.keys.Select(k => k.FromRiakString()).ToList());
}
return RiakResult<IList<string>>.Error(result.ResultCode, result.ErrorMessage, result.NodeOffline);
}
RpbIndexReq
对象包含以下内容:
private uint? _max_results;
[global::ProtoBuf.ProtoMember(9, IsRequired = false, Name=@"max_results", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)]
public uint max_results
{
get { return _max_results?? default(uint); }
set { _max_results = value; }
}
[global::System.Xml.Serialization.XmlIgnore]
[global::System.ComponentModel.Browsable(false)]
public bool max_resultsSpecified
{
get { return _max_results != null; }
set { if (value == (_max_results== null)) _max_results = value ? max_results : (uint?)null; }
}
private bool ShouldSerializemax_results() { return max_resultsSpecified; }
private void Resetmax_results() { max_resultsSpecified = false; }
由于max_results
是uint
而不是uint?
,所以尽管protobuf定义将其指定为可选项,但始终将其设置为0。
这是预期的结果吗? 我是否应该采用不同的方式生成RpbIndexReq消息,以确保在适当的地方通过线路发送空值?