Skip to content
Permalink
Browse files

Down integrate to GitHub

  • Loading branch information...
Hao Nguyen
Hao Nguyen committed May 21, 2019
1 parent fcfc47d commit 88339fa7f87e5e8fe29eef3ff4df02c7d841317d
@@ -18,7 +18,7 @@ def __get_data_size(filename):
return __file_size_map[filename]
benchmark_dataset = benchmarks_pb2.BenchmarkDataset()
benchmark_dataset.ParseFromString(
open(filename).read())
open(filename, "rb").read())
size = 0
count = 0
for payload in benchmark_dataset.payload:
@@ -60,7 +60,7 @@ def __parse_cpp_result(filename):
return
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename) as f:
with open(filename, "rb") as f:
results = json.loads(f.read())
for benchmark in results["benchmarks"]:
data_filename = "".join(
@@ -95,7 +95,7 @@ def __parse_synthetic_result(filename):
return
if filename[0] != "/":
filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename
with open(filename) as f:
with open(filename, "rb") as f:
results = json.loads(f.read())
for benchmark in results["benchmarks"]:
__results.append({
@@ -125,7 +125,7 @@ def __parse_python_result(filename):
return
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename) as f:
with open(filename, "rb") as f:
results_list = json.loads(f.read())
for results in results_list:
for result in results:
@@ -175,7 +175,7 @@ def __parse_java_result(filename):
return
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename) as f:
with open(filename, "rb") as f:
results = json.loads(f.read())
for result in results:
total_weight = 0
@@ -211,7 +211,7 @@ def __parse_go_result(filename):
return
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename) as f:
with open(filename, "rb") as f:
for line in f:
result_list = re.split(r"[\ \t]+", line)
if result_list[0][:9] != "Benchmark":
@@ -251,7 +251,7 @@ def __parse_custom_result(filename, language):
return
if filename[0] != '/':
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
with open(filename) as f:
with open(filename, "rb") as f:
results = json.loads(f.read())
for result in results:
_, avg_size = __get_data_size(result["filename"])
@@ -51,6 +51,7 @@
BuilderType extends AbstractMessageLite.Builder<MessageType, BuilderType>>
implements MessageLite {
protected int memoizedHashCode = 0;

@Override
public ByteString toByteString() {
try {
@@ -106,16 +107,6 @@ void setMemoizedSerializedSize(int size) {
}


@ExperimentalApi
protected final boolean isInitializedInternal() {
return Protobuf.getInstance().schemaFor(this).isInitialized(this);
}

@ExperimentalApi
protected final int getSerializedSizeInternal() {
return Protobuf.getInstance().schemaFor(this).getSerializedSize(this);
}

int getSerializedSize(Schema schema) {
int memoizedSerializedSize = getMemoizedSerializedSize();
if (memoizedSerializedSize == -1) {
@@ -125,37 +116,6 @@ int getSerializedSize(Schema schema) {
return memoizedSerializedSize;
}

@ExperimentalApi
protected final void writeToInternal(CodedOutputStream output) throws IOException {
Protobuf.getInstance()
.schemaFor(getClassInternal())
.writeTo(this, CodedOutputStreamWriter.forCodedOutput(output));
}

@ExperimentalApi
protected void mergeFromInternal(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
try {
Protobuf.getInstance()
.schemaFor(getClassInternal())
.mergeFrom(this, CodedInputStreamReader.forCodedInput(input), extensionRegistry);
} catch (InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (IOException e) {
throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this);
}
}

@ExperimentalApi
protected void makeImmutableInternal() {
Protobuf.getInstance().schemaFor(getClassInternal()).makeImmutable(this);
}

@SuppressWarnings("unchecked")
private Class<AbstractMessageLite<MessageType, BuilderType>> getClassInternal() {
return (Class<AbstractMessageLite<MessageType, BuilderType>>) getClass();
}

/** Package private helper method for AbstractParser to create UninitializedMessageException. */
UninitializedMessageException newUninitializedMessageException() {
return new UninitializedMessageException(this);
@@ -262,12 +262,14 @@ void setMemoizedSerializedSize(int size) {
}

public void writeTo(CodedOutputStream output) throws IOException {
writeToInternal(output);
Protobuf.getInstance()
.schemaFor(this)
.writeTo(this, CodedOutputStreamWriter.forCodedOutput(output));
}

public int getSerializedSize() {
if (memoizedSerializedSize == -1) {
memoizedSerializedSize = getSerializedSizeInternal();
memoizedSerializedSize = Protobuf.getInstance().schemaFor(this).getSerializedSize(this);
}
return memoizedSerializedSize;
}
@@ -126,6 +126,21 @@ public Descriptor getDescriptorForType() {
return internalGetFieldAccessorTable().descriptor;
}

protected void mergeFromAndMakeImmutableInternal(
CodedInputStream input, ExtensionRegistryLite extensionRegistry)
throws InvalidProtocolBufferException {
Schema<GeneratedMessageV3> schema =
(Schema<GeneratedMessageV3>) Protobuf.getInstance().schemaFor(this);
try {
schema.mergeFrom(this, CodedInputStreamReader.forCodedInput(input), extensionRegistry);
} catch (InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (IOException e) {
throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this);
}
schema.makeImmutable(this);
}

/**
* Internal helper to return a modifiable map containing all the fields.
* The returned Map is modifialbe so that the caller can add additional
@@ -439,6 +454,7 @@ protected static BooleanList mutableCopy(BooleanList list) {
size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
}


@Override
public void writeTo(final CodedOutputStream output) throws IOException {
MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false);
@@ -99,7 +99,7 @@ public void testLite() throws Exception {
TestAllTypesLite.newBuilder()
.setOptionalInt32(123)
.addRepeatedString("hello")
.setOptionalNestedMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
.setOptionalNestedMessage(NestedMessage.newBuilder().setBb(7))
.build();

ByteString data = message.toByteString();
@@ -135,11 +135,10 @@ public void testLiteExtensions() throws Exception {
TestAllExtensionsLite.newBuilder()
.setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
.addExtension(UnittestLite.repeatedStringExtensionLite, "hello")
.setExtension(
UnittestLite.optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ)
.setExtension(UnittestLite.optionalNestedEnumExtensionLite, NestedEnum.BAZ)
.setExtension(
UnittestLite.optionalNestedMessageExtensionLite,
TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
NestedMessage.newBuilder().setBb(7).build())
.build();

// Test copying a message, since coping extensions actually does use a
@@ -152,8 +151,7 @@ public void testLiteExtensions() throws Exception {
assertEquals(1, message2.getExtension(UnittestLite.repeatedStringExtensionLite).size());
assertEquals("hello", message2.getExtension(UnittestLite.repeatedStringExtensionLite, 0));
assertEquals(
TestAllTypesLite.NestedEnum.BAZ,
message2.getExtension(UnittestLite.optionalNestedEnumExtensionLite));
NestedEnum.BAZ, message2.getExtension(UnittestLite.optionalNestedEnumExtensionLite));
assertEquals(7, message2.getExtension(UnittestLite.optionalNestedMessageExtensionLite).getBb());
}

@@ -1377,14 +1375,16 @@ public void testToStringPrimitives() throws Exception {
proto =
TestAllTypesLite.newBuilder()
.setOptionalBool(true)
.setOptionalNestedEnum(TestAllTypesLite.NestedEnum.BAZ)
.setOptionalNestedEnum(NestedEnum.BAZ)
.build();
assertToStringEquals("optional_bool: true\noptional_nested_enum: BAZ", proto);
assertToStringEquals(
"optional_bool: true\noptional_nested_enum: " + NestedEnum.BAZ.toString(), proto);

proto = TestAllTypesLite.newBuilder().setOptionalFloat(2.72f).setOptionalDouble(3.14).build();
assertToStringEquals("optional_double: 3.14\noptional_float: 2.72", proto);
}


public void testToStringStringFields() throws Exception {
TestAllTypesLite proto =
TestAllTypesLite.newBuilder().setOptionalString("foo\"bar\nbaz\\").build();
@@ -1397,13 +1397,13 @@ public void testToStringStringFields() throws Exception {
public void testToStringNestedMessage() throws Exception {
TestAllTypesLite proto =
TestAllTypesLite.newBuilder()
.setOptionalNestedMessage(TestAllTypesLite.NestedMessage.getDefaultInstance())
.setOptionalNestedMessage(NestedMessage.getDefaultInstance())
.build();
assertToStringEquals("optional_nested_message {\n}", proto);

proto =
TestAllTypesLite.newBuilder()
.setOptionalNestedMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
.setOptionalNestedMessage(NestedMessage.newBuilder().setBb(7))
.build();
assertToStringEquals("optional_nested_message {\n bb: 7\n}", proto);
}
@@ -1419,8 +1419,8 @@ public void testToStringRepeatedFields() throws Exception {

proto =
TestAllTypesLite.newBuilder()
.addRepeatedLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
.addRepeatedLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(8))
.addRepeatedLazyMessage(NestedMessage.newBuilder().setBb(7))
.addRepeatedLazyMessage(NestedMessage.newBuilder().setBb(8))
.build();
assertToStringEquals(
"repeated_lazy_message {\n bb: 7\n}\nrepeated_lazy_message {\n bb: 8\n}", proto);
@@ -1433,7 +1433,10 @@ public void testToStringForeignFields() throws Exception {
.setOptionalForeignMessage(ForeignMessageLite.newBuilder().setC(3))
.build();
assertToStringEquals(
"optional_foreign_enum: FOREIGN_LITE_BAR\noptional_foreign_message {\n c: 3\n}", proto);
"optional_foreign_enum: "
+ ForeignEnumLite.FOREIGN_LITE_BAR
+ "\noptional_foreign_message {\n c: 3\n}",
proto);
}

public void testToStringExtensions() throws Exception {
@@ -1442,11 +1445,10 @@ public void testToStringExtensions() throws Exception {
.setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
.addExtension(UnittestLite.repeatedStringExtensionLite, "spam")
.addExtension(UnittestLite.repeatedStringExtensionLite, "eggs")
.setExtension(
UnittestLite.optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ)
.setExtension(UnittestLite.optionalNestedEnumExtensionLite, NestedEnum.BAZ)
.setExtension(
UnittestLite.optionalNestedMessageExtensionLite,
TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
NestedMessage.newBuilder().setBb(7).build())
.build();
assertToStringEquals(
"[1]: 123\n[18] {\n bb: 7\n}\n[21]: 3\n[44]: \"spam\"\n[44]: \"eggs\"", message);
@@ -1458,11 +1460,10 @@ public void testToStringUnknownFields() throws Exception {
.setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
.addExtension(UnittestLite.repeatedStringExtensionLite, "spam")
.addExtension(UnittestLite.repeatedStringExtensionLite, "eggs")
.setExtension(
UnittestLite.optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ)
.setExtension(UnittestLite.optionalNestedEnumExtensionLite, NestedEnum.BAZ)
.setExtension(
UnittestLite.optionalNestedMessageExtensionLite,
TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
NestedMessage.newBuilder().setBb(7).build())
.build();
TestAllExtensionsLite messageWithUnknownFields =
TestAllExtensionsLite.parseFrom(messageWithExtensions.toByteArray());
@@ -1611,13 +1612,12 @@ public void testMergeFrom_sanity() throws Exception {

public void testMergeFromNoLazyFieldSharing() throws Exception {
TestAllTypesLite.Builder sourceBuilder =
TestAllTypesLite.newBuilder()
.setOptionalLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(1));
TestAllTypesLite.newBuilder().setOptionalLazyMessage(NestedMessage.newBuilder().setBb(1));
TestAllTypesLite.Builder targetBuilder =
TestAllTypesLite.newBuilder().mergeFrom(sourceBuilder.build());
assertEquals(1, sourceBuilder.getOptionalLazyMessage().getBb());
// now change the sourceBuilder, and target value shouldn't be affected.
sourceBuilder.setOptionalLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(2));
sourceBuilder.setOptionalLazyMessage(NestedMessage.newBuilder().setBb(2));
assertEquals(1, targetBuilder.getOptionalLazyMessage().getBb());
}

@@ -2115,7 +2115,7 @@ public void testParseFromByteBuffer() throws Exception {
TestAllTypesLite.newBuilder()
.setOptionalInt32(123)
.addRepeatedString("hello")
.setOptionalNestedMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
.setOptionalNestedMessage(NestedMessage.newBuilder().setBb(7))
.build();

TestAllTypesLite copy =
@@ -2150,11 +2150,10 @@ public void testParseFromByteBuffer_extensions() throws Exception {
TestAllExtensionsLite.newBuilder()
.setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
.addExtension(UnittestLite.repeatedStringExtensionLite, "hello")
.setExtension(
UnittestLite.optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ)
.setExtension(UnittestLite.optionalNestedEnumExtensionLite, NestedEnum.BAZ)
.setExtension(
UnittestLite.optionalNestedMessageExtensionLite,
TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
NestedMessage.newBuilder().setBb(7).build())
.build();

ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance();
@@ -3731,7 +3731,12 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
options.GetFileNameExtension();
std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_CHECK(output.get());
io::Printer printer(output.get(), '$');
GeneratedCodeInfo annotations;
io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
&annotations);
io::Printer printer(
output.get(), '$',
options.annotate_code ? &annotation_collector : nullptr);

// Pull out all extensions -- we need these to generate all
// provides/requires.
@@ -3763,6 +3768,9 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
if (printer.failed()) {
return false;
}
if (options.annotate_code) {
EmbedCodeAnnotations(annotations, &printer);
}
} else if (options.output_mode() == GeneratorOptions::kOneOutputFilePerSCC) {
std::set<const Descriptor*> have_printed;
SCCAnalyzer<DepsGenerator> analyzer;
@@ -101,8 +101,8 @@ message DescriptorProto {
repeated EnumDescriptorProto enum_type = 4;

message ExtensionRange {
optional int32 start = 1;
optional int32 end = 2;
optional int32 start = 1; // Inclusive.
optional int32 end = 2; // Exclusive.

optional ExtensionRangeOptions options = 3;
}
@@ -246,6 +246,9 @@ class PROTOBUF_EXPORT MessageLite {
// assume it will remain stable over time.
std::string DebugString() const;
std::string ShortDebugString() const { return DebugString(); }
// MessageLite::DebugString is already Utf8 Safe. This is to add compatibility
// with Message.
std::string Utf8DebugString() const { return DebugString(); }

// Parsing ---------------------------------------------------------
// Methods for parsing in protocol buffer format. Most of these are

0 comments on commit 88339fa

Please sign in to comment.
You can’t perform that action at this time.