Skip to content

Commit

Permalink
Adding more logging and exceptions to ProtoUtil.
Browse files Browse the repository at this point in the history
  • Loading branch information
Craigacp committed May 25, 2022
1 parent 32a4a01 commit c24d4d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Core/src/main/java/org/tribuo/protos/ProtoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* Utilities for working with Tribuo protobufs.
*/
public final class ProtoUtil {
private static final Logger logger = Logger.getLogger(ProtoUtil.class.getName());

/**
* Used to provide internal Tribuo redirects as classes are redefined.
Expand Down Expand Up @@ -263,8 +265,10 @@ private static Object convert(Object obj) {
return Arrays.stream(t).boxed().collect(Collectors.toList());
} else if (obj instanceof String[]) {
return Arrays.asList((String[]) obj);
} else {
} else if (obj instanceof Double || obj instanceof Float || obj instanceof Byte || obj instanceof Short || obj instanceof Character || obj instanceof Integer || obj instanceof Long || obj instanceof Boolean || obj instanceof String) {
return obj;
} else {
throw new IllegalArgumentException("Invalid protobuf field type " + obj.getClass());
}
}

Expand All @@ -290,6 +294,8 @@ private static void getFields(Class<?> clazz, Set<String> fieldNameSet, List<Fie
if (!fieldNameSet.contains(protoFieldName)) {
fields.add(field);
fieldNameSet.add(field.getName());
} else {
logger.warning("Duplicate field named " + protoFieldName + " detected in class " + clazz);
}
} else if ((psf == null) && (pskvf != null) && (psmvf == null)) {
String keyName = pskvf.keysName();
Expand Down
3 changes: 2 additions & 1 deletion Core/src/main/resources/protos/tribuo-core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import "google/protobuf/any.proto";
import "olcut_proto.proto";

/*
Base model protobuf. Contains the core model fields, along with an Any containing model specific information.
Base model protobuf. Contains the core model fields, along with the ModelDataProto
containing model specific information.
*/
message ModelProto {
/*
Expand Down

0 comments on commit c24d4d2

Please sign in to comment.