A utility class for reading data from the memory-mapped binary counters file.
| 301 | |
| 302 | |
| 303 | class SharedDataAccess(object): |
| 304 | """A utility class for reading data from the memory-mapped binary |
| 305 | counters file.""" |
| 306 | |
| 307 | def __init__(self, data): |
| 308 | """Create a new instance. |
| 309 | |
| 310 | Args: |
| 311 | data: A handle to the memory-mapped file, as returned by mmap.mmap. |
| 312 | """ |
| 313 | self.data = data |
| 314 | |
| 315 | def ByteAt(self, index): |
| 316 | """Return the (unsigned) byte at the specified byte index.""" |
| 317 | return ord(self.CharAt(index)) |
| 318 | |
| 319 | def IntAt(self, index): |
| 320 | """Return the little-endian 32-byte int at the specified byte index.""" |
| 321 | word_str = self.data[index:index+4] |
| 322 | result, = struct.unpack("I", word_str) |
| 323 | return result |
| 324 | |
| 325 | def CharAt(self, index): |
| 326 | """Return the ascii character at the specified byte index.""" |
| 327 | return self.data[index] |
| 328 | |
| 329 | |
| 330 | class Counter(object): |
no outgoing calls
no test coverage detected
searching dependent graphs…