阅读982 返回首页    go 微信


附录__设备基于CCP接入_设备端接入手册_阿里云物联网套件-阿里云

CCP协议中字段类型为可变长数值,都需要使用该算法来实现。

The algorithm for encoding a decimal number (X) into the variable length encoding scheme is as follows:

  1. do
  2. digit = X MOD 128
  3. X = X DIV 128
  4. // if there are more digits to encode, set the top bit of this digit
  5. if ( X > 0 )
  6. digit = digit OR 0x80
  7. endif
  8. 'output' digit
  9. while ( X> 0 )

where MOD is the modulo operator (% in C), DIV is integer division (/ in C), and OR is bit-wise or (| in C).The algorithm for decoding the Number Length field is as follows:

  1. multiplier = 1
  2. value = 0
  3. do
  4. digit = 'next digit from stream'
  5. value += (digit AND 127) * multiplier
  6. multiplier *= 128
  7. while ((digit AND 128) != 0)

where AND is the bit-wise and operator (& in C).LS When this algorithm terminates, value contains the Remaining Length in bytes.

最后更新:2016-11-23 17:16:07

  上一篇:go 接入协议__设备基于MQTT接入_设备端接入手册_阿里云物联网套件-阿里云
  下一篇:go JAVA版demo__设备基于CCP接入_设备端接入手册_阿里云物联网套件-阿里云