cauterize 0.0.1.pre13 → 0.0.1.pre14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +33 -33
  3. data/.rspec +1 -1
  4. data/.travisci.yml +4 -4
  5. data/Gemfile +4 -4
  6. data/LICENSE.txt +21 -21
  7. data/README.md +177 -177
  8. data/Rakefile +54 -54
  9. data/bin/cauterize +61 -61
  10. data/cauterize.gemspec +27 -27
  11. data/example/Cauterize +68 -68
  12. data/example/build.sh +25 -25
  13. data/example/c_example_support/empty_main.c +1 -1
  14. data/example/c_example_support/example_project_config.c +11 -11
  15. data/example/c_example_support/example_project_config.h +15 -15
  16. data/example/ruby_ex.rb +14 -14
  17. data/lib/cauterize.rb +117 -117
  18. data/lib/cauterize/base_type.rb +78 -78
  19. data/lib/cauterize/builders.rb +41 -41
  20. data/lib/cauterize/builders/c/buildable.rb +91 -91
  21. data/lib/cauterize/builders/c/builtin.rb +43 -43
  22. data/lib/cauterize/builders/c/composite.rb +57 -57
  23. data/lib/cauterize/builders/c/enumeration.rb +60 -60
  24. data/lib/cauterize/builders/c/fixed_array.rb +74 -74
  25. data/lib/cauterize/builders/c/group.rb +143 -143
  26. data/lib/cauterize/builders/c/scalar.rb +34 -34
  27. data/lib/cauterize/builders/c/variable_array.rb +98 -98
  28. data/lib/cauterize/builders/cs/buildable.rb +59 -59
  29. data/lib/cauterize/builders/cs/builtin.rb +22 -22
  30. data/lib/cauterize/builders/cs/composite.rb +21 -21
  31. data/lib/cauterize/builders/cs/csarray.rb +32 -32
  32. data/lib/cauterize/builders/cs/enumeration.rb +21 -21
  33. data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
  34. data/lib/cauterize/builders/cs/group.rb +32 -32
  35. data/lib/cauterize/builders/cs/scalar.rb +10 -10
  36. data/lib/cauterize/builders/cs/variable_array.rb +40 -34
  37. data/lib/cauterize/builders/doc/buildable.rb +30 -30
  38. data/lib/cauterize/builders/doc/builtin.rb +21 -21
  39. data/lib/cauterize/builders/doc/composite.rb +23 -23
  40. data/lib/cauterize/builders/doc/enumeration.rb +24 -24
  41. data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
  42. data/lib/cauterize/builders/doc/group.rb +29 -29
  43. data/lib/cauterize/builders/doc/scalar.rb +21 -21
  44. data/lib/cauterize/builders/doc/variable_array.rb +26 -26
  45. data/lib/cauterize/builders/ruby/buildable.rb +11 -11
  46. data/lib/cauterize/builders/ruby/builtin.rb +25 -25
  47. data/lib/cauterize/builders/ruby/composite.rb +26 -26
  48. data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
  49. data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
  50. data/lib/cauterize/builders/ruby/group.rb +35 -35
  51. data/lib/cauterize/builders/ruby/scalar.rb +19 -19
  52. data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
  53. data/lib/cauterize/builtin.rb +62 -62
  54. data/lib/cauterize/c_builder.rb +103 -103
  55. data/lib/cauterize/cauterize.rb +76 -76
  56. data/lib/cauterize/composite.rb +64 -64
  57. data/lib/cauterize/cs_builder.rb +58 -58
  58. data/lib/cauterize/doc_builder.rb +34 -34
  59. data/lib/cauterize/enumeration.rb +98 -98
  60. data/lib/cauterize/fixed_array.rb +50 -50
  61. data/lib/cauterize/formatter.rb +67 -67
  62. data/lib/cauterize/group.rb +81 -81
  63. data/lib/cauterize/representation.rb +32 -32
  64. data/lib/cauterize/ruby_builder.rb +44 -44
  65. data/lib/cauterize/scalar.rb +53 -53
  66. data/lib/cauterize/snake_case.rb +21 -21
  67. data/lib/cauterize/variable_array.rb +55 -55
  68. data/lib/cauterize/version.rb +3 -3
  69. data/spec/base_type_spec.rb +251 -251
  70. data/spec/builders/c/buildable_spec.rb +25 -25
  71. data/spec/builders/c/builtin_spec.rb +22 -22
  72. data/spec/builders/c/composite_spec.rb +50 -50
  73. data/spec/builders/c/enumeration_spec.rb +95 -95
  74. data/spec/builders/c/fixed_array_spec.rb +36 -36
  75. data/spec/builders/c/group_spec.rb +140 -140
  76. data/spec/builders/c/scalar_spec.rb +26 -26
  77. data/spec/builders/c/variable_array_spec.rb +48 -48
  78. data/spec/builders/cs/buildable_spec.rb +8 -8
  79. data/spec/builders/cs/composite_spec.rb +32 -32
  80. data/spec/builders/cs/enumeration_spec.rb +33 -33
  81. data/spec/builders/cs/fixed_array_spec.rb +41 -41
  82. data/spec/builders/cs/group_spec.rb +56 -56
  83. data/spec/builders/cs/scalar_spec.rb +7 -7
  84. data/spec/builders/cs/variable_array_spec.rb +49 -45
  85. data/spec/builders/doc/buildable_spec.rb +25 -25
  86. data/spec/builders_spec.rb +57 -57
  87. data/spec/builtin_spec.rb +43 -43
  88. data/spec/c_builder_spec.rb +176 -176
  89. data/spec/cauterize_spec.rb +15 -15
  90. data/spec/composite_spec.rb +77 -77
  91. data/spec/cs_builder_spec.rb +115 -115
  92. data/spec/doc_builder_spec.rb +260 -260
  93. data/spec/enumeration_spec.rb +145 -145
  94. data/spec/fixed_array_spec.rb +61 -61
  95. data/spec/group_spec.rb +111 -111
  96. data/spec/ruby_builder_spec.rb +83 -83
  97. data/spec/ruby_generated_spec.rb +735 -735
  98. data/spec/scalar_spec.rb +44 -44
  99. data/spec/spec_helper.rb +122 -122
  100. data/spec/support/shared_examples_for_array_buildables.rb +22 -22
  101. data/spec/support/shared_examples_for_c_buildables.rb +103 -103
  102. data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
  103. data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
  104. data/spec/support/spec_sample_model.rb +74 -74
  105. data/spec/test_main.c +13 -13
  106. data/spec/variable_array_spec.rb +73 -73
  107. data/support/c/src/cauterize.c +75 -75
  108. data/support/c/src/cauterize.h +60 -60
  109. data/support/c/src/cauterize_debug.h +29 -29
  110. data/support/c/src/cauterize_util.h +8 -8
  111. data/support/c/test/greatest.h +536 -536
  112. data/support/c/test/test.c +166 -166
  113. data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
  114. data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
  115. data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
  116. data/support/cs/src/CauterizeException.cs +15 -15
  117. data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
  118. data/support/cs/src/CauterizeFormatter.cs +0 -0
  119. data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
  120. data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
  121. data/support/cs/src/CauterizeTypes.cs +46 -12
  122. data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
  123. data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
  124. data/support/cs/src/OrderAttribute.cs +0 -0
  125. data/support/cs/src/PrimitiveSupport.cs +12 -0
  126. data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
  127. data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
  128. data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
  129. data/support/cs/test/CauterizeFormatterTest.cs +0 -0
  130. data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
  131. data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
  132. data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
  133. data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
  134. data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
  135. data/support/cs/test/OrderAttributeTest.cs +0 -0
  136. data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
  137. data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
  138. metadata +20 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dc3160a85139642df941d4afd5e3e7bbac2b32b
