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