def METHOD_NAME(self, value, dialect):
    if isinstance(value, bytes):
        if len(value) != 8:
            raise ValueError("Invalid grid length: %r" % value)
        return value
    lat, lon = value
    return encode_datamap_grid(lat, lon)