Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc ::bpacket::encode::varint {value} {
- if {$value < 128} { ; # 2**7
- append x [binary format c $value]
- return $x
- } elseif {$value < 16384} { ; # 2**14
- append x [binary format c [expr {($value & 127) | 128}]]
- append x [binary format c [expr {$value >> 7}]]
- return $x
- } elseif {$value < 2097152} { ;# 2**21
- append x [binary format c [expr {($value & 127) | 128}]]
- append x [binary format c [expr {(($value >> 7) & 127) | 128}]]
- append x [binary format c [expr {$value >> 14}]]
- return $x
- }
- set n 0; set sh 0
- while 1 {
- set b [expr {($value >> $sh) & 127}]
- incr sh 7
- incr n
- if {$value >> $sh} {
- append x [binary format c [expr {$b | 128}]]
- } else {
- append x [binary format c $b]
- return $x
- }
- }
- return $x
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement