protobuf-generate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5a62cd275937980b1b0288c6c4c89ebae992616
4
- data.tar.gz: 697457604b2bdf9f5f68618925df3091c1d3b137
3
+ metadata.gz: fa660a22bbbf1df9773fa0d2740b8379c39f50b2
4
+ data.tar.gz: 1115bc3ce6f5054a2153bfe71c7625b471dbdd51
5
5
  SHA512:
6
- metadata.gz: 77564ae6657f10076c844674d118cb7693e7563c752505a0bf1b9f7d28500ac8c5e355238d31b60eabc0eada4c450bafcebc2b7da65cac667ecc2f052b4bd0b1
7
- data.tar.gz: 7c74335a4d38437e6b64853dfb247140fdd60ed642e1818cb108f74417e1bc817bbee70cacb1561318fb5585c2b17976d4938a9c69aef751ae78e8aba5b5aabf
6
+ metadata.gz: 2d47e29531f20c161ed8d3f0c84ef7263540fe4c20ebd30cd96d02aac0cd5b43556387589d527ba33dc018fdb9e03ae9cef621dba79c998c35f936590c389be0
7
+ data.tar.gz: 1ccba34aed35c2fb0ce4007cd37ded06cee2eaaa9091641eab08ef323b6b363ac8cf0a0b5e5b8ad18428925054c970cb5a9530f0a3cf4d33bcefd09f48d8eaf4
@@ -29,6 +29,18 @@ int write_raw_little_endian64(uint64_t value, uint8_t *buffer, int offset) {
29
29
  return offset;
30
30
  }
31
31
 
