encode_binary

Function encode_binary 

Source
pub fn encode_binary(
    precision: u8,
    points: impl IntoIterator<Item = (f64, f64)>,
) -> Vec<u8> 
Expand description

Encodes a sequence of points into a space-efficient binary format.

This binary format stores 7 bits per byte instead of the 5 bits used by the standard polyline format, resulting in approximately 20-30% smaller size. The format is not URL-safe and is intended for binary storage contexts like databases, protobuf, or file formats.

§Performance

Uses bit interleaving to optimize for small coordinate changes, which are common in geographic paths. This technique saves an additional 10-15% space compared to naive binary encoding.

§Examples

// Encode points in binary format
let points = [(55.58513, 12.99958), (55.61461, 13.04627)];
let binary_data = polyline_iter::encode_binary(5, points);

// Binary format is more compact than text
let text_polyline = polyline_iter::encode(5, points);
assert!(binary_data.len() < text_polyline.len());

// Round-trip encoding/decoding
let decoded_points: Vec<_> = polyline_iter::decode_binary(5, &binary_data).collect();
assert_eq!(decoded_points, points);

// Convert existing polyline to binary format
let polyline = "angrIk~inAgwDybH_|D_{K";
let binary = polyline_iter::encode_binary(5, polyline_iter::decode(5, polyline));