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
@@ -1,22 +1,22 @@
1
- include Cauterize::Builders::C
2
-
3
- shared_examples "a sane buildable" do
4
- let(:desc_instance) { type_constructor.call(:some_type_name) }
5
- let(:formatter) { default_formatter }
6
- subject { described_class.new(desc_instance) }
7
-
8
- describe :render do
9
- it "contains the name" do
10
- subject.render.should match /some_type_name/
11
- end
12
- end
13
-
14
- describe :declare do
15
- before { subject.declare(formatter, :some_sym) }
16
-
17
- it "contains the name and a ;" do
18
- formatter.to_s.should match /some_type_name/
19
- formatter.to_s.should match /;/
20
- end
21
- end
22
- end
1
+ include Cauterize::Builders::C
2
+
3
+ shared_examples "a sane buildable" do
4
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
5
+ let(:formatter) { default_formatter }
6
+ subject { described_class.new(desc_instance) }
7
+
8
+ describe :render do
9
+ it "contains the name" do
10
+ subject.render.should match /some_type_name/
11
+ end
12
+ end
13
+
14
+ describe :declare do
15
+ before { subject.declare(formatter, :some_sym) }
16
+
17
+ it "contains the name and a ;" do
18
+ formatter.to_s.should match /some_type_name/
19
+ formatter.to_s.should match /;/
20
+ end
21
+ end
22
+ end
@@ -1,18 +1,18 @@
1
- # shared examples for stubbed functions
2
-
3
- include Cauterize::Builders::C
4
-
5
- shared_examples "no struct" do
6
- let(:desc_instance) { type_constructor.call(:some_type_name) }
7
- let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
8
-
9
- it { builder.struct_proto(:f).should be_nil }
10
- it { builder.struct_defn(:f).should be_nil }
11
- end
12
-
13
- shared_examples "no enum" do
14
- let(:desc_instance) { type_constructor.call(:some_type_name) }
15
- let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
16
-
17
- it { builder.enum_defn(:f).should be_nil }
18
- end
1
+ # shared examples for stubbed functions
2
+
3
+ include Cauterize::Builders::C
4
+
5
+ shared_examples "no struct" do
6
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
7
+ let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
8
+
9
+ it { builder.struct_proto(:f).should be_nil }
10
+ it { builder.struct_defn(:f).should be_nil }
11
+ end
12
+
13
+ shared_examples "no enum" do
14
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
15
+ let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
16
+
17
+ it { builder.enum_defn(:f).should be_nil }
18
+ end
@@ -1,74 +1,74 @@
1
- module Cauterize
2
- module CauterizeHelpers
3
- def gen_a_model
4
- Cauterize.scalar(:foo) do |t|
5
- t.type_name :uint8
6
- end
7
-
8
- Cauterize.enumeration(:color) do |e|
9
- e.value :red
10
- e.value :blue
11
- e.value :green
12
- end
13
-
14
- Cauterize.fixed_array(:color_list) do |a|
15
- a.array_type :color
16
- a.array_size 41
17
- end
18
-
19
- Cauterize.variable_array(:int8_list) do |a|
20
- a.array_type :int8
21
- a.array_size 200
22
- end
23
-
24
- Cauterize.composite(:two_things) do |t|
25
- t.field :thing_1, :uint8
26
- t.field :thing_2, :uint16
27
- end
28
-
29
- Cauterize.group(:one_of_everything) do |t|
30
- t.field :a_foo, :foo
31
- t.field :a_color, :color
32
- t.field :a_color_list, :color_list
33
- t.field :an_int8_list, :int8_list
34
- t.field :a_two_things, :two_things
35
- end
36
- end
37
-
38
- def gen_b_model
39
- Cauterize.scalar(:foo) do |t|
40
- t.type_name :uint8
41
- end
42
-
43
- Cauterize.enumeration(:color) do |e|
44
- e.value :red
45
- e.value :blue
46
- e.value :green
47
- end
48
-
49
- Cauterize.fixed_array(:color_list) do |a|
50
- a.array_type :color
51
- a.array_size 41
52
- end
53
-
54
- Cauterize.variable_array(:int8_list) do |a|
55
- a.array_type :int8
56
- a.array_size 2000
57
- end
58
-
59
- Cauterize.composite(:two_things) do |t|
60
- t.field :thing_1, :uint8
61
- t.field :thing_2, :uint16
62
- end
63
-
64
- Cauterize.group(:one_of_everything) do |t|
65
- t.field :a_foo, :foo
66
- t.field :a_color, :color
67
- t.field :a_color_list, :color_list
68
- t.field :an_int8_list, :int8_list
69
- t.field :a_two_things, :two_things
70
- t.dataless :emptyness
71
- end
72
- end
73
- end
74
- end
1
+ module Cauterize
2
+ module CauterizeHelpers
3
+ def gen_a_model
4
+ Cauterize.scalar(:foo) do |t|
5
+ t.type_name :uint8
6
+ end
7
+
8
+ Cauterize.enumeration(:color) do |e|
9
+ e.value :red
10
+ e.value :blue
11
+ e.value :green
12
+ end
13
+
14
+ Cauterize.fixed_array(:color_list) do |a|
15
+ a.array_type :color
16
+ a.array_size 41
17
+ end
18
+
19
+ Cauterize.variable_array(:int8_list) do |a|
20
+ a.array_type :int8
21
+ a.array_size 200
22
+ end
23
+
24
+ Cauterize.composite(:two_things) do |t|
25
+ t.field :thing_1, :uint8
26
+ t.field :thing_2, :uint16
27
+ end
28
+
29
+ Cauterize.group(:one_of_everything) do |t|
30
+ t.field :a_foo, :foo
31
+ t.field :a_color, :color
32
+ t.field :a_color_list, :color_list
33
+ t.field :an_int8_list, :int8_list
34
+ t.field :a_two_things, :two_things
35
+ end
36
+ end
37
+
38
+ def gen_b_model
39
+ Cauterize.scalar(:foo) do |t|
40
+ t.type_name :uint8
41
+ end
42
+
43
+ Cauterize.enumeration(:color) do |e|
44
+ e.value :red
45
+ e.value :blue
46
+ e.value :green
47
+ end
48
+
49
+ Cauterize.fixed_array(:color_list) do |a|
50
+ a.array_type :color
51
+ a.array_size 41
52
+ end
53
+
54
+ Cauterize.variable_array(:int8_list) do |a|
55
+ a.array_type :int8
56
+ a.array_size 2000
57
+ end
58
+
59
+ Cauterize.composite(:two_things) do |t|
60
+ t.field :thing_1, :uint8
61
+ t.field :thing_2, :uint16
62
+ end
63
+
64
+ Cauterize.group(:one_of_everything) do |t|
65
+ t.field :a_foo, :foo
66
+ t.field :a_color, :color
67
+ t.field :a_color_list, :color_list
68
+ t.field :an_int8_list, :int8_list
69
+ t.field :a_two_things, :two_things
70
+ t.dataless :emptyness
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,13 +1,13 @@
1
- #include "testing.h"
2
-
3
- int main(int argc, char * argv[])
4
- {
5
- (void)argc;
6
- (void)argv;
7
-
8
- void * ptr;
9
-
10
- ptr = (void *)Pack_enum_group_animal_type;
11
-
12
- return 0;
13
- }
1
+ #include "testing.h"
2
+
3
+ int main(int argc, char * argv[])
4
+ {
5
+ (void)argc;
6
+ (void)argv;
7
+
8
+ void * ptr;
9
+
10
+ ptr = (void *)Pack_enum_group_animal_type;
11
+
12
+ return 0;
13
+ }
@@ -1,73 +1,73 @@
1
- module Cauterize
2
- describe :variable_array do
3
- it { creates_a_named_object(:variable_array, VariableArray) }
4
- it { retrieves_obj_with_identical_name(:variable_array) }
5
- it { yields_the_object(:variable_array) }
6
- it { adds_object_to_hash(:variable_array, Cauterize.variable_arrays) }
7
- end
8
-
9
- describe :variable_array! do
10
- it { creates_a_named_object(:variable_array!, VariableArray) }
11
- it { raises_exception_with_identical_name(:variable_array!) }
12
- it { yields_the_object(:variable_array!) }
13
- it { adds_object_to_hash(:variable_array!, Cauterize.variable_arrays) }
14
- end
15
-
16
- describe :variable_arrays do
17
- it { is_hash_of_created_objs(:variable_array, Cauterize.variable_arrays) }
18
- end
19
-
20
- describe VariableArray do
21
- before { @a = VariableArray.new(:foo) }
22
-
23
- describe :initialize do
24
- it "creates a VariableArray" do
25
- @a.name.should == :foo
26
- end
27
- end
28
-
29
- describe :array_type do
30
- it "defines the type of the VariableArray" do
31
- Cauterize.scalar(:uint32_t)
32
- @a.array_type :uint32_t
33
- @a.instance_variable_get(:@array_type).name.should == :uint32_t
34
- end
35
-
36
- it "raises an error if type doesn't exist" do
37
- lambda {
38
- Cauterize.fixed_array(:fa) do |f|
39
- f.array_type :lol
40
- end
41
- }.should raise_error /lol does not correspond/
42
- end
43
-
44
- it "is the defined type if no argument is passed" do
45
- s = Cauterize.scalar(:uint32_t)
46
- @a.array_type :uint32_t
47
- @a.array_type.should be s
48
- end
49
- end
50
-
51
- describe :array_size do
52
- it "Defines the size of the FixedArray." do
53
- @a.array_size 46
54
- @a.instance_variable_get(:@array_size).should == 46
55
- end
56
-
57
- it "is the defined size if no argument is passed" do
58
- @a.array_size 46
59
- @a.array_size.should == 46
60
- end
61
- end
62
-
63
- describe :size_type do
64
- it "determines the type used to encode the array size" do
65
- @a.array_size 30000
66
- @a.size_type.name.should == :uint16
67
-
68
- @a.array_size 10
69
- @a.size_type.name.should == :uint8
70
- end
71
- end
72
- end
73
- end
1
+ module Cauterize
2
+ describe :variable_array do
3
+ it { creates_a_named_object(:variable_array, VariableArray) }
4
+ it { retrieves_obj_with_identical_name(:variable_array) }
5
+ it { yields_the_object(:variable_array) }
6
+ it { adds_object_to_hash(:variable_array, Cauterize.variable_arrays) }
7
+ end
8
+
9
+ describe :variable_array! do
10
+ it { creates_a_named_object(:variable_array!, VariableArray) }
11
+ it { raises_exception_with_identical_name(:variable_array!) }
12
+ it { yields_the_object(:variable_array!) }
13
+ it { adds_object_to_hash(:variable_array!, Cauterize.variable_arrays) }
14
+ end
15
+
16
+ describe :variable_arrays do
17
+ it { is_hash_of_created_objs(:variable_array, Cauterize.variable_arrays) }
18
+ end
19
+
20
+ describe VariableArray do
21
+ before { @a = VariableArray.new(:foo) }
22
+
23
+ describe :initialize do
24
+ it "creates a VariableArray" do
25
+ @a.name.should == :foo
26
+ end
27
+ end
28
+
29
+ describe :array_type do
30
+ it "defines the type of the VariableArray" do
31
+ Cauterize.scalar(:uint32_t)
32
+ @a.array_type :uint32_t
33
+ @a.instance_variable_get(:@array_type).name.should == :uint32_t
34
+ end
35
+
36
+ it "raises an error if type doesn't exist" do
37
+ lambda {
38
+ Cauterize.fixed_array(:fa) do |f|
39
+ f.array_type :lol
40
+ end
41
+ }.should raise_error /lol does not correspond/
42
+ end
43
+
44
+ it "is the defined type if no argument is passed" do
45
+ s = Cauterize.scalar(:uint32_t)
46
+ @a.array_type :uint32_t
47
+ @a.array_type.should be s
48
+ end
49
+ end
50
+
51
+ describe :array_size do
52
+ it "Defines the size of the FixedArray." do
53
+ @a.array_size 46
54
+ @a.instance_variable_get(:@array_size).should == 46
55
+ end
56
+
57
+ it "is the defined size if no argument is passed" do
58
+ @a.array_size 46
59
+ @a.array_size.should == 46
60
+ end
61
+ end
62
+
63
+ describe :size_type do
64
+ it "determines the type used to encode the array size" do
65
+ @a.array_size 30000
66
+ @a.size_type.name.should == :uint16
67
+
68
+ @a.array_size 10
69
+ @a.size_type.name.should == :uint8
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,75 +1,75 @@
1
- #define CAUTERIZE_C
2
-
3
- #include "cauterize.h"
4
- #include "cauterize_util.h"
5
- #include "cauterize_debug.h"
6
-
7
- #include <string.h>
8
-
9
- #define S CAUTERIZE_STATUS_T
10
- #define T struct Cauterize
11
-
12
- S CauterizeInitAppend(T * m, uint8_t * buffer, uint32_t length)
13
- {
14
- CA_ASSERT(NULL != m);
15
- CA_ASSERT(NULL != buffer);
16
-
17
- m->size = length;
18
- m->used = 0;
19
- m->pos = 0;
20
- m->buffer = buffer;
21
-
22
- return CA_OK;
23
- }
24
-
25
- S CauterizeInitRead(T * m, uint8_t * buffer, uint32_t used)
26
- {
27
- CA_ASSERT(NULL != m);
28
- CA_ASSERT(NULL != buffer);
29
-
30
- m->size = used;
31
- m->used = used;
32
- m->pos = 0;
33
- m->buffer = buffer;
34
-
35
- return CA_OK;
36
- }
37
-
38
- S CauterizeAppend(T * m, uint8_t * src, uint32_t length)
39
- {
40
- CA_ASSERT(NULL != m);
41
- CA_ASSERT(NULL != src);
42
-
43
- uint32_t needed = m->used + length;
44
-
45
- if (needed > m->size)
46
- return CA_ERR_NOT_ENOUGH_SPACE;
47
-
48
- uint8_t * dest = &m->buffer[m->used];
49
- memcpy(dest, src, length);
50
- m->used += length;
51
-
52
- return CA_OK;
53
- }
54
-
55
- S CauterizeRead(T * m, uint8_t * dst, uint32_t length)
56
- {
57
- CA_ASSERT(NULL != m);
58
- CA_ASSERT(NULL != dst);
59
- CA_ASSERT(m->used >= m->pos);
60
-
61
- uint32_t available = m->used - m->pos;
62
-
63
- if (length > available)
64
- return CA_ERR_NOT_ENOUGH_DATA;
65
-
66
- uint8_t * src = &m->buffer[m->pos];
67
- memcpy(dst, src, length);
68
- m->pos += length;
69
-
70
- return CA_OK;
71
- }
72
-
73
- #undef S
74
- #undef T
75
- #undef CAUTERIZE_C
1
+ #define CAUTERIZE_C
2
+
3
+ #include "cauterize.h"
4
+ #include "cauterize_util.h"
5
+ #include "cauterize_debug.h"
6
+
7
+ #include <string.h>
8
+
9
+ #define S CAUTERIZE_STATUS_T
10
+ #define T struct Cauterize
11
+
12
+ S CauterizeInitAppend(T * m, uint8_t * buffer, uint32_t length)
13
+ {
14
+ CA_ASSERT(NULL != m);
15
+ CA_ASSERT(NULL != buffer);
16
+
17
+ m->size = length;
18
+ m->used = 0;
19
+ m->pos = 0;
20
+ m->buffer = buffer;
21
+
22
+ return CA_OK;
23
+ }
24
+
25
+ S CauterizeInitRead(T * m, uint8_t * buffer, uint32_t used)
26
+ {
27
+ CA_ASSERT(NULL != m);
28
+ CA_ASSERT(NULL != buffer);
29
+
30
+ m->size = used;
31
+ m->used = used;
32
+ m->pos = 0;
33
+ m->buffer = buffer;
34
+
35
+ return CA_OK;
36
+ }
37
+
38
+ S CauterizeAppend(T * m, uint8_t * src, uint32_t length)
39
+ {
40
+ CA_ASSERT(NULL != m);
41
+ CA_ASSERT(NULL != src);
42
+
43
+ uint32_t needed = m->used + length;
44
+
45
+ if (needed > m->size)
46
+ return CA_ERR_NOT_ENOUGH_SPACE;
47
+
48
+ uint8_t * dest = &m->buffer[m->used];
49
+ memcpy(dest, src, length);
50
+ m->used += length;
51
+
52
+ return CA_OK;
53
+ }
54
+
55
+ S CauterizeRead(T * m, uint8_t * dst, uint32_t length)
56
+ {
57
+ CA_ASSERT(NULL != m);
58
+ CA_ASSERT(NULL != dst);
59
+ CA_ASSERT(m->used >= m->pos);
60
+
61
+ uint32_t available = m->used - m->pos;
62
+
63
+ if (length > available)
64
+ return CA_ERR_NOT_ENOUGH_DATA;
65
+
66
+ uint8_t * src = &m->buffer[m->pos];
67
+ memcpy(dst, src, length);
68
+ m->pos += length;
69
+
70
+ return CA_OK;
71
+ }
72
+
73
+ #undef S
74
+ #undef T
75
+ #undef CAUTERIZE_C