Brian Silverman | 1885bd0 | 2014-02-13 12:28:12 -0800 | [diff] [blame] | 1 | require File.dirname(__FILE__) + '/load.rb' |
| 2 | |
| 3 | TypeNames = [8, 16, 32, 64].collect do |size| |
| 4 | ["uint#{size}_t", "int#{size}_t"] |
Brian Silverman | 96e6d5a | 2014-03-24 15:55:40 -0700 | [diff] [blame^] | 5 | end.flatten + ['bool', 'float', 'char', 'double', '::aos::time::Time'] |
Brian Silverman | 1885bd0 | 2014-02-13 12:28:12 -0800 | [diff] [blame] | 6 | |
Brian Silverman | cbbc3c4 | 2014-02-22 18:33:17 -0800 | [diff] [blame] | 7 | WriteIffChanged.open(ARGV[0]) do |output| |
Brian Silverman | 1885bd0 | 2014-02-13 12:28:12 -0800 | [diff] [blame] | 8 | output.puts <<END |
| 9 | // This file is generated by #{File.expand_path(__FILE__)}. |
| 10 | // DO NOT EDIT BY HAND! |
| 11 | |
| 12 | #include <sys/types.h> |
| 13 | #include <stdint.h> |
| 14 | #include <inttypes.h> |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | #include "aos/common/byteorder.h" |
Brian Silverman | 96e6d5a | 2014-03-24 15:55:40 -0700 | [diff] [blame^] | 18 | #include "aos/common/time.h" |
Brian Silverman | 1885bd0 | 2014-02-13 12:28:12 -0800 | [diff] [blame] | 19 | |
| 20 | namespace aos { |
| 21 | |
Brian Silverman | d4b1ed5 | 2014-02-15 15:26:04 -0800 | [diff] [blame] | 22 | bool PrintField(char *output, size_t *output_bytes, const void *input, |
Brian Silverman | 1885bd0 | 2014-02-13 12:28:12 -0800 | [diff] [blame] | 23 | size_t *input_bytes, uint32_t type) { |
| 24 | switch (type) { |
| 25 | #{TypeNames.collect do |name| |
| 26 | message_element = Target::MessageElement.new(name, 'value') |
| 27 | statement = MessageElementStmt.new(name, 'value') |
| 28 | message_element.size = statement.size |
| 29 | print_args = [] |
| 30 | message_element.fetchPrintArgs(print_args) |
| 31 | next <<END2 |
| 32 | case #{message_element.getTypeID()}: |
| 33 | { |
| 34 | if (*input_bytes < #{statement.size}) return false; |
| 35 | *input_bytes -= #{statement.size}; |
| 36 | #{name} value; |
| 37 | to_host(static_cast<const char *>(input), &value); |
| 38 | int ret = snprintf(output, *output_bytes, |
| 39 | "#{statement.toPrintFormat()}", |
| 40 | #{print_args[0]}); |
| 41 | if (ret < 0) return false; |
| 42 | if (static_cast<unsigned int>(ret) >= *output_bytes) return false; |
| 43 | *output_bytes -= ret + 1; |
| 44 | return true; |
| 45 | } |
| 46 | END2 |
| 47 | end.join('')} |
| 48 | default: |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } // namespace aos |
| 54 | END |
| 55 | end |