Implement PII Stripper, part 2

Implement EncodedBuffer that strip pii based on given privacy request.
The reason to implement another buffer is the length-delimited field's
size could change when its submessage gets stripped. It also intends to
keep the orignal data around for other requests to consume it.

In addition, the section implementation has adapted EncodedBuffer so
write out to each request's fd could be request-specific. The next step
is allow requests to set its privacy spec.

Notice the current design set the privacy spec of dropbox to AUTOMATIC,
this behavior might change in the future.

Bug: 64687253
Test: unit tests are writtern, see README.md for how to run unit tests.
Change-Id: I7ac236b8265ba9289dc6e17a8a5bf7f67ffb6bf5
diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp
index 23aafb2..7966d88 100644
--- a/tools/incident_section_gen/main.cpp
+++ b/tools/incident_section_gen/main.cpp
@@ -135,27 +135,24 @@
                 if (generatePrivacyFlags(field->message_type(), field_name, msgNames) &&
                     isDefaultDest(field)) break;
 
-                printf("static Privacy %s = { %d, %d, %d, NULL, %s_LIST };\n", field_name, field->number(),
-                        (int) field->type(), p.dest(), field_name);
+                printf("Privacy %s(%d, %s_LIST);\n", field_name, field->number(), field_name);
                 hasDefaultFlags[i] = false;
                 break;
             case FieldDescriptor::TYPE_STRING:
                 if (isDefaultDest(field) && p.patterns_size() == 0) break;
 
-                printf("static const char* %s_patterns[] = {\n", field_name);
+                printf("const char* %s_patterns[] = {\n", field_name);
                 for (int i=0; i<p.patterns_size(); i++) {
                     // the generated string need to escape backslash as well, need to dup it here
                     printf("    \"%s\",\n", replaceAll(p.patterns(i), '\\', "\\\\").c_str());
                 }
                 printf("    NULL };\n");
-                printf("static Privacy %s = { %d, %d, %d, %s_patterns };\n", field_name, field->number(),
-                        (int) field->type(), p.dest(), field_name);
+                printf("Privacy %s(%d, %d, %s_patterns);\n", field_name, field->number(), p.dest(), field_name);
                 hasDefaultFlags[i] = false;
                 break;
             default:
                 if (isDefaultDest(field)) break;
-                printf("static Privacy %s = { %d, %d, %d };\n", field_name, field->number(),
-                        (int) field->type(), p.dest());
+                printf("Privacy %s(%d, %d, %d);\n", field_name, field->number(), (int) field->type(), p.dest());
                 hasDefaultFlags[i] = false;
         }
         // add the field name to message map, true means it has default flags
@@ -213,20 +210,6 @@
     printf("    NULL };\n");
     emptyline();
 
-    // generates DESTINATION enum values
-    EnumDescriptor const* destination = Destination_descriptor();
-    for (int i=0; i<destination->value_count(); i++) {
-        EnumValueDescriptor const* val = destination->value(i);
-        printf("const uint8_t %s = %d;\n", val->name().c_str(), val->number());
-    }
-    emptyline();
-    printf("const uint8_t DEST_DEFAULT_VALUE = %d;\n", PrivacyFlags::default_instance().dest());
-    emptyline();
-    // populates string type and message type values
-    printf("const uint8_t TYPE_STRING = %d;\n", (int) FieldDescriptor::TYPE_STRING);
-    printf("const uint8_t TYPE_MESSAGE = %d;\n", (int) FieldDescriptor::TYPE_MESSAGE);
-    emptyline();
-
     // generates PRIVACY_POLICY
     map<string, bool> messageNames;
     if (generatePrivacyFlags(descriptor, "PRIVACY_POLICY", messageNames)) {