Stop stripping the size prefix off
This turns out to be super dangerous to do. A flatbuffer is aligned
assuming that the size is either there or not there. By removing it,
you break alignment.
This necesitates having 2 subclasses of Flatbuffer. A SizePrefixed
version and a non size prefixed version. That lets us distinguish for
methods which care.
Once all that's done, deal with the fallout through the code base,
including logfile_utils and the chaos that causes rippling out.
Change-Id: I91b7be355279a1c19e5c956c33359df01a17eacf
diff --git a/aos/json_to_flatbuffer_test.cc b/aos/json_to_flatbuffer_test.cc
index 80dec7c..4379ae9 100644
--- a/aos/json_to_flatbuffer_test.cc
+++ b/aos/json_to_flatbuffer_test.cc
@@ -16,14 +16,14 @@
bool JsonAndBack(const ::std::string in, const ::std::string out) {
printf("Testing: %s\n", in.c_str());
- const flatbuffers::DetachedBuffer fb =
- JsonToFlatbuffer(in.data(), ConfigurationTypeTable());
+ FlatbufferDetachedBuffer<Configuration> fb =
+ JsonToFlatbuffer<Configuration>(in.data());
- if (fb.size() == 0) {
+ if (fb.span().size() == 0) {
return false;
}
- const ::std::string back = FlatbufferToJson(fb, ConfigurationTypeTable());
+ const ::std::string back = FlatbufferToJson(fb);
printf("Back to string: %s\n", back.c_str());
@@ -215,17 +215,17 @@
json_short += " ] }";
json_long += ", 101 ] }";
- const flatbuffers::DetachedBuffer fb_short =
- JsonToFlatbuffer(json_short.data(), ConfigurationTypeTable());
- ASSERT_GT(fb_short.size(), 0);
- const flatbuffers::DetachedBuffer fb_long =
- JsonToFlatbuffer(json_long.data(), ConfigurationTypeTable());
- ASSERT_GT(fb_long.size(), 0);
+ const FlatbufferDetachedBuffer<Configuration> fb_short(
+ JsonToFlatbuffer<Configuration>(json_short));
+ ASSERT_GT(fb_short.span().size(), 0);
+ const FlatbufferDetachedBuffer<Configuration> fb_long(
+ JsonToFlatbuffer<Configuration>(json_long));
+ ASSERT_GT(fb_long.span().size(), 0);
- const std::string back_json_short = FlatbufferToJson(
- fb_short, ConfigurationTypeTable(), {.multi_line = false, .max_vector_size = 100});
- const std::string back_json_long = FlatbufferToJson(
- fb_long, ConfigurationTypeTable(), {.multi_line = false, .max_vector_size = 100});
+ const std::string back_json_short = FlatbufferToJson<Configuration>(
+ fb_short, {.multi_line = false, .max_vector_size = 100});
+ const std::string back_json_long = FlatbufferToJson<Configuration>(
+ fb_long, {.multi_line = false, .max_vector_size = 100});
EXPECT_EQ(json_short, back_json_short);
EXPECT_EQ("{ \"vector_foo_int\": [ ... 101 elements ... ] }", back_json_long);