Skip to main content

Crate srcmap_codec

Crate srcmap_codec 

Source
Expand description

High-performance VLQ source map codec.

Encodes and decodes source map mappings using the Base64 VLQ format as specified in the Source Map v3 specification (ECMA-426).

§Features

  • parallel — enables [encode_parallel] for multi-threaded encoding via rayon. ~1.5x faster for large maps (5K+ lines).

§Examples

Decode and re-encode a mappings string:

use srcmap_codec::{decode, encode};

let mappings = decode("AAAA;AACA,EAAE").unwrap();
assert_eq!(mappings.len(), 2); // 2 lines
assert_eq!(mappings[0][0], vec![0, 0, 0, 0]); // first segment

let encoded = encode(&mappings);
assert_eq!(encoded, "AAAA;AACA,EAAE");

Low-level VLQ primitives:

use srcmap_codec::{vlq_decode, vlq_encode};

let mut buf = Vec::new();
vlq_encode(&mut buf, 42);

let (value, bytes_read) = vlq_decode(&buf, 0).unwrap();
assert_eq!(value, 42);

Enums§

DecodeError
Errors that can occur when decoding a VLQ-encoded mappings string.

Functions§

decode
Decode a VLQ-encoded source map mappings string into structured data.
encode
Encode decoded source map mappings back into a VLQ-encoded string.
vlq_decode
Decode a single VLQ value from the input bytes starting at the given position.
vlq_decode_unsigned
Decode a single unsigned VLQ value from the input bytes starting at the given position.
vlq_encode
Encode a single VLQ value, appending base64 chars to the output buffer.
vlq_encode_unsigned
Encode a single unsigned VLQ value, appending base64 chars to the output buffer.

Type Aliases§

Line
A source map line is a list of segments.
Segment
A single source map segment.
SourceMapMappings
Decoded source map mappings: a list of lines, each containing segments.