# Path: cb_bin_client.py
# def encode_collection_id(cid: int) -> bytes:
#     output = array.array('B', [0])
#     while cid > 0:
#         byte = cid & 0xFF
#         cid >>= 7
#         # CID has more bits
#         if cid > 0:
#             # Set the 'continue' bit of this byte
#             byte |= 0x80
#             output[-1] = byte
#             output.append(0)
#         else:
#             output[-1] = byte
#     return output.tobytes()


import json
import random
import string
import struct
import couchbaseConstants
import pump
from typing import Any, Dict, Optional, Tuple
from cb_bin_client import encode_collection_id
                else:
                    key = str(self.cur_sets % self.cur_items)
            else:
                self.cur_gets = self.cur_gets + 1
                if xattrs:
                    cmd = couchbaseConstants.CMD_SUBDOC_MULTIPATH_LOOKUP
                else:
                    cmd = couchbaseConstants.CMD_GET
                key = str(self.cur_gets % self.cur_items)
            self.cur_ops = self.cur_ops + 1

            if json_body:
                value = f'{{"name": "{prefix}{key}", "age": {int(key) % 101}, "index": "{key}", "body":"{self.body}"}}'
            else:
                value = self.body

            if xattrs:
                value = json.dumps({"obj": value, "xattr_f": "field1", "xattr_v": "\"value1\""})

            value_bytes: bytes = value.encode()
            # generate a collection key
            if itr:
                try:
                    cid = int(next(itr), 16)
                except StopIteration:
                    itr = iter(collections)
                    cid = int(next(itr), 16)
                except ValueError as e:
                    return f'Invalid collection id, collection id must be a hexadecimal number: {e}', None


# Path: cb_bin_client.py
# def encode_collection_id(cid: int) -> bytes:
#     output = array.array('B', [0])
#     while cid > 0:
#         byte = cid & 0xFF
#         cid >>= 7
#         # CID has more bits
#         if cid > 0:
#             # Set the 'continue' bit of this byte
#             byte |= 0x80
#             output[-1] = byte
#             output.append(0)
#         else:
#             output[-1] = byte
#     return output.tobytes()


# Path: pump_gen.py
import json
import random
import string
import struct
import couchbaseConstants
import pump
from typing import Any, Dict, Optional, Tuple
from cb_bin_client import encode_collection_id

                else:
                    key = str(self.cur_sets % self.cur_items)
            else:
                self.cur_gets = self.cur_gets + 1
                if xattrs:
                    cmd = couchbaseConstants.CMD_SUBDOC_MULTIPATH_LOOKUP
                else:
                    cmd = couchbaseConstants.CMD_GET
                key = str(self.cur_gets % self.cur_items)
            self.cur_ops = self.cur_ops + 1

            if json_body:
                value = f'{{"name": "{prefix}{key}", "age": {int(key) % 101}, "index": "{key}", "body":"{self.body}"}}'
            else:
                value = self.body

            if xattrs:
                value = json.dumps({"obj": value, "xattr_f": "field1", "xattr_v": "\"value1\""})

            value_bytes: bytes = value.encode()
            # generate a collection key
            if itr:
                try:
                    cid = int(next(itr), 16)
                except StopIteration:
                    itr = iter(collections)
                    cid = int(next(itr), 16)
                except ValueError as e:
                    return f'Invalid collection id, collection id must be a hexadecimal number: {e}', None


                encoded_cid = encode_collection_id(cid)