MCPcopy Create free account
hub / github.com/apache/arrow / TypedView

Class TypedView

cpp/gdb_arrow.py:714–740  ·  view source on GitHub ↗

View a bytes-compatible object as a sequence of objects described by a struct format code.

Source from the content-addressed store, hash-verified

712
713
714class TypedView(Sequence):
715 """
716 View a bytes-compatible object as a sequence of objects described
717 by a struct format code.
718 """
719
720 def __init__(self, mem, mem_format):
721 assert isinstance(mem, memoryview)
722 self.mem = mem
723 self.mem_format = mem_format
724 self.byte_width = struct.calcsize('=' + mem_format)
725 self.length = mem.nbytes // self.byte_width
726
727 def _check_index(self, index):
728 if not 0 <= index < self.length:
729 raise IndexError("Wrong index for bitmap")
730
731 def __len__(self):
732 return self.length
733
734 def __getitem__(self, index):
735 self._check_index(index)
736 w = self.byte_width
737 # Cannot use memoryview.cast() because the 'e' format for half-floats
738 # is poorly supported.
739 mem = self.mem[index * w:(index + 1) * w]
740 return struct.unpack('=' + self.mem_format, mem)
741
742
743class Bitmap(Sequence):

Callers 1

viewMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected