Skip to content

Commit caeba4d

Browse files
committed
readme: add information about when generated messages are prepended with x or X
1 parent 0bc5dab commit caeba4d

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,48 @@ Generates Rust messages from a `dbc` file.
44

55
⚠️ This is experimental - use with caution. Breaking changes will happen when you least expect it. ⚠️
66

7-
# Usage
7+
## Usage
88

99
Generate `messages.rs` from `example.dbc`.
1010
```bash
1111
cargo run -- testing/dbc-examples/example.dbc dir/where/messages_rs/file/is/written
1212
```
1313

14-
# Development
14+
If some field name starts with a non-alphabetic character or is a Rust keyword then it is prepended with `x`.
15+
16+
For example:
17+
```
18+
VAL_ 512 Five 0 "0Off" 1 "1On" 2 "2Oner" 3 "3Onest";
19+
```
20+
..is generated to:
21+
```rust
22+
pub enum BarFive {
23+
X0off,
24+
X1on,
25+
X2oner,
26+
X3onest,
27+
Other(bool),
28+
}
29+
```
30+
31+
`Type` here:
32+
```
33+
SG_ Type : 30|1@0+ (1,0) [0|1] "boolean" Dolor
34+
```
35+
..would become Rust keyword `type` therefore it is prepended with `x`:
36+
```rust
37+
pub fn xtype(&self) -> BarType {
38+
match self.xtype_raw() {
39+
false => BarType::X0off,
40+
true => BarType::X1on,
41+
false => BarType::X2oner,
42+
false => BarType::Type,
43+
x => BarType::Other(x),
44+
}
45+
}
46+
```
47+
48+
## Development
1549

1650
```bash
1751
# generate messages.rs
@@ -27,7 +61,7 @@ cargo test --all
2761
cargo fmt --all
2862
```
2963

30-
## Generate .kdc from .dbc
64+
### Generate .kdc from .dbc
3165

3266
Use [canmatrix](https://github.com/ebroecker/canmatrix) if you need to generate a new `.kcd` file from a `.dbc`.
3367

0 commit comments

Comments
 (0)