steeve / libtorrent-go

SWIG Go bindings for libtorrent-rasterbar
BSD 3-Clause "New" or "Revised" License
103 stars 56 forks source link

Cast to a specific alert type in Golang #4

Closed colthreepv closed 9 years ago

colthreepv commented 9 years ago

I am trying to cast a specific alert to its C++ subclass, to access its methods. I also opened a stackoverflow question since my desperation got to very high levels :scream:

I have read the source code of torrent2http, and has been a real source of informations, but you never cast an Alert there, I was wondering if you know how to do an alert_cast or something similar in Golang.

Thanks for your time

steeve commented 9 years ago

Pretty simple (well, sort of), for instance:

            switch alert.Xtype() {
            case libtorrent.Metadata_received_alertAlert_type:
                metadataAlert := libtorrent.SwigcptrMetadata_received_alert(alert.Swigcptr())
colthreepv commented 9 years ago

Oh wow, yes!
Reading your example I traced it back to SWIG documentation. Too bad it wasn't so clear before you pointed it out, thanks a ton.

steeve commented 9 years ago

Remember SWIG lets you interact with interfaces, that's why you need the actual SWIG type (Swigcptr prefixed) to properly convert the pointer.