Skip to content

Commit

Permalink
Cast to Void STRUCT_NULL.decode
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Jul 12, 2020
1 parent 25fa80c commit e249e0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ private MethodSpec messageAdapterDecode(NameAllocator nameAllocator, MessageType
for (Field field : fields) {
int fieldTag = field.getTag();

if (isEnum(field.getType())) {
if (isEnum(field.getType()) && !field.getType().equals(ProtoType.STRUCT_NULL)) {
result.beginControlFlow("case $L:", fieldTag);
result.beginControlFlow("try");
result.addCode(decodeAndAssign(field, nameAllocator, useBuilder));
Expand Down Expand Up @@ -1056,15 +1056,19 @@ private CodeBlock decodeAndAssign(Field field, NameAllocator nameAllocator, bool
CodeBlock decode = CodeBlock.of("$L.decode(reader)", singleAdapterFor(field, nameAllocator));
if (field.isRepeated()) {
return useBuilder
? CodeBlock.of("builder.$L.add($L)", fieldName, decode)
? field.getType().equals(ProtoType.STRUCT_NULL)
? CodeBlock.of("builder.$L.add(($T) $L)", fieldName, Void.class, decode)
: CodeBlock.of("builder.$L.add($L)", fieldName, decode)
: CodeBlock.of("$L.add($L)", fieldName, decode);
} else if (field.getType().isMap()) {
return useBuilder
? CodeBlock.of("builder.$L.putAll($L)", fieldName, decode)
: CodeBlock.of("$L.putAll($L)", fieldName, decode);
} else {
return useBuilder
? CodeBlock.of("builder.$L($L)", fieldName, decode)
? field.getType().equals(ProtoType.STRUCT_NULL)
? CodeBlock.of("builder.$L(($T) $L)", fieldName, Void.class, decode)
: CodeBlock.of("builder.$L($L)", fieldName, decode)
: CodeBlock.of("$L = $L", fieldName, decode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2400,14 +2400,7 @@ public AllTypes decode(ProtoReader reader) throws IOException {
case 20: builder.struct(ProtoAdapter.STRUCT_MAP.decode(reader)); break;
case 21: builder.list_value(ProtoAdapter.STRUCT_LIST.decode(reader)); break;
case 22: builder.value(ProtoAdapter.STRUCT_VALUE.decode(reader)); break;
case 23: {
try {
builder.null_value(ProtoAdapter.STRUCT_NULL.decode(reader));
} catch (ProtoAdapter.EnumConstantNotFoundException e) {
builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
}
break;
}
case 23: builder.null_value((Void) ProtoAdapter.STRUCT_NULL.decode(reader)); break;
case 24: builder.empty(ProtoAdapter.EMPTY.decode(reader)); break;
case 25: builder.timestamp(ProtoAdapter.INSTANT.decode(reader)); break;
case 201: builder.rep_int32.add(ProtoAdapter.INT32.decode(reader)); break;
Expand Down Expand Up @@ -2439,14 +2432,7 @@ public AllTypes decode(ProtoReader reader) throws IOException {
case 220: builder.rep_struct.add(ProtoAdapter.STRUCT_MAP.decode(reader)); break;
case 221: builder.rep_list_value.add(ProtoAdapter.STRUCT_LIST.decode(reader)); break;
case 222: builder.rep_value.add(ProtoAdapter.STRUCT_VALUE.decode(reader)); break;
case 223: {
try {
builder.rep_null_value.add(ProtoAdapter.STRUCT_NULL.decode(reader));
} catch (ProtoAdapter.EnumConstantNotFoundException e) {
builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
}
break;
}
case 223: builder.rep_null_value.add((Void) ProtoAdapter.STRUCT_NULL.decode(reader)); break;
case 224: builder.rep_empty.add(ProtoAdapter.EMPTY.decode(reader)); break;
case 225: builder.rep_timestamp.add(ProtoAdapter.INSTANT.decode(reader)); break;
case 301: builder.pack_int32.add(ProtoAdapter.INT32.decode(reader)); break;
Expand All @@ -2470,14 +2456,7 @@ public AllTypes decode(ProtoReader reader) throws IOException {
}
break;
}
case 323: {
try {
builder.pack_null_value.add(ProtoAdapter.STRUCT_NULL.decode(reader));
} catch (ProtoAdapter.EnumConstantNotFoundException e) {
builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
}
break;
}
case 323: builder.pack_null_value.add((Void) ProtoAdapter.STRUCT_NULL.decode(reader)); break;
case 501: builder.map_int32_int32.putAll(map_int32_int32Adapter().decode(reader)); break;
case 502: builder.map_string_string.putAll(map_string_stringAdapter().decode(reader)); break;
case 503: builder.map_string_message.putAll(map_string_messageAdapter().decode(reader)); break;
Expand Down

0 comments on commit e249e0f

Please sign in to comment.