Skip to content

Commit

Permalink
Fix reading of proto Uint32Value
Browse files Browse the repository at this point in the history
  • Loading branch information
aandres3 committed Jan 6, 2025
1 parent a3bfbcd commit eccd877
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,13 @@ public ProtoUInt32ValueConverter(ParentValueContainer parent) {
this.parent = parent;
}


@Override
public void addInt(int value) {
parent.add(UInt32Value.of(value));
}

// This is left for backward compatibility with the old implementation which used int64 for uint32
@Override
public void addLong(long value) {
parent.add(UInt32Value.of(Math.toIntExact(value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private <T> Builder<? extends Builder<?, GroupBuilder<T>>, GroupBuilder<T>> addF
return builder.primitive(INT32, getRepetition(descriptor));
}
if (messageType.equals(UInt32Value.getDescriptor())) {
return builder.primitive(INT64, getRepetition(descriptor));
return builder.primitive(INT32, getRepetition(descriptor));
}
if (messageType.equals(BytesValue.getDescriptor())) {
return builder.primitive(BINARY, getRepetition(descriptor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ void writeRawValue(Object value) {
class UInt32ValueWriter extends FieldWriter {
@Override
void writeRawValue(Object value) {
recordConsumer.addLong(((UInt32Value) value).getValue());
recordConsumer.addInteger(((UInt32Value) value).getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public void testProto3ConvertWrappedMessageUnwrapped() throws Exception {
+ " optional int64 wrappedInt64 = 3;\n"
+ " optional int64 wrappedUInt64 = 4;\n"
+ " optional int32 wrappedInt32 = 5;\n"
+ " optional int64 wrappedUInt32 = 6;\n"
+ " optional int32 wrappedUInt32 = 6;\n"
+ " optional boolean wrappedBool = 7;\n"
+ " optional binary wrappedString (UTF8) = 8;\n"
+ " optional binary wrappedBytes = 9;\n"
Expand Down

0 comments on commit eccd877

Please sign in to comment.