blob: 8e9521e8665d645933b0f14053669f5aff853f4c [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"]
5end.flatten + ['bool', 'float', 'char', 'double']
6
7File.open(ARGV[0], 'w') do |output|
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"
18
19namespace aos {
20
21bool PrintField(char *output, size_t *output_bytes, void *input,
22 size_t *input_bytes, uint32_t type) {
23 switch (type) {
24#{TypeNames.collect do |name|
25 message_element = Target::MessageElement.new(name, 'value')
26 statement = MessageElementStmt.new(name, 'value')
27 message_element.size = statement.size
28 print_args = []
29 message_element.fetchPrintArgs(print_args)
30 next <<END2
31 case #{message_element.getTypeID()}:
32 {
33 if (*input_bytes < #{statement.size}) return false;
34 *input_bytes -= #{statement.size};
35 #{name} value;
36 to_host(static_cast<const char *>(input), &value);
37 int ret = snprintf(output, *output_bytes,
38 "#{statement.toPrintFormat()}",
39 #{print_args[0]});
40 if (ret < 0) return false;
41 if (static_cast<unsigned int>(ret) >= *output_bytes) return false;
42 *output_bytes -= ret + 1;
43 return true;
44 }
45END2
46end.join('')}
47 default:
48 return false;
49 }
50}
51
52} // namespace aos
53END
54end