from typing import Optional
import pickle


def DumpsPickle(obj, protocol:Optional[int]=None):
    """Save an object as pickle bytearray.

    Args:
        obj: The object to be saved.
        protocol (int/None): The `protocol` argument for `pickle.dump`.
    Returns:
        bytearray: The pickle bytearray.
    """
    return pickle.dumps(obj) if protocol is None else pickle.dumps(obj, protocol=protocol)