Skip to content

Commit

Permalink
README: document how to implement a custom format
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Mar 5, 2023
1 parent 3392177 commit 64d9a53
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ Pantrace converts between traceroute formats, in the same way as [Pandoc](https:

Each format needs to implement only two conversions: to and from the internal format.

## Formats

- `atlas`: RIPE Atlas JSONL (read/write)
- `flat`: JSONL with one document per reply (write-only)
- `internal`: Pantrace internal format (read/write)
- `iris`: Iris JSONL format (read/write)
- `scamper-trace-warts`: Scamper traceroute in warts format (read/write)

## Quickstart

### Cargo
Expand Down Expand Up @@ -50,3 +42,28 @@ cat example.ndjson | pantrace --standalone --from atlas --to scamper-trace-warts
# Convert from a file to a file
pantrace --standalone --from atlas --to scamper-trace-warts --input example.ndjson --output example.warts
```


## Formats

- `atlas`: RIPE Atlas JSONL (read/write)
- `flat`: JSONL with one document per reply (write-only)
- `internal`: Pantrace internal format (read/write)
- `iris`: Iris JSONL format (read/write)
- `scamper-trace-warts`: Scamper traceroute in warts format (read/write)

### Implementing a new format

To add a new `CustomFormat` to the pantrace CLI ([`main.rs`](src/main.rs)), two structures must be implemented:
- `CustomTracerouteReader` which implements the `Iterator<Item = Result<Traceroute>>` trait.
- `CustomTracerouteWriter` which implements the [`TracerouteWriter`](src/traits.rs) trait, and in particular the
`fn write_traceroute(&mut self, traceroute: &Traceroute) -> Result<()>` function
where [`Traceroute`](src/formats/internal/models.rs) is pantrace's internal traceroute format.

The conversion between `CustomFormat` and `Traceroute` can be implemented in any way, but the current formats are
implemented as follows:
- `CustomFormat` to `Traceroute` conversion in a `to_internal` module:
- `impl From<CustomFormat> for Traceroute { ... }`
- `CustomFormat` from `Traceroute` conversion in a `from_internal` module
- `impl From<Traceroute> for CustomFormat { ... }`
- or `impl From<Traceroute> for Vec<CustomFormat> { ... }` if `CustomFormat` is a single path traceroute format

0 comments on commit 64d9a53

Please sign in to comment.