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.
- checksums.yaml +4 -4
- data/.gitignore +33 -33
- data/.rspec +1 -1
- data/.travisci.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +177 -177
- data/Rakefile +54 -54
- data/bin/cauterize +61 -61
- data/cauterize.gemspec +27 -27
- data/example/Cauterize +68 -68
- data/example/build.sh +25 -25
- data/example/c_example_support/empty_main.c +1 -1
- data/example/c_example_support/example_project_config.c +11 -11
- data/example/c_example_support/example_project_config.h +15 -15
- data/example/ruby_ex.rb +14 -14
- data/lib/cauterize.rb +117 -117
- data/lib/cauterize/base_type.rb +78 -78
- data/lib/cauterize/builders.rb +41 -41
- data/lib/cauterize/builders/c/buildable.rb +91 -91
- data/lib/cauterize/builders/c/builtin.rb +43 -43
- data/lib/cauterize/builders/c/composite.rb +57 -57
- data/lib/cauterize/builders/c/enumeration.rb +60 -60
- data/lib/cauterize/builders/c/fixed_array.rb +74 -74
- data/lib/cauterize/builders/c/group.rb +143 -143
- data/lib/cauterize/builders/c/scalar.rb +34 -34
- data/lib/cauterize/builders/c/variable_array.rb +98 -98
- data/lib/cauterize/builders/cs/buildable.rb +59 -59
- data/lib/cauterize/builders/cs/builtin.rb +22 -22
- data/lib/cauterize/builders/cs/composite.rb +21 -21
- data/lib/cauterize/builders/cs/csarray.rb +32 -32
- data/lib/cauterize/builders/cs/enumeration.rb +21 -21
- data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
- data/lib/cauterize/builders/cs/group.rb +32 -32
- data/lib/cauterize/builders/cs/scalar.rb +10 -10
- data/lib/cauterize/builders/cs/variable_array.rb +40 -34
- data/lib/cauterize/builders/doc/buildable.rb +30 -30
- data/lib/cauterize/builders/doc/builtin.rb +21 -21
- data/lib/cauterize/builders/doc/composite.rb +23 -23
- data/lib/cauterize/builders/doc/enumeration.rb +24 -24
- data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
- data/lib/cauterize/builders/doc/group.rb +29 -29
- data/lib/cauterize/builders/doc/scalar.rb +21 -21
- data/lib/cauterize/builders/doc/variable_array.rb +26 -26
- data/lib/cauterize/builders/ruby/buildable.rb +11 -11
- data/lib/cauterize/builders/ruby/builtin.rb +25 -25
- data/lib/cauterize/builders/ruby/composite.rb +26 -26
- data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
- data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
- data/lib/cauterize/builders/ruby/group.rb +35 -35
- data/lib/cauterize/builders/ruby/scalar.rb +19 -19
- data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
- data/lib/cauterize/builtin.rb +62 -62
- data/lib/cauterize/c_builder.rb +103 -103
- data/lib/cauterize/cauterize.rb +76 -76
- data/lib/cauterize/composite.rb +64 -64
- data/lib/cauterize/cs_builder.rb +58 -58
- data/lib/cauterize/doc_builder.rb +34 -34
- data/lib/cauterize/enumeration.rb +98 -98
- data/lib/cauterize/fixed_array.rb +50 -50
- data/lib/cauterize/formatter.rb +67 -67
- data/lib/cauterize/group.rb +81 -81
- data/lib/cauterize/representation.rb +32 -32
- data/lib/cauterize/ruby_builder.rb +44 -44
- data/lib/cauterize/scalar.rb +53 -53
- data/lib/cauterize/snake_case.rb +21 -21
- data/lib/cauterize/variable_array.rb +55 -55
- data/lib/cauterize/version.rb +3 -3
- data/spec/base_type_spec.rb +251 -251
- data/spec/builders/c/buildable_spec.rb +25 -25
- data/spec/builders/c/builtin_spec.rb +22 -22
- data/spec/builders/c/composite_spec.rb +50 -50
- data/spec/builders/c/enumeration_spec.rb +95 -95
- data/spec/builders/c/fixed_array_spec.rb +36 -36
- data/spec/builders/c/group_spec.rb +140 -140
- data/spec/builders/c/scalar_spec.rb +26 -26
- data/spec/builders/c/variable_array_spec.rb +48 -48
- data/spec/builders/cs/buildable_spec.rb +8 -8
- data/spec/builders/cs/composite_spec.rb +32 -32
- data/spec/builders/cs/enumeration_spec.rb +33 -33
- data/spec/builders/cs/fixed_array_spec.rb +41 -41
- data/spec/builders/cs/group_spec.rb +56 -56
- data/spec/builders/cs/scalar_spec.rb +7 -7
- data/spec/builders/cs/variable_array_spec.rb +49 -45
- data/spec/builders/doc/buildable_spec.rb +25 -25
- data/spec/builders_spec.rb +57 -57
- data/spec/builtin_spec.rb +43 -43
- data/spec/c_builder_spec.rb +176 -176
- data/spec/cauterize_spec.rb +15 -15
- data/spec/composite_spec.rb +77 -77
- data/spec/cs_builder_spec.rb +115 -115
- data/spec/doc_builder_spec.rb +260 -260
- data/spec/enumeration_spec.rb +145 -145
- data/spec/fixed_array_spec.rb +61 -61
- data/spec/group_spec.rb +111 -111
- data/spec/ruby_builder_spec.rb +83 -83
- data/spec/ruby_generated_spec.rb +735 -735
- data/spec/scalar_spec.rb +44 -44
- data/spec/spec_helper.rb +122 -122
- data/spec/support/shared_examples_for_array_buildables.rb +22 -22
- data/spec/support/shared_examples_for_c_buildables.rb +103 -103
- data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
- data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
- data/spec/support/spec_sample_model.rb +74 -74
- data/spec/test_main.c +13 -13
- data/spec/variable_array_spec.rb +73 -73
- data/support/c/src/cauterize.c +75 -75
- data/support/c/src/cauterize.h +60 -60
- data/support/c/src/cauterize_debug.h +29 -29
- data/support/c/src/cauterize_util.h +8 -8
- data/support/c/test/greatest.h +536 -536
- data/support/c/test/test.c +166 -166
- data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
- data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
- data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
- data/support/cs/src/CauterizeException.cs +15 -15
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
- data/support/cs/src/CauterizeFormatter.cs +0 -0
- data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
- data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
- data/support/cs/src/CauterizeTypes.cs +46 -12
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
- data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
- data/support/cs/src/OrderAttribute.cs +0 -0
- data/support/cs/src/PrimitiveSupport.cs +12 -0
- data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
- data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
- data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
- data/support/cs/test/OrderAttributeTest.cs +0 -0
- data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
- data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d11716e541353c226d505c7a4722a81e682d9e2a
|
4
|
+
data.tar.gz: ac8804479d6ebc0ed4ab1b606a480f74ac3ba101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/.travisci.yml
CHANGED
@@ -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
|
data/LICENSE.txt
CHANGED
@@ -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
|
+
```
|