Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
change GeneratedMessage to GeneratedMessageV3
Browse files Browse the repository at this point in the history
The proto3 compiler generates slightly different classes, so we must use
GeneratedMessageV3 instead.
  • Loading branch information
berler committed Jan 19, 2018
1 parent d52b578 commit afb5b13
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.googlecode.protobuf.format.JsonFormat;
Expand Down Expand Up @@ -125,11 +125,11 @@ public static ColumnValueDescription forPersister(Class<? extends Persister<?>>
return new ColumnValueDescription(Format.PERSISTER, clazz.getName(), clazz.getCanonicalName(), compression, null);
}

public static ColumnValueDescription forProtoMessage(Class<? extends GeneratedMessage> clazz) {
public static ColumnValueDescription forProtoMessage(Class<? extends GeneratedMessageV3> clazz) {
return forProtoMessage(clazz, Compression.NONE);
}

public static ColumnValueDescription forProtoMessage(Class<? extends GeneratedMessage> clazz,
public static ColumnValueDescription forProtoMessage(Class<? extends GeneratedMessageV3> clazz,
Compression compression) {
return new ColumnValueDescription(
Format.PROTO,
Expand All @@ -139,7 +139,7 @@ public static ColumnValueDescription forProtoMessage(Class<? extends GeneratedMe
getDescriptor(clazz));
}

private static <T extends GeneratedMessage> Descriptor getDescriptor(Class<T> clazz) {
private static <T extends GeneratedMessageV3> Descriptor getDescriptor(Class<T> clazz) {
try {
Method method = clazz.getMethod("getDescriptor");
return (Descriptor) method.invoke(null);
Expand Down Expand Up @@ -270,7 +270,7 @@ public byte[] persistJsonToBytes(ClassLoader classLoader, String str) throws Par
throw new IllegalArgumentException("Tried to write json to a Persister that isn't for JsonNode.");
}
} else if (format == Format.PROTO) {
GeneratedMessage.Builder<?> builder = createBuilder(classLoader);
GeneratedMessageV3.Builder<?> builder = createBuilder(classLoader);
// This will have issues with base64 blobs
JsonFormat.merge(str, builder);
bytes = builder.build().toByteArray();
Expand All @@ -280,10 +280,10 @@ public byte[] persistJsonToBytes(ClassLoader classLoader, String str) throws Par
return CompressionUtils.compress(bytes, compression);
}

private GeneratedMessage.Builder<?> createBuilder(ClassLoader classLoader) {
private GeneratedMessageV3.Builder<?> createBuilder(ClassLoader classLoader) {
try {
Method method = getImportClass(classLoader).getMethod("newBuilder");
return (GeneratedMessage.Builder<?>) method.invoke(null);
return (GeneratedMessageV3.Builder<?>) method.invoke(null);
} catch (Exception e) {
throw Throwables.throwUncheckedException(e);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ public Object hydratePersister(ClassLoader classLoader, byte[] value) {
@SuppressWarnings("unchecked")
public Message hydrateProto(ClassLoader classLoader, byte[] value) {
Preconditions.checkState(format == Format.PROTO, "Column value is not a protocol buffer.");
return ColumnValues.parseProtoBuf((Class<? extends GeneratedMessage>) getImportClass(classLoader), CompressionUtils.decompress(value, compression));
return ColumnValues.parseProtoBuf((Class<? extends GeneratedMessageV3>) getImportClass(classLoader), CompressionUtils.decompress(value, compression));
}

public TableMetadataPersistence.ColumnValueDescription.Builder persistToProto() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.palantir.atlasdb.AtlasDbConstants;
import com.palantir.atlasdb.persist.api.Persister;
import com.palantir.atlasdb.protos.generated.TableMetadataPersistence.LogSafety;
Expand Down Expand Up @@ -438,7 +438,7 @@ public ConstraintMetadata getConstraintMetadata() {

@SuppressWarnings({ "rawtypes", "unchecked" })
private ColumnValueDescription getColumnValueDescription(Class protoOrPersistable, Compression compression) {
if (GeneratedMessage.class.isAssignableFrom(protoOrPersistable)) {
if (GeneratedMessageV3.class.isAssignableFrom(protoOrPersistable)) {
return ColumnValueDescription.forProtoMessage(protoOrPersistable, compression);
} else if (Persister.class.isAssignableFrom(protoOrPersistable)) {
return ColumnValueDescription.forPersister(protoOrPersistable, compression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.palantir.atlasdb.keyvalue.api.Cell;
import com.palantir.atlasdb.table.api.ColumnValue;
import com.palantir.common.base.Throwables;
Expand Down Expand Up @@ -76,7 +76,7 @@ public static <T> Function<ColumnValue<T>, T> getValuesFun() {
}

@SuppressWarnings("unchecked")
public static <T extends GeneratedMessage> T parseProtoBuf(Class<T> clazz, byte[] msg) {
public static <T extends GeneratedMessageV3> T parseProtoBuf(Class<T> clazz, byte[] msg) {
try {
Method parseMethod = clazz.getMethod("parseFrom", byte[].class);
return (T) parseMethod.invoke(null, msg);
Expand Down
2 changes: 1 addition & 1 deletion docs/source/schemas/tables_and_indices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ component ordering determines sort ordering for retrieval.
.. code:: java
public void value(ValueType valueType)
public void value(Class<? extends GeneratedMessage> proto, Compression compression = Compression.NONE)
public void value(Class<? extends GeneratedMessageV3> proto, Compression compression = Compression.NONE)
Every dynamic column will also have a value associated with it, which
can be a primitive ValueType or protobuf (optionally compressed).
Expand Down

0 comments on commit afb5b13

Please sign in to comment.