4
- data.tar.gz: 827cf33e36a85a7acf94e0c92418e4a5ece5b419
3
+ metadata.gz: d11716e541353c226d505c7a4722a81e682d9e2a
4
+ data.tar.gz: ac8804479d6ebc0ed4ab1b606a480f74ac3ba101
5
5
  SHA512:
6
- metadata.gz: 6f4311c1ca2b228a9cad06b595756f57e40327fdba18664b8419770c91e7f2b1fd95aa1cb0a7b94e66b7f8007d1cbd2aeea19a41209197ece8bf7da8c082b9dd
7
- data.tar.gz: c32033d4dfd4575cc11ff4dda714211df2cbf46b552903a69659278b90f8ee049bf3f2ef4191da363f4664f2e115a8aa4dd143a401c2017b34233c19cd8edfd7
6
+ metadata.gz: eb52dda5e785d62fa1aea8410f1bd9c0005e2118d2645f5b056900de8818cbee5b931d323cc277ce099c3cf7b8862bde849d18d6e9af0766b87a143eda664cf9
7
+ data.tar.gz: e9d6fde04f9f564f1fe0dee795f1d1866388d2efa9c7922a0f1944189547e201f94f648f55c492c120d617c23e3f20d0130184966410184840e5fbe91e1e4a16
data/.gitignore CHANGED
@@ -1,33 +1,33 @@
1
- # Object files
2
- *.o
3
-
4
- # Libraries
5
- *.lib
6
- *.a
7
-
8
- # Shared objects (inc. Windows DLLs)
9
- *.dll
10
- *.so
11
- *.so.*
12
- *.dylib
13
-
14
- # Executables
15
- *.exe
16
- *.out
17
- *.app
18
-
19
- # Bundler
20
- Gemfile.lock
21
- pkg
22
-
23
- # Examples
24
- example/*_cauterize_output
25
-
26
- # Nunit test results
27
- TestResult.xml
28
-
29
- # rbenv
30
- .ruby-version
31
-
32
- # Tags
33
- tags
1
+ # Object files
2
+ *.o
3
+
4
+ # Libraries
5
+ *.lib
6
+ *.a
7
+
8
+ # Shared objects (inc. Windows DLLs)
9
+ *.dll
10
+ *.so
11
+ *.so.*
12
+ *.dylib
13
+
14
+ # Executables
15
+ *.exe
16
+ *.out
17
+ *.app
18
+
19
+ # Bundler
20
+ Gemfile.lock
21
+ pkg
22
+
23
+ # Examples
24
+ example/*_cauterize_output
25
+
26
+ # Nunit test results
27
+ TestResult.xml
28
+
29
+ # rbenv
30
+ .ruby-version
31
+
32
+ # Tags
33
+ tags
data/.rspec CHANGED
@@ -1 +1 @@
1
- -r spec_helper
1
+ -r spec_helper
@@ -1,4 +1,4 @@
1
- language: ruby
2
- rvm:
3
- - "1.9.3"
4
- script: bundle exec rake
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ script: bundle exec rake
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
2
-
3
- # Specify your gem's dependencies in cauterize.gemspec
4
- gemspec
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cauterize.gemspec
4
+ gemspec
@@ -1,22 +1,22 @@
1
- Copyright (c) 2012 John Van Enk
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ Copyright (c) 2012 John Van Enk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,177 +1,177 @@
1
- # cauterize
2
-
3
- A Ruby DSL for generating marshalable structured data easily compatable with
4
- statically allocated C systems. Currently, it prefers simplicity and
5
- predictability over speed.
6
-
7
- # Why?
8
-
9
- Basically, `malloc` is a huge pain when you only have 16K of RAM.
10
-
11
- # Examples
12
-
13
- There's currently a (single) example in this project. To run it, do this:
14
-
15
- ```
16
- git clone git://github.com/sw17ch/cauterize.git
17
- cd cauterize
18
- bundle install
19
- cd example
20
- sh build.sh
21
- ```
22
-
23
- If this completes without error, then you should find a bunch of generated code
24
- in cauterize_output. Look at the structures and enumerations defined in the
25
- `example_project.h` file. Also look at how the `Pack_*` and `Unpack_*`
26
- functions are organized and named.
27
-
28
- Once you've looked at this, take a look at `example_project.c`. This will show
29
- you the exact mechanism used to package and unpackage different structures.
30
-
31
- `cauterize.h` and `cauterize.c` are used as iterators over C buffers. They are
32
- used to abstract the process of packaging and unpackaging different elements.
33
-
34
- # Different Types
35
-
36
- There are 7 fundamental classes of types in Cauterize. These types have several characteristics:
37
-
38
- * They can be copied with `memcpy`.
39
- * They do not attempt to cover the concept of indirection or pointers.
40
- * They are simple.
41
- * They cannot be defined recursively.
42
-
43
- ## Primitives
44
-
45
- * 1 Byte Primitives
46
- * `:bool` - a boolean value
47
- * `:int8` - a signed, 8 bit value
48
- * `:uint8` - an unsigned, 8 bit value
49
- * 2 Byte Primitives
50
- * `:int16` - a signed, 16 bit value
51
- * `:uint16` - an unsigned, 16 bit value
52
- * 4 Byte Primitives
53
- * `:int32` - a signed, 32 bit value
54
- * `:uint32` - an unsigned, 32 bit value
55
- * `:float32` - a 32 bit floating point value
56
- * 8 Byte Primitives
57
- * `:int64` - a signed, 64 bit value
58
- * `:uint64` - an unsigned, 64 bit value
59
- * `:float64` - a 64 bit floating point value
60
-
61
- ## Scalars
62
-
63
- Scalars are any type that corresponds to a C scalar value. That is, something
64
- that can be defined with the native types (`int`, `long`, `short`, etc). It is
65
- highly recommended that these ONLY ever use values from `stdint.h`. This
66
- ensures that the sizes of these scalars will be consistent across platforms.
67
-
68
- Scalars can be defined simply by giving them a name that corresponds to a type
69
- from `stdint.h`.
70
-
71
- ```ruby
72
- scalar(:uint8_t)
73
- scalar(:uint32_t)
74
- ```
75
-
76
- ## Enumerations
77
-
78
- Enumerations correspond almost exactly to C enumerations. They are a list of
79
- names. When appropriate, a specific scalar value may also be specified. If no
80
- scalar is specified, enumerations will be represented in order from 0.
81
-
82
- ```ruby
83
- enumeration(:color) do |e|
84
- e.value :red
85
- e.value :blue
86
- e.value :green
87
- end
88
-
89
- enumeration(:days_of_week) do |e|
90
- e.value :sunday, 100
91
- e.value :monday, 101
92
- e.value :tuesday, 102
93
- e.value :wednesday, 103
94
- e.value :thursday, 104
95
- e.value :friday, 105
96
- e.value :saturday, 106
97
- end
98
- ```
99
-
100
- ## Fixed Arrays
101
-
102
- Fixed arrays are arrays that only ever make sense when they are full. An
103
- example of an array with this property is a MAC Address. MAC addresses are
104
- always 6 bytes. Never more. Never less.
105
-
106
- ```ruby
107
- fixed_array(:mac_address) do |a|
108
- a.array_type :uint8_t # the type held by the array
109
- a.array_size 6 # the number of elements in the array
110
- end
111
- ```
112
-
113
- ## Variable Arrays
114
-
115
- Variable Arrays are arrays that have a maximum length, but may not be entirely
116
- utilized.
117
-
118
- ```ruby
119
- # a way to represent some number of dates/times as 32-bit values
120
- variable_array(:datetimes) do |a|
121
- a.size_type :uint8_t # WILL BE DEPRECATED
122
- a.array_type :int32_t
123
- a.array_size 128
124
- end
125
-
126
- # a string, represented as `int_8`'s, with a maximum length of 32 bytes
127
- variable_array(:string_32) do |a|
128
- a.size_type :uint8_t # WILL BE DEPRECATED
129
- a.array_type :int8_t
130
- a.array_size 32
131
- end
132
- ```
133
-
134
- ## Composites
135
-
136
- Composites are very similar to C structures. They are collections of other
137
- types. Each field has a name and may correspond to any other defined type.
138
-
139
- ```ruby
140
- composite(:person) do |c|
141
- c.field :name, :string_32
142
- c.field :age, :uint8_t
143
- c.field :date_of_birth, :uint32_t
144
- end
145
- ```
146
-
147
- ## Groups
148
-
149
- Groups are similar to C unions with one major difference. Each group is
150
- comprised of a type tag and a union of the types the union is capable of
151
- representing. This is known as a tagged union.
152
-
153
- The tag is used to inform the user application what type the union is currently
154
- representing. The tag is a special enumeration that is automatically defined.
155
-
156
- ```ruby
157
- group(:requests) do |g|
158
- c.field :add_user, :add_user_request
159
- c.field :get_user, :get_user_request
160
- c.field :delete_user, :delete_user_request
161
- end
162
-
163
- group(:responses) do |g|
164
- c.field :add_user, :add_user_response
165
- c.field :get_user, :get_user_response
166
- c.field :delete_user, :delete_user_response
167
- end
168
- ```
169
-
170
- Groups don't have to specify a data type in all of their fields.
171
-
172
- ```ruby
173
- group(:complex) do |g|
174
- g.field :a_number, :int32
175
- g.dataless :a_state # no associated data with this alternative
176
- end
177
- ```
1
+ # cauterize
2
+
3
+ A Ruby DSL for generating marshalable structured data easily compatable with
4
+ statically allocated C systems. Currently, it prefers simplicity and
5
+ predictability over speed.
6
+
7
+ # Why?
8
+
9
+ Basically, `malloc` is a huge pain when you only have 16K of RAM.
10
+
11
+ # Examples
12
+
13
+ There's currently a (single) example in this project. To run it, do this:
14
+
15
+ ```
16
+ git clone git://github.com/sw17ch/cauterize.git
17
+ cd cauterize
18
+ bundle install
19
+ cd example
20
+ sh build.sh
21
+ ```
22
+
23
+ If this completes without error, then you should find a bunch of generated code
24
+ in cauterize_output. Look at the structures and enumerations defined in the
25
+ `example_project.h` file. Also look at how the `Pack_*` and `Unpack_*`
26
+ functions are organized and named.
27
+
28
+ Once you've looked at this, take a look at `example_project.c`. This will show
29
+ you the exact mechanism used to package and unpackage different structures.
30
+
31
+ `cauterize.h` and `cauterize.c` are used as iterators over C buffers. They are
32
+ used to abstract the process of packaging and unpackaging different elements.
33
+
34
+ # Different Types
35
+
36
+ There are 7 fundamental classes of types in Cauterize. These types have several characteristics:
37
+
38
+ * They can be copied with `memcpy`.
39
+ * They do not attempt to cover the concept of indirection or pointers.
40
+ * They are simple.
41
+ * They cannot be defined recursively.
42
+
43
+ ## Primitives
44
+
45
+ * 1 Byte Primitives
46
+ * `:bool` - a boolean value
47
+ * `:int8` - a signed, 8 bit value
48
+ * `:uint8` - an unsigned, 8 bit value
49
+ * 2 Byte Primitives
50
+ * `:int16` - a signed, 16 bit value
51
+ * `:uint16` - an unsigned, 16 bit value
52
+ * 4 Byte Primitives
53
+ * `:int32` - a signed, 32 bit value
54
+ * `:uint32` - an unsigned, 32 bit value
55
+ * `:float32` - a 32 bit floating point value
56
+ * 8 Byte Primitives
57
+ * `:int64` - a signed, 64 bit value
58
+ * `:uint64` - an unsigned, 64 bit value
59
+ * `:float64` - a 64 bit floating point value
60
+
61
+ ## Scalars
62
+
63
+ Scalars are any type that corresponds to a C scalar value. That is, something
64
+ that can be defined with the native types (`int`, `long`, `short`, etc). It is
65
+ highly recommended that these ONLY ever use values from `stdint.h`. This
66
+ ensures that the sizes of these scalars will be consistent across platforms.
67
+
68
+ Scalars can be defined simply by giving them a name that corresponds to a type
69
+ from `stdint.h`.
70
+
71
+ ```ruby
72
+ scalar(:uint8_t)
73
+ scalar(:uint32_t)
74
+ ```
75
+
76
+ ## Enumerations
77
+
78
+ Enumerations correspond almost exactly to C enumerations. They are a list of
79
+ names. When appropriate, a specific scalar value may also be specified. If no
80
+ scalar is specified, enumerations will be represented in order from 0.
81
+
82
+ ```ruby
83
+ enumeration(:color) do |e|
84
+ e.value :red
85
+ e.value :blue
86
+ e.value :green
87
+ end
88
+
89
+ enumeration(:days_of_week) do |e|
90
+ e.value :sunday, 100
91
+ e.value :monday, 101
92
+ e.value :tuesday, 102
93
+ e.value :wednesday, 103
94
+ e.value :thursday, 104
95
+ e.value :friday, 105
96
+ e.value :saturday, 106
97
+ end
98
+ ```
99
+
100
+ ## Fixed Arrays
101
+
102
+ Fixed arrays are arrays that only ever make sense when they are full. An
103
+ example of an array with this property is a MAC Address. MAC addresses are
104
+ always 6 bytes. Never more. Never less.
105
+
106
+ ```ruby
107
+ fixed_array(:mac_address) do |a|
108
+ a.array_type :uint8_t # the type held by the array
109
+ a.array_size 6 # the number of elements in the array
110
+ end
111
+ ```
112
+
113
+ ## Variable Arrays
114
+
115
+ Variable Arrays are arrays that have a maximum length, but may not be entirely
116
+ utilized.
117
+
118
+ ```ruby
119
+ # a way to represent some number of dates/times as 32-bit values
120
+ variable_array(:datetimes) do |a|
121
+ a.size_type :uint8_t # WILL BE DEPRECATED
122
+ a.array_type :int32_t
123
+ a.array_size 128
124
+ end
125
+
126
+ # a string, represented as `int_8`'s, with a maximum length of 32 bytes
127
+ variable_array(:string_32) do |a|
128
+ a.size_type :uint8_t # WILL BE DEPRECATED
129
+ a.array_type :int8_t
130
+ a.array_size 32
131
+ end
132
+ ```
133
+
134
+ ## Composites
135
+
136
+ Composites are very similar to C structures. They are collections of other
137
+ types. Each field has a name and may correspond to any other defined type.
138
+
139
+ ```ruby
140
+ composite(:person) do |c|
141
+ c.field :name, :string_32
142
+ c.field :age, :uint8_t
143
+ c.field :date_of_birth, :uint32_t
144
+ end
145
+ ```
146
+
147
+ ## Groups
148
+
149
+ Groups are similar to C unions with one major difference. Each group is
150
+ comprised of a type tag and a union of the types the union is capable of
151
+ representing. This is known as a tagged union.
152
+
153
+ The tag is used to inform the user application what type the union is currently
154
+ representing. The tag is a special enumeration that is automatically defined.
155
+
156
+ ```ruby
157
+ group(:requests) do |g|
158
+ c.field :add_user, :add_user_request
159
+ c.field :get_user, :get_user_request
160
+ c.field :delete_user, :delete_user_request
161
+ end
162
+
163
+ group(:responses) do |g|
164
+ c.field :add_user, :add_user_response
165
+ c.field :get_user, :get_user_response
166
+ c.field :delete_user, :delete_user_response
167
+ end
168
+ ```
169
+
170
+ Groups don't have to specify a data type in all of their fields.
171
+
172
+ ```ruby
173
+ group(:complex) do |g|
174
+ g.field :a_number, :int32
175
+ g.dataless :a_state # no associated data with this alternative
176
+ end
177
+ ```