fixed printing queue messages
diff --git a/aos/build/queues/print_field.rb b/aos/build/queues/print_field.rb
index c7b8530..75cc1da 100644
--- a/aos/build/queues/print_field.rb
+++ b/aos/build/queues/print_field.rb
@@ -75,7 +75,7 @@
if (*output_bytes < 1) return false;
*input_bytes -= 1;
bool value = static_cast<const char *>(input)[0];
- *output_bytes += 1;
+ *output_bytes -= 1;
*output = value ? 'T' : 'f';
return true;
}
diff --git a/aos/common/print_field_helpers.h b/aos/common/print_field_helpers.h
index 48acdf6..50ac01e 100644
--- a/aos/common/print_field_helpers.h
+++ b/aos/common/print_field_helpers.h
@@ -13,13 +13,13 @@
size_t len = 0;
if (is_signed && val <= 0) {
- while (*output > len && (val != 0 || len == 0)) {
+ while (*output >= len && (val != 0 || len == 0)) {
buf[len++] = '0' - (val % 10);
val /= 10;
}
buf[len++] = '-';
} else {
- while (*output > len && (val != 0 || len == 0)) {
+ while (*output >= len && (val != 0 || len == 0)) {
buf[len++] = '0' + (val % 10);
val /= 10;
}
diff --git a/aos/common/queue_types_test.cc b/aos/common/queue_types_test.cc
index ac7e683..26b5a87 100644
--- a/aos/common/queue_types_test.cc
+++ b/aos/common/queue_types_test.cc
@@ -52,6 +52,9 @@
}
};
+// TODO(brians): Do a better job testing PrintField with the types that have
+// specialized implementations.
+
TEST_F(QueueTypesTest, Serialization) {
char buffer[512];
ssize_t size;
@@ -93,12 +96,12 @@
ASSERT_TRUE(PrintField(output, &output_bytes, input, &input_bytes,
Structure::GetType()->fields[1]->type));
EXPECT_EQ(0u, input_bytes);
- EXPECT_EQ(sizeof(output) - 4, output_bytes);
- EXPECT_EQ(::std::string("971\0", 4),
+ EXPECT_EQ(sizeof(output) - 3, output_bytes);
+ EXPECT_EQ(::std::string("971"),
::std::string(output, sizeof(output) - output_bytes));
}
-// Tests PrintField with trailing input bytes and no extra output bytes.
+// Tests PrintField with trailing input bytes and only 1 extra output byte.
TEST_F(PrintFieldTest, OtherSizes) {
static const float kData = 16.78;
static const ::std::string kString("16.780001");
@@ -110,7 +113,7 @@
ASSERT_TRUE(PrintField(output, &output_bytes, input, &input_bytes,
Structure::GetType()->fields[2]->type));
EXPECT_EQ(kExtraInputBytes, input_bytes);
- EXPECT_EQ(0u, output_bytes);
+ EXPECT_EQ(1u, output_bytes);
EXPECT_EQ(kString, ::std::string(output));
}
@@ -126,7 +129,7 @@
static const uint16_t kData = 12345;
input_bytes = sizeof(input);
to_network(&kData, input);
- output_bytes = 5;
+ output_bytes = 4;
EXPECT_FALSE(PrintField(output, &output_bytes, input, &input_bytes,
Structure::GetType()->fields[1]->type));
}