OLD | NEW |
1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 | 8 |
9 def write_uvarint(w, val): | 9 def write_uvarint(w, val): |
10 """Writes a varint value to the supplied file-like object. | 10 """Writes a varint value to the supplied file-like object. |
11 | 11 |
12 Args: | 12 Args: |
13 w (object): A file-like object to write to. Must implement write. | 13 w (object): A file-like object to write to. Must implement write. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 byte = r.read(1) | 54 byte = r.read(1) |
55 if len(byte) == 0: | 55 if len(byte) == 0: |
56 raise ValueError('UVarint was not terminated') | 56 raise ValueError('UVarint was not terminated') |
57 | 57 |
58 byte = ord(byte) | 58 byte = ord(byte) |
59 result |= ((byte & 0b01111111) << (7 * count)) | 59 result |= ((byte & 0b01111111) << (7 * count)) |
60 count += 1 | 60 count += 1 |
61 if byte & 0b10000000 == 0: | 61 if byte & 0b10000000 == 0: |
62 break | 62 break |
63 return result, count | 63 return result, count |
OLD | NEW |