def serialize_proto(proto):
    """Serialize the protocol buffer object."""
    if proto is None:
        return b''
    elif isinstance(proto, bytes):
        return proto
    elif (hasattr(proto, 'SerializeToString') and
          callable(proto.SerializeToString)):
        result = proto.SerializeToString()
        return result
    else:
        raise ValueError(
            'No <SerializeToString> method. Type is {}'
            .format(type(proto)))