Esempio n. 1
0
    def _prepare_batch(self, items):
        """Encode a list of records into their batch representation, returning
        a tuple of the encoded physical key and value."""
        keytups = [key for key, _ in reversed(items)]
        phys = keylib.packs(keytups, self.prefix)

        if len(items) == 1:
            out = items[0][1]
        else:
            out = bytearray()
            keylib.write_int(len(items), out.append, 0)
            for _, data in items:
                keylib.write_int(len(data), out.append, 0)
            concat = ''.join(data for _, data in items)
            out.extend(self.compressor.pack(concat))
        return phys, bytes(out)
Esempio n. 2
0
    def _prepare_batch(self, items, packer):
        packer_prefix = self.store._encoder_prefix.get(packer)
        if not packer_prefix:
            packer_prefix = self.store.add_encoder(packer)
        keytups = [key for key, _ in reversed(items)]
        phys = keylib.packs(self.prefix, keytups)
        out = bytearray()

        if len(items) == 1:
            out.extend(packer_prefix)
            out.extend(packer.pack(items[0][1]))
        else:
            keylib.write_int(len(items), out.append, 0)
            for _, data in items:
                keylib.write_int(len(data), out.append, 0)
            out.extend(packer_prefix)
            concat = ''.join(data for _, data in items)
            out.extend(packer.pack(concat))
        return phys, str(out)