QMsgPack 更新 – 修正了键不支持非字符串类型的兼容性问题

【问题描述】

该问题是由于我对协议的理解出现差错造成的。MessagePack 协议不要求映射的键一定是字符串,所以键就可以是任何简单类型。新版加入了 KeyAsXXX 用来对不同类型的键进行支持:

    property KeyType: TQMsgPackType read FKeyType;
    property KeyAsString: QStringW read GetKeyAsString write SetKeyAsString;
    property KeyAsInt64: Int64 read GetKeyAsInt64 write SetKeyAsInt64;
    property KeyAsInteger: Integer read GetKeyAsInteger write SetKeyAsInteger;
    property KeyAsSingle: Single read GetKeyAsSingle write SetKeyAsSingle;
    property KeyAsFloat: Double read GetKeyAsFloat write SetKeyAsFloat;
    property KeyAsDateTime: TDateTime read GetKeyAsDateTime
      write SetKeyAsDateTime;
    property KeyAsBytes: TBytes read GetKeyAsBytes write SetKeyAsBytes;
    property KeyAsBoolean: Boolean read GetKeyAsBoolean write SetKeyAsBoolean;
    property KeyIsNull: Boolean read GetKeyIsNull;

其中,KeyType 表明了键的类型,KeyAsXXX 做为具体的类型赋值和取值的属性存在,KeyIsNull 可以用于检查是否设置了键的值。

老版本中的 Name 属性已经被直接映射为 KeyAsString ,从而达到兼容以前版本的目的。

另外,不建议使用浮点数做为键时,使用 ItemByName、ItemByPath、IndexOf 函数按键值的字符串表示来检索内容。

【严重级别】

【更新级别】

推荐

【特别感谢】

天地弦

分享到:

0 条评论

沙发空缺中,还不快抢~