def serialize_protobuf(pb):
    """
    Serialize a protobuf object into a bytestring

    Arguments:
        pb (Protobuf, bytes): Protobuf object to serialize or bytestring to pass through
    """
    if not isinstance(pb, bytes):
        if not hasattr(pb, "SerializeToString"):
            raise TypeError("pb must be a bytestring or a protobuf object, "
                            "not {}".format(type(pb)))
        pb = pb.SerializeToString()

    return pb