将对象转换为协议缓冲区时,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
is auint
而不是uint?
,它总是被设置为 0,尽管 protobuf 定义将它指定为可选。
这是预期的结果吗?我应该以不同的方式生成 RpbIndexReq 消息以确保在适当的情况下通过线路发送空值?