diff options
Diffstat (limited to 'rns510.pyx')
-rw-r--r-- | rns510.pyx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/rns510.pyx b/rns510.pyx new file mode 100644 index 0000000..ca0f0ff --- /dev/null +++ b/rns510.pyx @@ -0,0 +1,47 @@ +import cython + +from libc.stdlib cimport malloc +from libc.stdlib cimport free + +cdef extern from "librns510.h": + void librns510_encode(const char *lat, const char *lon, char *code) +cdef extern from "librns510.h": + char *librns510_decode(const char *code, char *lat, char *lon) + +def encode(char *lat, char *lon): + assert lat is not NULL + assert lon is not NULL + cdef bytes py_string + cdef char *out + + out=<char *> malloc(128) + librns510_encode(lat,lon,out) + try: + py_string=out + finally: + free(out) + + return py_string + +def decode(char *code): + assert code is not NULL + cdef bytes py_lat + cdef bytes py_lon + cdef char *lat + cdef char *lon + + lat=<char *> malloc(128) + lon=<char *> malloc(128) + librns510_decode(code,lat,lon) + try: + py_lat=lat + finally: + free(lat) + + try: + py_lon=lon + finally: + free(lon) + + return py_lat,py_lon + |