Changeset 4574b4f1b1074c71a4cc2a2c75361462d9a8fc3b
- Timestamp:
- 03/28/08 00:28:44
(8 months ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1206682124 -0500
- git-parent:
[b46e10febbd9c882f90e4aa35ddd7f7af26ad53c]
- git-author:
- Jason Michalski <armooo@armooo.net> 1206682124 -0500
- Message:
Added Variable Length Integers for string size fields
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2578ef5 |
r4574b4f |
|
| 6 | 6 | import time |
|---|
| 7 | 7 | import warnings |
|---|
| | 8 | import itertools |
|---|
| 8 | 9 | |
|---|
| 9 | 10 | try: |
|---|
| … | … | |
| 212 | 213 | v = d[k] |
|---|
| 213 | 214 | |
|---|
| 214 | | l = len(k) | 128 |
|---|
| 215 | | output.append( struct.pack('>B', l) ) |
|---|
| | 215 | output.append( varint( len(k) ) ) |
|---|
| 216 | 216 | output.append( k ) |
|---|
| 217 | 217 | |
|---|
| … | … | |
| 223 | 223 | v = str(v) |
|---|
| 224 | 224 | output.append( struct.pack('>B', 0x01) ) |
|---|
| 225 | | l = len(v) | 128 |
|---|
| 226 | | output.append( struct.pack('>B', l) ) |
|---|
| | 225 | output.append( varint( len(v) ) ) |
|---|
| 227 | 226 | output.append( v ) |
|---|
| 228 | 227 | |
|---|
| … | … | |
| 233 | 232 | return ''.join(output) |
|---|
| 234 | 233 | |
|---|
| 235 | | |
|---|
| 236 | | if __name__ == '__main__': |
|---|
| 237 | | username = 'armooo@armooo.net' |
|---|
| 238 | | password = 'in(into)' |
|---|
| 239 | | tsn = '6520001802C0F2A' |
|---|
| 240 | | url = 'http://10.0.1.52:9032/Steph%27s%20Videos/Weekend%20%28Godard%201967%29.avi' |
|---|
| 241 | | |
|---|
| 242 | | mind = Mind(username, password, True) |
|---|
| 243 | | mind.pushVideo(tsn, url) |
|---|
| 244 | | |
|---|
| | 234 | def varint(i): |
|---|
| | 235 | import sys |
|---|
| | 236 | |
|---|
| | 237 | bits = [] |
|---|
| | 238 | while i: |
|---|
| | 239 | bits.append(i & 0x01) |
|---|
| | 240 | i = i >> 1 |
|---|
| | 241 | |
|---|
| | 242 | if not bits: |
|---|
| | 243 | output = [0] |
|---|
| | 244 | else: |
|---|
| | 245 | output = [] |
|---|
| | 246 | |
|---|
| | 247 | while bits: |
|---|
| | 248 | byte = 0 |
|---|
| | 249 | mybits = bits[:7] |
|---|
| | 250 | del bits[:7] |
|---|
| | 251 | |
|---|
| | 252 | for bit, p in zip(mybits, itertools.count()): |
|---|
| | 253 | byte += bit * (2 ** p) |
|---|
| | 254 | |
|---|
| | 255 | output.append(byte) |
|---|
| | 256 | |
|---|
| | 257 | output[-1] = output[-1] | 0x80 |
|---|
| | 258 | return ''.join([chr(b) for b in output]) |
|---|
| | 259 | |
|---|