DCCL v5
Loading...
Searching...
No Matches
test4.proto
1syntax = "proto2";
2
3import "dccl/option_extensions.proto";
4
5package dccl.test;
6
7message TestMsg
8{
9 option(dccl.msg) = { id : 2, max_bytes : 512, codec_version : 4 };
10
11 enum State
12 {
13 STATE_1 = 1; STATE_2 = 2; STATE_3 = 3;
14 }
15
16 required State state = 1;
17
18 optional int32 a = 2 [(dccl.field) = {
19 min : 0 max : 200 dynamic_conditions{
20 // can use "return"
21 required_if : "return this.state == 'STATE_1'"
22 omit_if : "return this.state ~= 'STATE_1'"
23 }
24 }];
25
26 optional int32 b = 3 [(dccl.field) = {
27 min : 0 max : 300 dynamic_conditions{
28 // if no return in script, assume it is implicit - DCCL will prefix
29 // with "return "
30 required_if : "this.state == 'STATE_2'" omit_if : "this.state ~= 'STATE_2'"
31 }
32 }];
33
34 optional int32 c_center = 4 [default = 199, (dccl.field) = {
35 min : 0 max : 300 dynamic_conditions{
36 // same as required_if: "this.state == 'STATE_3'" and omit_if ~=
37 // 'STATE_3'"
38 only_if : "this.state == 'STATE_1'"
39 }
40 }
41
42 ];
43
44 optional int32 c = 6 [(dccl.field) = {
45 min : 0 max : 400 dynamic_conditions{
46 only_if : "this.state == 'STATE_1'" min : "this.c_center-100" max : "this.c_center+100"
47 }
48 }];
49
50 repeated int32 d = 7 [(dccl.field) = {
51 min : 0 max : 300 max_repeat : 6 dynamic_conditions{
52 // LUA indexes from 1
53 only_if : "this_index ~= 4" min : "this_index*50" max : "this_index*50+100"
54 }
55 }];
56
57 repeated Child child = 10 [(dccl.field) = {max_repeat : 10}];
58
59 message Child
60 {
61 enum IncludeI
62 {
63 UNUSED = 0; YES = 1; NO = 2;
64 }
65
66 required IncludeI include_i = 1;
67 optional int32 i = 2 [(dccl.field) = {
68 min : 0 max : 255
69 // within the embedded message, 'this' refers to the embedded
70 // message (innermost scope) ...
71 dynamic_conditions{only_if : "this.include_i == 'YES'"}
72 }];
73
74 optional int32 i2 = 3 [(dccl.field) = {
75 min : 0 max : 255
76 // ... but the entire message is still accessible with 'root', and
77 // 'this_index' refers to the current repeated message index
78 dynamic_conditions{
79 only_if : "print(this_index); return root.child[this_index].include_i == 'YES'"
80 }
81 }];
82 }
83
84 message Child2
85 {
86 enum IncludeI
87 {
88 UNUSED = 0; YES = 1; NO = 2;
89 }
90
91 required IncludeI include_i = 1;
92 optional int32 i = 2 [(dccl.field) = {
93 min : 0 max : 255 dynamic_conditions{only_if : "this.include_i == 'YES'"}
94
95 }];
96 }
97
98 required Child2 child2 = 11;
99
100 message Child3
101 {
102 enum IncludeI
103 {
104 UNUSED = 0; YES = 1; NO = 2;
105 }
106
107 required IncludeI include_i = 1;
108 optional int32 i = 2 [(dccl.field) = {
109 min : 0 max : 255
110 // check that root works correctly here
111 dynamic_conditions{only_if : "root.child3.include_i == 'YES'"}
112
113 }];
114
115 // since this message uses local scoping only, we can include it again
116 optional Child2 subchild = 3;
117 }
118 optional Child3 child3 = 12;
119
120 oneof example_oneof
121 {
122 int32 x =
123 20 [(dccl.field) =
124 {min : 0 max : 255 dynamic_conditions{only_if : "this.state == 'STATE_1'"}}];
125 int32 y =
126 21 [(dccl.field) =
127 {min : 0 max : 255 dynamic_conditions{only_if : "this.state == 'STATE_2'"}}];
128 }
129}