blob: 84cf1f4d906b695da5160dc6f386b02aa8a0fa1c [file] [log] [blame]
Brian Silverman1885bd02014-02-13 12:28:12 -08001require File.dirname(__FILE__) + '/load.rb'
2
3TypeNames = [8, 16, 32, 64].collect do |size|
4 ["uint#{size}_t", "int#{size}_t"]
Brian Silverman96e6d5a2014-03-24 15:55:40 -07005end.flatten + ['bool', 'float', 'char', 'double', '::aos::time::Time']
Brian Silverman1885bd02014-02-13 12:28:12 -08006
Brian Silvermancbbc3c42014-02-22 18:33:17 -08007WriteIffChanged.open(ARGV[0]) do |output|
Brian Silverman1885bd02014-02-13 12:28:12 -08008 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 Silverman96e6d5a2014-03-24 15:55:40 -070018#include "aos/common/time.h"
Brian Silverman1885bd02014-02-13 12:28:12 -080019
20namespace aos {
21
Brian Silvermand4b1ed52014-02-15 15:26:04 -080022bool PrintField(char *output, size_t *output_bytes, const void *input,
Brian Silverman1885bd02014-02-13 12:28:12 -080023 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 }
46END2
47end.join('')}
48 default:
49 return false;
50 }
51}
52
53} // namespace aos
54END
55end