Comments (6)
Sounds like a bug in my code to me. Let me check please.
from nfc.
unsafe_p := (unsafe.Pointer(targets[0].Marshall()))
defer C.free(unsafe_p)
mtarget := (*nfc.ISO14443aTarget)(unsafe_p)
Casting an unsafe.Pointer
you get from Marshall()
to one of the target types can't work. The pointer you get from Marshall()
points to a C type, whereas the target types are entirely different types. As per documentation for Target.Marshall()
:
Marshall() returns a pointer to an nfc_target allocated with C.malloc() that contains the same data as the Target. Don't forget to C.free() the result of Marshall() afterwards. A runtime panic may occur if any slice referenced by a Target has been made larger than the maximum length mentioned in the respective comments.
Where nfc_target
refers to the C type nfc_target
, not the Go type. If you want to convert a Target
into an object of concrete type, use a type assertion like this (replacing the code above):
mtarget, ok := targets[0].(nfc.ISO14443aTarget)
if !ok {
// targets[0] is apparently not an ISO 14443a target. Do something here...
}
Please tell me if this solved your problem and then close the issue.
from nfc.
Thanks for the quick response.
I tried your suggestion, but it won't compile. See snippet and error message below. Seems that nfc.ISO14443aTarget should implement nfc.Target, but doesn't.
//unsafe_p := (unsafe.Pointer(targets[0].Marshall()))
//defer C.free(unsafe_p)
//mtarget := (*nfc.ISO14443aTarget)(unsafe_p)
mtarget, ok := targets[0].(nfc.ISO14443aTarget)
if !ok {
fmt.Printf("Not ISO14443aTarget!")
} else {
fmt.Printf("Atqa =%v\n",mtarget.Atqa)
fmt.Printf("Sak =%v\n",mtarget.Sak)
fmt.Printf("UIDLen =%v\n",mtarget.UIDLen)
fmt.Printf("UID =%v\n",mtarget.UID)
}
//does not compile:
//../src/messinm2/testnfc/testnfc.go:81: impossible type assertion:
// nfc.ISO14443aTarget does not implement nfc.Target (Marshall method has pointer receiver)
from nfc.
Sorry. Cast to *nfc.ISO14443aTarget
, not nfc.ISO14443aTarget
. I don't know why I forgot that star.
from nfc.
That works! Thanks, and thanks very much for the lib.
from nfc.
It was a pleasure to me.
from nfc.
Related Issues (11)
- Explicitly check ranges in Target.Marshall() implementations HOT 1
- Help with cross compiling for Raspberry Pi HOT 1
- undefined: context HOT 7
- thread safety? HOT 4
- github.com\clausecker\nfc\[email protected]\nfc.go:208:17: undefined: context HOT 6
- nfc_initiator_deselect_target() is not wrapped
- Does not compile with go 1.3 (so you said) HOT 7
- Initiator Target Selection? HOT 3
- Device.InitiatorSelectPassiveTarget does not work HOT 4
- Device.InitiatorSelectPassiveTarget panic when InfiniteSelect == false and no tag was found HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nfc.