32
+ int write_raw_float(float value, uint8_t *buffer, int offset) {
33
+ union { uint32_t i; float f; } punner;
34
+ punner.f = value;
35
+ return write_raw_little_endian32(punner.i, buffer, offset);
36
+ }
37
+
38
+ int write_raw_double(double value, uint8_t *buffer, int offset) {
39
+ union { uint64_t i; double f; } punner;
40
+ punner.f = value;
41
+ return write_raw_little_endian64(punner.i, buffer, offset);
42
+ }
43
+
32
44
  int write_raw_varint32(uint32_t value, uint8_t *buffer, int offset) {
33
45
  while (1) {
34
46
  if ((value & ~0x7F) == 0) {
@@ -129,6 +141,20 @@ int read_raw_little_endian64(uint64_t *tag, const uint8_t *buffer, int offset) {
129
141
  return offset;
130
142
  }
131
143
 
144
+ int read_raw_float(float *value, const uint8_t *buffer, int offset) {
145
+ union { uint32_t i; float f; } punner;
146
+ offset = read_raw_little_endian32(&punner.i, buffer, offset);
147
+ *value = punner.f;
148
+ return offset;
149
+ }
150
+
151
+ int read_raw_double(double *value, const uint8_t *buffer, int offset) {
152
+ union { uint64_t i; double f; } punner;
153
+ offset = read_raw_little_endian64(&punner.i, buffer, offset);
154
+ *value = punner.f;
155
+ return offset;
156
+ }
157
+
132
158
  int read_raw_varint32(uint32_t *tag, const uint8_t *buffer, int offset) {
133
159
  uint8_t result;
134
160
 
@@ -249,12 +275,12 @@ int read_raw_varint64(uint64_t *tag, const uint8_t *buffer, int offset) {
249
275
  <% elsif field.type =~ /double/ %>
250
276
  if (pb-><%= field.name %> != <%= field.options.fetch('default', 0) %>) {
251
277
  offset = write_raw_varint32((<%= field.tag %><<3)+<%= type_wire field.type %>, buffer, offset);
252
- offset = write_raw_little_endian64(*(uint64_t *)&pb-><%= field.name %>, buffer, offset);
278
+ offset = write_raw_double(pb-><%= field.name %>, buffer, offset);
253
279
  }
254
280
  <% elsif field.type =~ /float/ %>
255
281
  if (pb-><%= field.name %> != <%= field.options.fetch('default', 0) %>) {
256
282
  offset = write_raw_varint32((<%= field.tag %><<3)+<%= type_wire field.type %>, buffer, offset);
257
- offset = write_raw_little_endian32(*(uint32_t *)&pb-><%= field.name %>, buffer, offset);
283
+ offset = write_raw_float(pb-><%= field.name %>, buffer, offset);
258
284
  }
259
285
  <% elsif field.type =~ /int32/%>
260
286
  if (pb-><%= field.name %> != <%= field.options.fetch('default', 0) %>) {
@@ -323,10 +349,10 @@ int read_raw_varint64(uint64_t *tag, const uint8_t *buffer, int offset) {
323
349
  offset = write_raw_varint32(pb-><%= field.name %>, buffer, offset);
324
350
  <% elsif field.type =~ /double/ %>
325
351
  offset = write_raw_varint32((<%= field.tag %><<3)+<%= type_wire field.type %>, buffer, offset);
326
- offset = write_raw_little_endian64(*(uint64_t *)&pb-><%= field.name %>, buffer, offset);
352
+ offset = write_raw_double(pb-><%= field.name %>, buffer, offset);
327
353
  <% elsif field.type =~ /float/ %>
328
354
  offset = write_raw_varint32((<%= field.tag %><<3)+<%= type_wire field.type %>, buffer, offset);
329
- offset = write_raw_little_endian32(*(uint32_t *)&pb-><%= field.name %>, buffer, offset);
355
+ offset = write_raw_float(pb-><%= field.name %>, buffer, offset);
330
356
  <% elsif field.type =~ /int32/ %>
331
357
  offset = write_raw_varint32((<%= field.tag %><<3)+<%= type_wire field.type %>, buffer, offset);
332
358
  if (pb-><%= field.name %> >= 0) offset = write_raw_varint32(pb-><%= field.name %>, buffer, offset);
@@ -413,14 +439,9 @@ int read_raw_varint64(uint64_t *tag, const uint8_t *buffer, int offset) {
413
439
  offset = read_raw_varint32(&tag, buffer, offset);
414
440
  pb-><%= field.name %> = tag;
415
441
  <% elsif field.type =~ /float/ %>
416
- offset = read_raw_little_endian32(&tag, buffer, offset);
417
- pb-><%= field.name %> = *(float *)(&tag);
442
+ offset = read_raw_float(&pb-><%= field.name %>, buffer, offset);
418
443
  <% elsif field.type =~ /double/ %>
419
- {
420
- uint64_t value = 0;
421
- offset = read_raw_little_endian64(&value, buffer, offset);
422
- pb-><%= field.name %> = *(double *)(&value);
423
- }
444
+ offset = read_raw_double(&pb-><%= field.name %>, buffer, offset);
424
445
  <% elsif field.type =~ /int32/ %>
425
446
  offset = read_raw_varint32(&tag, buffer, offset);
426
447
  pb-><%= field.name %> = (int32_t)tag;
@@ -12,10 +12,14 @@
12
12
  // Remove. Have parser count type usage and only include the code if required.
13
13
  int write_raw_little_endian32(uint32_t value, uint8_t *buffer, int offset);
14
14
  int write_raw_little_endian64(uint64_t value, uint8_t *buffer, int offset);
15
+ int write_raw_float(float value, uint8_t *buffer, int offset);
16
+ int write_raw_double(double value, uint8_t *buffer, int offset);
15
17
  int write_raw_varint32(uint32_t value, uint8_t *buffer, int offset);
16
18
  int write_raw_varint64(uint64_t value, uint8_t *buffer, int offset);
17
19
  int read_raw_little_endian32(uint32_t *tag, const uint8_t *buffer, int offset);
18
20
  int read_raw_little_endian64(uint64_t *tag, const uint8_t *buffer, int offset);
21
+ int read_raw_float(float *tag, const uint8_t *buffer, int offset);
22
+ int read_raw_double(double *tag, const uint8_t *buffer, int offset);
19
23
  int read_raw_varint32(uint32_t *tag, const uint8_t *buffer, int offset);
20
24
  int read_raw_varint64(uint64_t *tag, const uint8_t *buffer, int offset);
21
25
 
@@ -2,7 +2,7 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = 'protobuf-generate'
5
- s.version = '0.1.0'
5
+ s.version = '0.1.1'
6
6
  s.summary = 'A multi-language concrete protobuf code generator.'
7
7
  s.description = 'A simple PEG parser, AST and template based approach to code generation.'
8
8
  s.authors = ['Shane Hanna']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-generate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Hanna
@@ -78,8 +78,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 2.0.3
81
+ rubygems_version: 2.0.0
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: A multi-language concrete protobuf code generator.
85
85
  test_files: []
86
+ has_rdoc: