File tree 5 files changed +77
-4
lines changed
5 files changed +77
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,23 @@ Rust Generated Code Guide
4
4
Usage
5
5
-----
6
6
7
- Example invocation:
7
+ The crate `pdl_derive ` lets developers embed their grammar in a source module
8
+ using the `pdl ` proc_macro attribute. Example usage:
9
+
10
+ .. sourcecode :: rust
11
+
12
+ use pdl_derive::pdl
13
+
14
+ #[pdl("my-protocol.pdl")]
15
+ mod my_protocol {
16
+ }
17
+
18
+ The `pdl ` proc_macro attribute must be attached to a module declaration.
19
+ `pdl ` preserves the original name, attributes, and items of the associated
20
+ module.
21
+
22
+ The backend can also be pre-generated from the `pdlc ` tool,
23
+ and compiled as source. Example invocation:
8
24
9
25
.. sourcecode :: bash
10
26
Original file line number Diff line number Diff line change @@ -61,13 +61,13 @@ enum MarkerType : 8 {
61
61
62
62
struct Marker {
63
63
_fixed_ = 0xff : 8,
64
- type: MarkerType,
64
+ type : MarkerType,
65
65
_payload_,
66
66
}
67
67
68
68
struct Segment: Marker {
69
- _size_(_payload_): 16,
70
- _payload_ [+2],
69
+ _size_(_payload_) : 16,
70
+ _payload_ : [+2],
71
71
}
72
72
73
73
struct StartOfImage : Marker(type = SOI) {}
File renamed without changes.
Original file line number Diff line number Diff line change @@ -26,3 +26,7 @@ proc-macro2 = "1.0.66"
26
26
quote = " 1.0.33"
27
27
syn = {version = " 2.0.29" , features = [" full" ]}
28
28
termcolor = " 1.2.0"
29
+
30
+ [dev-dependencies ]
31
+ bytes = " 1.4.0"
32
+ thiserror = " 1.0.47"
Original file line number Diff line number Diff line change
1
+ // Copyright 2023 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ //! PDL tests.
16
+
17
+ use pdl_derive:: pdl;
18
+
19
+ #[ test]
20
+ fn test_pcap ( ) {
21
+ #[ pdl( "../examples/pcap.pdl" ) ]
22
+ mod pcap { }
23
+
24
+ use pcap:: * ;
25
+ let pcap_file = PcapFileBuilder {
26
+ header : PcapHeader {
27
+ version_major : 1 ,
28
+ version_minor : 0 ,
29
+ thiszone : 0 ,
30
+ sigfigs : 0 ,
31
+ snaplen : 512 ,
32
+ network : 42 ,
33
+ } ,
34
+ records : vec ! [ PcapRecord {
35
+ ts_sec: 0xdead ,
36
+ ts_usec: 0xbeef ,
37
+ orig_len: 1024 ,
38
+ payload: vec![ 1 , 2 , 3 ] ,
39
+ } ] ,
40
+ }
41
+ . build ( ) ;
42
+
43
+ assert ! ( PcapFile :: parse( & pcap_file. to_vec( ) ) . is_ok( ) ) ;
44
+ }
45
+
46
+ #[ test]
47
+ #[ cfg( disabled) ]
48
+ fn test_jpeg ( ) {
49
+ // The JPEG syntax depends on struct inheritance which is currently
50
+ // not supported. https://github.com/google/pdl/issues/62
51
+ #[ pdl( "../examples/jpeg.pdl" ) ]
52
+ mod jpeg { }
53
+ }
You can’t perform that action at this time.
0 commit comments