Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ else if(field.getType().equals("DayOfMonth")) {
}
else if(field.getType().equals("float")) {
protoField.name = getFieldName(fieldRef);
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
Expand All @@ -411,19 +411,19 @@ else if(field.getType().equals("Price")) {
}
else if(field.getType().equals("PriceOffset")) {
protoField.name = getFieldName(fieldRef);
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
else if(field.getType().equals("Amt")) {
protoField.name = getFieldName(fieldRef);
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
else if(field.getType().equals("Percentage")) {
protoField.name = getFieldName(fieldRef);
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import io.fixprotocol._2020.orchestra.repository.CodeSetType;
import io.fixprotocol._2020.orchestra.repository.CodeSets;
import io.fixprotocol._2020.orchestra.repository.CodeType;
Expand Down Expand Up @@ -91,6 +92,8 @@ protected ProtobufModel buildProtobufModel() {
ext.addField(new ExtensionField("Datatype", "type", 50010));
ext.addField(new ExtensionField("TimeUnitFieldOption", "time_unit", 50011));
ext.addField(new ExtensionField("EpochFieldOption", "epoch", 50012));
ext.addField(new ExtensionField(ScalarType.STRING, "abbr_name", 50013));
ext.addField(new ExtensionField(ScalarType.STRING, "base_abbr_name", 50014));
ext.homePackage = "extended-gpb-options";
protoSchema.extensions.add(ext);

Expand All @@ -110,6 +113,8 @@ protected ProtobufModel buildProtobufModel() {
ext.addField(new ExtensionField("Version", "field_deprecated", 50004));
ext.addField(new ExtensionField(ScalarType.FIXED32, "group_tag", 50009));
ext.addField(new ExtensionField("Datatype", "type", 50010));
ext.addField(new ExtensionField(ScalarType.STRING, "abbr_name", 50011));
ext.addField(new ExtensionField(ScalarType.STRING, "base_abbr_name", 50012));
ext.homePackage = "fix";
protoSchema.extensions.add(ext);

Expand Down Expand Up @@ -192,6 +197,25 @@ protected ProtobufModel buildProtobufModel() {

return protoSchema;
}

private boolean containsName(final List<EnumField> list, final String name) {
return list.stream().anyMatch(o -> Objects.equals(o.fieldName, name));
}

private List<EnumField> addEnumVal(final List<EnumField> list, final String name, final String s) {
// This function adds additional enum values to already existing fields for the case of when a proto can be one of multiple values
list.stream().filter(o -> Objects.equals(o.fieldName, name)).forEach(
o -> {
o.fieldOptions.stream().filter(a -> Objects.equals(a.name, "enum_value")).forEach(
a -> {
a.value += "," + s;
}
);
}
);

return list;
}

private Enum buildEnum(CodeSetType codeSet) {
Enum protoEnum = new Enum();
Expand Down Expand Up @@ -232,9 +256,16 @@ private Enum buildEnum(CodeSetType codeSet) {
}
if(codeType.getValue() != null) {
String s = codeType.getValue();
f.fieldOptions.add(new Option("enum_value", s, Option.ValueType.QUOTED_STRING));
// check if already added -- append to enum value if so
if(containsName(fields, f.fieldName)) {
fields = addEnumVal(fields, f.fieldName, s);
} else {
f.fieldOptions.add(new Option("enum_value", s, Option.ValueType.QUOTED_STRING));
}
}
if (!containsName(fields, f.fieldName)) {
fields.add(f);
}
fields.add(f);
}
FieldComparator fieldComparator = new FieldComparator(FieldComparator.SortOrder.NONE);
Collections.sort(fields, fieldComparator);
Expand Down Expand Up @@ -339,6 +370,9 @@ private MessageField buildField(GroupRefType groupRef) {
String s = numInGroup.getId().toString();
protoField.fieldOptions.add(new Option("group_tag", s, Option.ValueType.NUMERIC));
}
if (group.getAbbrName() != null) {
protoField.fieldOptions.add(new Option("abbr_name", group.getAbbrName(), Option.ValueType.QUOTED_STRING));
}
return protoField;
}

Expand All @@ -365,6 +399,9 @@ private MessageField buildField(ComponentRefType componentRef) {
String s = toVersionFieldName(componentRef.getDeprecated());
protoField.fieldOptions.add(new Option("field_deprecated", s, Option.ValueType.ENUM_LITERAL));
}
if(component.getAbbrName() != null) {
protoField.fieldOptions.add(new Option("abbr_name", component.getAbbrName(), Option.ValueType.QUOTED_STRING));
}
return protoField;
}

Expand Down Expand Up @@ -431,7 +468,7 @@ else if(field.getType().equals("DayOfMonth")) {
}
else if(field.getType().equals("float")) {
protoField.fieldName = toProtoFieldName(getFieldName(fieldRef));
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
Expand All @@ -449,19 +486,19 @@ else if(field.getType().equals("Price")) {
}
else if(field.getType().equals("PriceOffset")) {
protoField.fieldName = toProtoFieldName(getFieldName(fieldRef));
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
else if(field.getType().equals("Amt")) {
protoField.fieldName = toProtoFieldName(getFieldName(fieldRef));
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
else if(field.getType().equals("Percentage")) {
protoField.fieldName = toProtoFieldName(getFieldName(fieldRef));
protoField.typeName = "Decimal32"; // this will depend on enc attrs
protoField.typeName = "Decimal64"; // this will depend on enc attrs
protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg;
protoField.isRepeating = false;
}
Expand Down Expand Up @@ -633,6 +670,12 @@ else if(field.getType().equals("XIDRef")) {
String s = fieldRef.getId().toString();
protoField.fieldOptions.add(new Option("tag", s, Option.ValueType.NUMERIC));
}
if (field.getAbbrName() != null) {
protoField.fieldOptions.add(new Option("abbr_name", field.getAbbrName(), Option.ValueType.QUOTED_STRING));
}
if (field.getBaseCategoryAbbrName() != null) {
protoField.fieldOptions.add(new Option("base_abbr_name", field.getBaseCategoryAbbrName(), Option.ValueType.QUOTED_STRING));
}
return protoField;
}

Expand Down Expand Up @@ -693,6 +736,12 @@ else if(unionType == UnionDataTypeT.TENOR) {
String s = fieldRef.getId().toString();
protoField.fieldOptions.add(new Option("tag", s, Option.ValueType.NUMERIC));
}
if (field.getAbbrName() != null) {
protoField.fieldOptions.add(new Option("abbr_name", field.getAbbrName(), Option.ValueType.QUOTED_STRING));
}
if (field.getBaseCategoryAbbrName() != null) {
protoField.fieldOptions.add(new Option("base_abbr_name", field.getBaseCategoryAbbrName(), Option.ValueType.QUOTED_STRING));
}
}
else {
logger.info("Alternate union data type " + unionType.name() + " is not supported.");
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/io/fixprotocol/orchestra2proto/capnp/CapnpModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class CapnpModel implements IModel {
public List<Message> messages;
public List<AnnotationDecl> annotationDecls;
private final String fileSfx = ".capnp";

private final String fix = "fix/";

public CapnpModel(String repoName) {
this.repoName = repoName;
Expand Down Expand Up @@ -101,8 +103,8 @@ class ProtoFile {
if(!itemPkg.equals(msg.homePackage)) {
String itemFileName = itemPkg.toLowerCase() + fileSfx;
String itemName = "\"" + itemFileName + "\"" + "." + msgRefName;
if(!f.requiredImports.contains(itemName))
f.requiredImports.add(itemName);
if(!f.requiredImports.contains(fix + itemName))
f.requiredImports.add(fix + itemName);
}
}
}
Expand All @@ -115,8 +117,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
if(!itemPkg.equals(msg.homePackage)) {
String itemFileName = itemPkg.toLowerCase() + fileSfx;
String itemName = "\"" + itemFileName + "\"" + "." + enumRefName;
if(!f.requiredImports.contains(itemName))
f.requiredImports.add(itemName);
if(!f.requiredImports.contains(fix + itemName))
f.requiredImports.add(fix + itemName);
}
}
}
Expand All @@ -131,8 +133,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
if(!annDecl.homePackage.equals(msg.homePackage)) {
String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx;
String itemName = "\"" + itemFileName + "\"" + "." + ann.name;
if(!f.requiredImports.contains(itemName))
f.requiredImports.add(itemName);
if(!f.requiredImports.contains(fix + itemName))
f.requiredImports.add(fix + itemName);
}
}
}
Expand All @@ -149,8 +151,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
if(!annDecl.homePackage.equals(msg.homePackage)) {
String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx;
String itemName = "\"" + itemFileName + "\"" + "." + ann.name;
if(!f.requiredImports.contains(itemName))
f.requiredImports.add(itemName);
if(!f.requiredImports.contains(fix + itemName))
f.requiredImports.add(fix + itemName);
}
}
}
Expand Down Expand Up @@ -183,8 +185,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
if(!annDecl.homePackage.equals(e.homePackage)) {
String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx;
String itemName = "\"" + itemFileName + "\"" + "." + ann.name;
if(!f.requiredImports.contains(itemName))
f.requiredImports.add(itemName);
if(!f.requiredImports.contains(fix + itemName))
f.requiredImports.add(fix + itemName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public enum Syntax {
public List<Extension> extensions; // Extension defined at the global scope. Primary use is to facilitate custom fieldOptions.

//public String packageName; // we should set this equal to repoName


private final String fix = "fix/";

public ProtobufModel(String repoName, Syntax syntax) {
this.syntax = syntax;
this.repoName = repoName;
Expand Down Expand Up @@ -140,8 +142,8 @@ class ProtoFile {
String itemPkg = item.homePackage;
if(!itemPkg.equals(msg.homePackage)) {
String itemFileName = itemPkg.toLowerCase() + ".proto";
if(!f.requiredImports.contains(itemFileName))
f.requiredImports.add(itemFileName);
if(!f.requiredImports.contains(fix + itemFileName))
f.requiredImports.add(fix + itemFileName);
}
}
}
Expand All @@ -153,8 +155,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
String itemPkg = item.homePackage;
if(!itemPkg.equals(msg.homePackage)) {
String itemFileName = itemPkg.toLowerCase() + ".proto";
if(!f.requiredImports.contains(itemFileName))
f.requiredImports.add(itemFileName);
if(!f.requiredImports.contains(fix + itemFileName))
f.requiredImports.add(fix + itemFileName);
}
}
}
Expand All @@ -171,8 +173,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
String efPkg = ext.homePackage;
if(!efPkg.equals(msg.homePackage)) {
String itemFileName = efPkg.toLowerCase() + ".proto";
if(!f.requiredImports.contains(itemFileName))
f.requiredImports.add(itemFileName);
if(!f.requiredImports.contains(fix + itemFileName))
f.requiredImports.add(fix + itemFileName);
}
}
}
Expand Down Expand Up @@ -205,8 +207,8 @@ else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) {
String efPkg = ext.homePackage;
if(!efPkg.equals(e.homePackage)) {
String itemFileName = efPkg.toLowerCase() + ".proto";
if(!f.requiredImports.contains(itemFileName))
f.requiredImports.add(itemFileName);
if(!f.requiredImports.contains(fix + itemFileName))
f.requiredImports.add(fix + itemFileName);
}
}
}
Expand Down