閱讀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接入_設備端接入手冊_阿裏雲物聯網套件-阿裏雲