5 releases

0.1.4 Jul 21, 2022
0.1.3 May 22, 2022
0.1.2 Jun 10, 2020
0.1.1 Jun 10, 2020
0.1.0 Jun 10, 2020

#478 in WebAssembly

Download history 5/week @ 2023-12-18 15/week @ 2024-02-19 33/week @ 2024-02-26 64/week @ 2024-03-11 45/week @ 2024-03-18 97/week @ 2024-04-01

206 downloads per month

ISC license

87KB
2K SLoC

rust-geobuf

Crates.io Build Status Coverage Status

Tested with rust 1.60

A port of geobuf encoder and decoder into Rust and WebAssembly

Usage

This crate provides a command line binary, a rust library, and a WebAssembly package. The binary and library are in geobuf and the Rust/WebAssembly code is in geobuf-wasm.

Binary:

geobuf [encode|decode] -i <path-to-input-file> -o <path-to-output-file>

Use geobuf [encode|decode] --help for more info.

Library

use geobuf::{decode, encode};
use serde_json;

fn main() {
    let original_geojson = serde_json::from_str(r#"{"type": "Point", "coordinates": [100.0, 0.0]}"#).unwrap();
    let geobuf = encode::Encoder::encode(&original_geojson, 6, 2).unwrap();
    let geojson = decode::Decoder::decode(&geobuf).unwrap();
    assert_eq!(original_geojson, geojson);
}

WebAssembly

The www folder contains a sample project showing how the wasm code can be used.

To run the example locally, clone the repo and run the following:

  • wasm-pack build -- --no-default-features --features wasm
  • cd www && npm i && npm start

Note: The wasm code is currently slower that the node version and requires some refactoring to improve how data is being passed between the JS and Rust code.

Dependencies

~8–22MB
~307K SLoC