Function polyline_ffi::encode_coordinates_ffi
[−]
[src]
pub extern fn encode_coordinates_ffi(coords: Array, precision: uint32_t) -> *mut c_char
Convert an array of coordinates into a Polyline
Callers must pass two arguments:
- a Struct with two fields:
data, a void pointer to an array of floating-point lat, lon coordinates:[[1.0, 2.0]]len, the length of the array being passed. Its type must besize_t:1
- an unsigned 32-bit
intfor precision (5 for Google Polylines, 6 for OSRM and Valhalla Polylines)
Examples
extern crate libc; use libc::{c_void, size_t}; use std::ffi::CStr; use std::slice; let input = vec![[1.0, 2.0], [3.0, 4.0]].as_slice(); let array = Array { data: input.as_ptr() as *const c_void, len: input.len() as size_t }; let output = "_ibE_seK_seK_seK".to_string(); let pl = encode_coordinates_ffi(array, 5); let result = unsafe { CStr::from_ptr(pl).to_str().unwrap() }; assert_eq!(result, output); drop_cstring(pl);
A decoding failure will always return a string: "Couldn't decode Polyline"
Implementations calling this function must call drop_cstring
with the returned c_char pointer, in order to free the memory it allocates.
Safety
This function is unsafe because it accesses a raw pointer which could contain arbitrary data