├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── io └── fixprotocol └── orchestra2proto ├── CapnpModelFactory.java ├── CodegenSettings.java ├── FieldComparator.java ├── IModel.java ├── JAXBValidator.java ├── ModelFactory.java ├── ProtoGen.java ├── ProtobufModelFactory.java ├── capnp ├── Annotation.java ├── AnnotationDecl.java ├── CapnpModel.java ├── Enum.java ├── EnumField.java ├── Field.java ├── Message.java ├── MessageField.java ├── ScalarType.java └── package-info.java ├── package-info.java └── protobuf ├── Enum.java ├── EnumField.java ├── Extension.java ├── ExtensionField.java ├── Field.java ├── Message.java ├── MessageField.java ├── Option.java ├── ProtobufModel.java ├── ScalarType.java └── package-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # eclipse, intellij-idea and maven artifacts 26 | .project 27 | .settings 28 | .classpath 29 | target 30 | .idea/ 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fix-orchestra-protobuf 2 | Translators from FIX Orchestra to the protobuf family of serializations. 3 | 4 | ---- 5 | ## Supported Serializations 6 | 7 | * Protocol Buffers ver 2 8 | * Protocol Buffers ver 3 9 | * Cap'n Proto 10 | 11 | Generation of schema files is based on [Encoding FIX using GPB Release Candidate 3](https://www.fixtrading.org/standards/gpb/) specifications. Note that generation of .capnp files is also based on this spec and is done so without much consideration of the differences between the two encodings. I.e. there may be other ways to generate .capnp files to better leverage Cap'n Proto's efficiencies. 12 | 13 | ---- 14 | ## Prerequisites 15 | 16 | * Java bindings for the orchestra XML schema are provided by the [repository2016 module](https://github.com/FIXTradingCommunity/fix-orchestra/tree/master/repository2016). 17 | 18 | ## Build 19 | 20 | The project is built with Maven version 3.0 or later. 21 | 22 | ---- 23 | ## Usage 24 | 25 | java -jar orchestra2proto-jar-with-dependencies.jar [options] *orchestra_file* 26 | 27 | Options: 28 | -altfs Use alternate output file packaging 29 | -help Print this message 30 | -lang Schema language (valid args: proto2 proto3 capnp) 31 | -nosort Maintain repo field ordering 32 | -opath Output directory 33 | -version Print version 34 | 35 | ---- 36 | ## License 37 | 38 | © *2019 FIX Protocol Limited* 39 | 40 | Licensed under the Apache License, Version 2.0 (the "License"); 41 | you may not use this file except in compliance with the License. 42 | You may obtain a copy of the License at 43 | 44 | http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | Unless required by applicable law or agreed to in writing, software 47 | distributed under the License is distributed on an "AS IS" BASIS, 48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | See the License for the specific language governing permissions and 50 | limitations under the License. 51 | 52 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | io.fixprotocol 7 | orchestra2proto 8 | 0.0.1-SNAPSHOT 9 | jar 10 | ${project.groupId}:${project.artifactId} 11 | Translators from FIX Orchestra to the protobuf family of serializations 12 | https://github.com/FIXTradingCommunity/fix-orchestra-protobuf 13 | 2019 14 | 15 | 3.0.5 16 | 17 | 18 | 19 | FIX Trading Community 20 | http://https://www.fixtrading.org/ 21 | 22 | 23 | 24 | The Apache License, Version 2.0 25 | http://www.apache.org/licenses/LICENSE-2.0.txt 26 | 27 | 28 | 29 | 30 | Greg Malatestinic 31 | gmala@jandj.com 32 | FIX Trading Community 33 | https://www.fixtrading.org/ 34 | 35 | 36 | 37 | scm:git:ssh://git@github.com/FIXTradingCommunity/fix-orchestra-protobuf.git 38 | https://github.com/FIXTradingCommunity/fix-orchestra-protobuf 39 | 40 | 41 | GitHub 42 | http://github.com/FIXTradingCommunity/fix-orchestra-protobuf/issues 43 | 44 | 45 | 46 | UTF-8 47 | 1.6.1 48 | 1.4 49 | 2.17.1 50 | 2.3.1 51 | 2.3.0.1 52 | 2.3.2 53 | 3.8.1 54 | 3.2.0 55 | 3.2.0 56 | 57 | 58 | 59 | 60 | io.fixprotocol.orchestra 61 | repository 62 | ${orchestra.version} 63 | 64 | 65 | commons-cli 66 | commons-cli 67 | ${commons-cli.version} 68 | 69 | 70 | org.apache.logging.log4j 71 | log4j-api 72 | ${log4j.version} 73 | 74 | 75 | org.apache.logging.log4j 76 | log4j-core 77 | ${log4j.version} 78 | 79 | 80 | javax.xml.bind 81 | jaxb-api 82 | ${jaxb-api.version} 83 | 84 | 85 | com.sun.xml.bind 86 | jaxb-core 87 | ${jaxb-core.version} 88 | 89 | 90 | com.sun.xml.bind 91 | jaxb-impl 92 | ${jaxb-impl.version} 93 | 94 | 95 | 96 | 97 | 98 | 99 | org.apache.maven.plugins 100 | maven-compiler-plugin 101 | ${maven-compiler-plugin.version} 102 | 103 | 8 104 | 8 105 | -Xlint 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-dependency-plugin 111 | 112 | 113 | copy-dependencies 114 | prepare-package 115 | 116 | copy-dependencies 117 | 118 | 119 | 120 | ${project.build.directory}/libs 121 | 122 | 123 | 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-jar-plugin 129 | ${maven-jar-plugin.version} 130 | 131 | 132 | 133 | true 134 | libs/ 135 | 136 | io.fixprotocol.orchestra2proto.ProtoGen 137 | 138 | 139 | 140 | 141 | 142 | 143 | org.apache.maven.plugins 144 | maven-assembly-plugin 145 | ${maven-assembly-plugin.version} 146 | 147 | 148 | make-assembly 149 | package 150 | 151 | single 152 | 153 | 154 | 155 | 156 | 157 | io.fixprotocol.orchestra2proto.ProtoGen 158 | 159 | 160 | 161 | true 162 | ${project.artifactId} 163 | 164 | jar-with-dependencies 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/CapnpModelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import io.fixprotocol._2020.orchestra.repository.CodeSetType; 22 | import io.fixprotocol._2020.orchestra.repository.CodeSets; 23 | import io.fixprotocol._2020.orchestra.repository.CodeType; 24 | import io.fixprotocol._2020.orchestra.repository.ComponentRefType; 25 | import io.fixprotocol._2020.orchestra.repository.ComponentType; 26 | import io.fixprotocol._2020.orchestra.repository.Components; 27 | import io.fixprotocol._2020.orchestra.repository.FieldRefType; 28 | import io.fixprotocol._2020.orchestra.repository.FieldType; 29 | import io.fixprotocol._2020.orchestra.repository.GroupRefType; 30 | import io.fixprotocol._2020.orchestra.repository.GroupType; 31 | import io.fixprotocol._2020.orchestra.repository.MessageType; 32 | import io.fixprotocol._2020.orchestra.repository.MessageType.Structure; 33 | import io.fixprotocol._2020.orchestra.repository.Messages; 34 | import io.fixprotocol._2020.orchestra.repository.Repository; 35 | import io.fixprotocol._2020.orchestra.repository.UnionDataTypeT; 36 | import io.fixprotocol.orchestra2proto.capnp.Annotation; 37 | import io.fixprotocol.orchestra2proto.capnp.AnnotationDecl; 38 | import io.fixprotocol.orchestra2proto.capnp.CapnpModel; 39 | import io.fixprotocol.orchestra2proto.capnp.Enum; 40 | import io.fixprotocol.orchestra2proto.capnp.EnumField; 41 | import io.fixprotocol.orchestra2proto.capnp.Message; 42 | import io.fixprotocol.orchestra2proto.capnp.MessageField; 43 | import io.fixprotocol.orchestra2proto.capnp.ScalarType; 44 | 45 | public class CapnpModelFactory extends ModelFactory { 46 | 47 | public CapnpModelFactory(Repository repoParam, CodegenSettings appSettingsParam) { 48 | super(repoParam, appSettingsParam); 49 | } 50 | 51 | protected CapnpModel buildModel() { 52 | return buildCapnpModel(); 53 | } 54 | 55 | protected CapnpModel buildCapnpModel() { 56 | 57 | CapnpModel schema = new CapnpModel(repo.getName()); 58 | 59 | /* 60 | * Build the AnnotationDecls 61 | * 62 | */ 63 | AnnotationDecl annDecl = new AnnotationDecl("category", ScalarType.TEXT); 64 | annDecl.addTarget(AnnotationDecl.Target.FILE); 65 | schema.annotationDecls.add(annDecl); 66 | 67 | annDecl = new AnnotationDecl("msgTypeValue", ScalarType.TEXT); 68 | annDecl.addTarget(AnnotationDecl.Target.STRUCT); 69 | schema.annotationDecls.add(annDecl); 70 | 71 | annDecl = new AnnotationDecl("tag", ScalarType.INT32); 72 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 73 | schema.annotationDecls.add(annDecl); 74 | 75 | annDecl = new AnnotationDecl("groupTag", ScalarType.INT32); 76 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 77 | schema.annotationDecls.add(annDecl); 78 | 79 | // Todo: investigate whether we can use "added" instead of "enumAdded". Use "added" for Structs Fields, Enums and Enumeratnts. 80 | annDecl = new AnnotationDecl("enumAdded", ScalarType.TEXT); 81 | annDecl.addTarget(AnnotationDecl.Target.ENUMERANT); 82 | schema.annotationDecls.add(annDecl); 83 | 84 | annDecl = new AnnotationDecl("enumAddedEP", ScalarType.INT32); 85 | annDecl.addTarget(AnnotationDecl.Target.ENUMERANT); 86 | schema.annotationDecls.add(annDecl); 87 | 88 | annDecl = new AnnotationDecl("enumDeprecated", ScalarType.TEXT); 89 | annDecl.addTarget(AnnotationDecl.Target.ENUMERANT); 90 | schema.annotationDecls.add(annDecl); 91 | 92 | annDecl = new AnnotationDecl("enumValue", ScalarType.TEXT); 93 | annDecl.addTarget(AnnotationDecl.Target.ENUMERANT); 94 | schema.annotationDecls.add(annDecl); 95 | 96 | annDecl = new AnnotationDecl("type", ScalarType.TEXT); 97 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 98 | schema.annotationDecls.add(annDecl); 99 | 100 | annDecl = new AnnotationDecl("fieldAdded", ScalarType.TEXT); 101 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 102 | schema.annotationDecls.add(annDecl); 103 | 104 | annDecl = new AnnotationDecl("fieldAddedEP", ScalarType.INT32); 105 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 106 | schema.annotationDecls.add(annDecl); 107 | 108 | annDecl = new AnnotationDecl("fieldDeprecated", ScalarType.TEXT); 109 | annDecl.addTarget(AnnotationDecl.Target.FIELD); 110 | schema.annotationDecls.add(annDecl); 111 | 112 | /* 113 | * Build enums from the CodeSets 114 | */ 115 | CodeSets codeSets = repo.getCodeSets(); 116 | List codeSetTypes = codeSets.getCodeSet(); 117 | for(CodeSetType codeSetType : codeSetTypes) { 118 | Enum protoEnum = buildEnum(codeSetType); 119 | if(codeSetCategoryMap.containsKey(codeSetType.getName())) { 120 | String pkgName = codeSetCategoryMap.get(codeSetType.getName()); 121 | protoEnum.homePackage = pkgName; 122 | } 123 | else { 124 | protoEnum.homePackage = null; 125 | } 126 | schema.enums.add(protoEnum); 127 | } 128 | /* 129 | * Build proto messages from the FIX components. 130 | */ 131 | Components components = repo.getComponents(); 132 | List componentTypes = components.getComponent(); 133 | for(ComponentType componentType : componentTypes) { 134 | Message protoMsg = buildMessage(componentType); 135 | protoMsg.homePackage = componentType.getCategory(); 136 | schema.messages.add(protoMsg); 137 | } 138 | /* 139 | * Build proto messages from the FIX messages. 140 | */ 141 | Messages messages = repo.getMessages(); 142 | List messageTypes = messages.getMessage(); 143 | for(MessageType messageType : messageTypes) { 144 | Message protoMsg = buildMessage(messageType); 145 | protoMsg.homePackage = messageType.getCategory(); 146 | schema.messages.add(protoMsg); 147 | } 148 | /* 149 | * Build the supporting messages. 150 | */ 151 | schema.messages.add(buildDecimal32()); 152 | schema.messages.add(buildDecimal64()); 153 | schema.messages.add(buildTimestamp()); 154 | schema.messages.add(buildTimeOnly()); 155 | schema.messages.add(buildLocalTimestamp()); 156 | schema.messages.add(buildLocalTimeOnly()); 157 | schema.messages.add(buildTenor()); 158 | 159 | return schema; 160 | } 161 | 162 | private Enum buildEnum(CodeSetType codeSet) { 163 | Enum protoEnum = new Enum(); 164 | protoEnum.name = codeSet.getName(); 165 | 166 | EnumField dfltField = new EnumField(); 167 | dfltField.name = "unspecified"; 168 | dfltField.num = 0; 169 | protoEnum.fields.add(dfltField); 170 | 171 | for(CodeType codeType : codeSet.getCode()) { 172 | EnumField f = new EnumField(); 173 | f.name = codeType.getName(); 174 | f.num = Integer.parseInt(codeType.getSort()); // for now 175 | if(codeType.getAdded() != null) { 176 | String added = codeType.getAdded(); 177 | f.annotations.add(new Annotation("enumAdded", added, Annotation.ValueType.QUOTED_STRING)); 178 | } 179 | if(codeType.getAddedEP() != null) { 180 | String added_ep = codeType.getAddedEP().toString(); 181 | f.annotations.add(new Annotation("enumAddedEP", added_ep, Annotation.ValueType.NUMERIC)); 182 | } 183 | if(codeType.getDeprecated() != null) { 184 | String s = codeType.getDeprecated(); 185 | f.annotations.add(new Annotation("enumDeprecated", s, Annotation.ValueType.QUOTED_STRING)); 186 | } 187 | if(codeType.getValue() != null) { 188 | String s = codeType.getValue(); 189 | f.annotations.add(new Annotation("enumValue", s, Annotation.ValueType.QUOTED_STRING)); 190 | } 191 | protoEnum.fields.add(f); 192 | } 193 | 194 | /* 195 | FieldComparator fieldComparator = new FieldComparator(FieldComparator.SortOrder.NONE); 196 | Collections.sort(fields, fieldComparator); 197 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSet.getName(), null)); 198 | defaultField.fieldNum = 0; 199 | protoEnum.fields.add(defaultField); 200 | for(int i=0; i msgItems = component.getComponentRefOrGroupRefOrFieldRef(); 213 | for(Object msgItem : msgItems) { 214 | MessageField protoField = null; 215 | if(msgItem instanceof ComponentRefType) { 216 | if(msgItem instanceof GroupRefType) 217 | protoField = buildField((GroupRefType) msgItem); 218 | else 219 | protoField = buildField((ComponentRefType) msgItem); 220 | } 221 | else if(msgItem instanceof FieldRefType) { 222 | protoField = buildField((FieldRefType) msgItem); 223 | 224 | if(hasUnionType((FieldRefType) msgItem)) { 225 | MessageField altField = buildAltUnionField((FieldRefType) msgItem); 226 | if(altField != null) { 227 | protoMsg.fields.add(altField); 228 | List unionList = new ArrayList(Arrays.asList(altField, protoField)); 229 | protoMsg.nestedUnions.put(protoField.name, unionList); 230 | } 231 | } 232 | 233 | } 234 | if(protoField != null) { 235 | protoMsg.fields.add(protoField); 236 | } 237 | 238 | } 239 | /* 240 | Collections.sort(protoMsg.fields, fieldCmp); 241 | */ 242 | for(int i=0; i msgItems = msgStructure.getComponentRefOrGroupRefOrFieldRef(); 254 | for(Object msgItem : msgItems) { 255 | MessageField protoField = null; 256 | if(msgItem instanceof ComponentRefType) { 257 | if(msgItem instanceof GroupRefType) 258 | protoField = buildField((GroupRefType) msgItem); 259 | else 260 | protoField = buildField((ComponentRefType) msgItem); 261 | } 262 | else if(msgItem instanceof FieldRefType) { 263 | protoField = buildField((FieldRefType) msgItem); 264 | if(hasUnionType((FieldRefType) msgItem)) { 265 | MessageField altField = buildAltUnionField((FieldRefType) msgItem); 266 | if(altField != null) { 267 | protoMsg.fields.add(altField); 268 | List unionList = new ArrayList(Arrays.asList(altField, protoField)); 269 | protoMsg.nestedUnions.put(protoField.name, unionList); 270 | } 271 | } 272 | } 273 | if(protoField != null) 274 | protoMsg.fields.add(protoField); 275 | } 276 | /* 277 | Collections.sort(protoMsg.fields, fieldCmp); 278 | */ 279 | for(int i=0; i unionFields = new ArrayList(); 756 | for(int i=0; i /*, Comparator */ { 28 | 29 | static Logger logger = LogManager.getLogger(FieldComparator.class); 30 | 31 | public enum SortOrder { 32 | BY_SPEC, 33 | NONE 34 | } 35 | private SortOrder sortOrder; 36 | 37 | FieldComparator(SortOrder sortOrder) { 38 | this.sortOrder = sortOrder; 39 | } 40 | 41 | public int compare(Field f1, Field f2) { 42 | if(sortOrder == SortOrder.NONE) 43 | return 0; 44 | StringBuilder sb1 = new StringBuilder(); 45 | StringBuilder sb2 = new StringBuilder(); 46 | 47 | if(f1 instanceof MessageField && f2 instanceof MessageField) { 48 | String fieldAdded = ""; 49 | String epAdded = ""; 50 | for(Option opt : f1.fieldOptions) { 51 | if(opt.name.equals("field_added")) { 52 | sb1.append(opt.value); 53 | } 54 | else if(opt.name.equals("field_added_ep")) { 55 | sb1.append(opt.value); 56 | } 57 | } 58 | sb1.append(rightPadding(fieldAdded,12)); 59 | sb1.append(rightPadding(epAdded, 6)); 60 | sb1.append(f1.fieldName); 61 | fieldAdded = ""; 62 | epAdded = ""; 63 | for(Option opt : f2.fieldOptions) { 64 | if(opt.name.equals("field_added")) { 65 | sb2.append(opt.value); 66 | } 67 | else if(opt.name.equals("field_added_ep")) { 68 | sb2.append(opt.value); 69 | } 70 | } 71 | sb2.append(rightPadding(fieldAdded,12)); 72 | sb2.append(rightPadding(epAdded, 6)); 73 | sb2.append(f2.fieldName); 74 | } 75 | else if(f1 instanceof EnumField && f2 instanceof EnumField) { 76 | String enumAdded = ""; 77 | String epAdded = ""; 78 | for(Option opt : f1.fieldOptions) { 79 | if(opt.name.equals("enum_added")) { 80 | sb1.append(opt.value); 81 | } 82 | else if(opt.name.equals("enum_added_ep")) { 83 | sb1.append(opt.value); 84 | } 85 | } 86 | sb1.append(rightPadding(enumAdded,12)); 87 | sb1.append(rightPadding(epAdded, 6)); 88 | sb1.append(f1.fieldName); 89 | enumAdded = ""; 90 | epAdded = ""; 91 | for(Option opt : f2.fieldOptions) { 92 | if(opt.name.equals("field_added")) { 93 | sb2.append(opt.value); 94 | } 95 | else if(opt.name.equals("field_added_ep")) { 96 | sb2.append(opt.value); 97 | } 98 | } 99 | sb2.append(rightPadding(enumAdded,12)); 100 | sb2.append(rightPadding(epAdded, 6)); 101 | sb2.append(f2.fieldName); 102 | } 103 | else { 104 | logger.error("Cannot compare fields: "+ f1.toString() + " " + f2.toString()); 105 | } 106 | 107 | return sb1.toString().compareTo(sb2.toString()); 108 | } 109 | 110 | public static String rightPadding(String str, int num) { 111 | return String.format("%1$-" + num + "s", str); 112 | } 113 | 114 | /* 115 | public int compare(capnp_model.Field f1, capnp_model.Field f2) { 116 | return 0; 117 | } 118 | */ 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/IModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import java.util.Map; 19 | //import io.fixprotocol._2016.fixrepository.*; 20 | 21 | public interface IModel { 22 | //public boolean buildFromRepo(Repository repo); 23 | public Map toFileSet(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/JAXBValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import javax.xml.bind.ValidationEvent; 19 | import javax.xml.bind.ValidationEventLocator; 20 | import javax.xml.bind.util.ValidationEventCollector; 21 | 22 | class JAXBValidator extends ValidationEventCollector { 23 | @Override 24 | public boolean handleEvent(ValidationEvent event) { 25 | if (event.getSeverity() == ValidationEvent.ERROR || event.getSeverity() == ValidationEvent.FATAL_ERROR) { 26 | ValidationEventLocator locator = event.getLocator(); 27 | String msg = "XML Validation Exception: " + event.getMessage() + " at row: " + 28 | locator.getLineNumber() + 29 | " column: " + locator.getColumnNumber(); 30 | throw new RuntimeException(msg); 31 | } 32 | return true; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/ModelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import java.math.BigInteger; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | import org.apache.logging.log4j.LogManager; 23 | import org.apache.logging.log4j.Logger; 24 | import io.fixprotocol._2020.orchestra.repository.CodeSetType; 25 | import io.fixprotocol._2020.orchestra.repository.CodeSets; 26 | import io.fixprotocol._2020.orchestra.repository.ComponentType; 27 | import io.fixprotocol._2020.orchestra.repository.Components; 28 | import io.fixprotocol._2020.orchestra.repository.Datatype; 29 | import io.fixprotocol._2020.orchestra.repository.FieldRefType; 30 | import io.fixprotocol._2020.orchestra.repository.FieldType; 31 | import io.fixprotocol._2020.orchestra.repository.GroupType; 32 | import io.fixprotocol._2020.orchestra.repository.Groups; 33 | import io.fixprotocol._2020.orchestra.repository.MessageType; 34 | import io.fixprotocol._2020.orchestra.repository.MessageType.Structure; 35 | import io.fixprotocol._2020.orchestra.repository.Repository; 36 | 37 | abstract class ModelFactory { 38 | 39 | static Logger logger = LogManager.getLogger(ModelFactory.class); 40 | 41 | protected Repository repo; 42 | protected CodegenSettings codegenSettings; 43 | /* 44 | * These maps will come in handy when we build a schema. 45 | */ 46 | protected Map datatypeMap; 47 | protected Map fieldMap; 48 | protected Map codeSetMap; 49 | protected Map codeSetCategoryMap; 50 | protected Map componentMap; 51 | protected Map groupMap; 52 | 53 | protected FieldComparator fieldCmp; 54 | 55 | public ModelFactory(Repository repoParam, CodegenSettings codegenSettingsParam) { 56 | /* 57 | * If we want to do some validation we can do it here. E.g. check whether 58 | * fields have correct datatype spellings. 59 | */ 60 | repo = repoParam; 61 | codegenSettings = codegenSettingsParam; 62 | 63 | /* 64 | * If we want to make corrections to the repo we can do it here. 65 | */ 66 | { 67 | /* 68 | * The field NoSides is problematic. It is a NumInGroup and a CodeSet. Furthermore, when we create an Enum 69 | * we cannot assign it to a package. So what to do? Let's remove it from the list of CodeSets. 70 | */ 71 | CodeSets codeSets = repo.getCodeSets(); 72 | List codeSetTypes = codeSets.getCodeSet(); 73 | CodeSetType noSidesCodeSet = null; 74 | for(CodeSetType codeSetType : codeSetTypes) { 75 | if(codeSetType.getName().equals("NoSidesCodeSet")) { 76 | //logger.info("Removing NoSides from list of CodeSets."); 77 | noSidesCodeSet = codeSetType; 78 | } 79 | } 80 | if(noSidesCodeSet != null) 81 | codeSetTypes.remove(noSidesCodeSet); 82 | } 83 | 84 | /* 85 | * Let's now set-up our handy maps. 86 | */ 87 | datatypeMap = new HashMap(); 88 | for(Datatype datatype : repo.getDatatypes().getDatatype()) { 89 | datatypeMap.put(datatype.getName(), datatype); 90 | } 91 | fieldMap = new HashMap(); 92 | for(FieldType field : repo.getFields().getField()) { 93 | fieldMap.put(field.getId(), field); 94 | } 95 | codeSetMap = new HashMap(); 96 | CodeSets codeSets = repo.getCodeSets(); 97 | List codeSetTypes = codeSets.getCodeSet(); 98 | for(CodeSetType codeSetType : codeSetTypes) { 99 | codeSetMap.put(codeSetType.getName(), codeSetType); 100 | if(codeSetType.getName().startsWith("NoSide")) 101 | logger.warn("Field \"NoSides\" is defined as a CodeSet rather than a NumInGroup."); 102 | } 103 | componentMap = new HashMap(); 104 | Components components = repo.getComponents(); 105 | List componentTypes = components.getComponent(); 106 | for(ComponentType componentType : componentTypes) { 107 | componentMap.put(componentType.getId(), componentType); 108 | } 109 | groupMap = new HashMap(); 110 | Groups groups = repo.getGroups(); 111 | List groupTypes = groups.getGroup(); 112 | for(GroupType groupType : groupTypes) { 113 | groupMap.put(groupType.getId(), groupType); 114 | } 115 | 116 | /* 117 | * We'll want to know what file to place the CodeSets into. This will be helpful when we are generating the output and need to 118 | * know which files must be imported. The rule is: if a CodeSet is referred by more than one field, and each of these fields 119 | * are members of messages of different categories, then print the CodeSet in the common.proto file. If each field 120 | * is a member of a message of the same category, then print the CodeSet in said category. 121 | * It's a bit of work to figure out the proper category for the CodeSets, but here goes... 122 | */ 123 | codeSetCategoryMap = new HashMap(); 124 | for(ComponentType component : componentTypes) { 125 | List compItems = component.getComponentRefOrGroupRefOrFieldRef(); 126 | for(Object obj : compItems){ 127 | if(obj instanceof FieldRefType) { 128 | FieldRefType fieldRef = (FieldRefType) obj; // we got the field ref, but I think we need to get the actual field and examine it's type. 129 | FieldType field = fieldMap.get(fieldRef.getId()); 130 | String codeSetName = field.getType(); // CodeSet types will end in "CodeSet". 131 | CodeSetType cs = codeSetMap.get(codeSetName); 132 | if(cs != null) { 133 | String category = component.getCategory(); 134 | if(category != null) { 135 | if(codeSetCategoryMap.containsKey(codeSetName)) { 136 | String prevCategory = codeSetCategoryMap.get(codeSetName); 137 | if(!prevCategory.equals(category)) { 138 | codeSetCategoryMap.put(codeSetName, "common"); 139 | } 140 | } 141 | else { 142 | codeSetCategoryMap.put(codeSetName, category); 143 | } 144 | } 145 | else { 146 | logger.info("category is missing for " + cs.getName()); 147 | } 148 | } 149 | } 150 | } 151 | } 152 | for(MessageType message : repo.getMessages().getMessage()) { 153 | Structure msgStructure = message.getStructure(); 154 | List msgItems = msgStructure.getComponentRefOrGroupRefOrFieldRef(); 155 | for(Object obj : msgItems) { 156 | if(obj instanceof FieldRefType) { 157 | FieldRefType fieldRef = (FieldRefType) obj; 158 | FieldType field = fieldMap.get(fieldRef.getId()); 159 | String codeSetName = field.getType(); // CodeSet types will end in "CodeSet". 160 | CodeSetType cs = codeSetMap.get(codeSetName); 161 | if(cs != null) { 162 | String category = message.getCategory(); 163 | if(category != null) { 164 | if(codeSetCategoryMap.containsKey(codeSetName)) { 165 | String prevCategory = codeSetCategoryMap.get(codeSetName); 166 | if(!prevCategory.equals(category)) { 167 | codeSetCategoryMap.put(codeSetName, "common"); 168 | } 169 | } 170 | else { 171 | codeSetCategoryMap.put(codeSetName, category); 172 | } 173 | } 174 | else { 175 | logger.info("category is missing for " + cs.getName()); 176 | } 177 | } 178 | } 179 | } 180 | } 181 | 182 | if(codegenSettings.maintainRepoFieldOrder) 183 | fieldCmp = new FieldComparator(FieldComparator.SortOrder.NONE); 184 | else 185 | fieldCmp = new FieldComparator(FieldComparator.SortOrder.BY_SPEC); 186 | } 187 | 188 | protected abstract IModel buildModel(); 189 | 190 | protected String getFieldName(FieldRefType fieldRef) { 191 | FieldType field = fieldMap.get(fieldRef.getId()); 192 | if (field != null) { 193 | return field.getName(); 194 | } else { 195 | return ""; 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/ProtoGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import java.io.BufferedWriter; 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.FileNotFoundException; 22 | import java.io.FileWriter; 23 | import java.io.IOException; 24 | import java.util.List; 25 | import java.util.Map; 26 | import javax.xml.bind.JAXBContext; 27 | import javax.xml.bind.JAXBException; 28 | import javax.xml.bind.Unmarshaller; 29 | //import javax.xml.bind.ValidationEvent; 30 | import javax.xml.bind.util.ValidationEventCollector; 31 | import org.apache.commons.cli.CommandLine; 32 | import org.apache.commons.cli.CommandLineParser; 33 | import org.apache.commons.cli.DefaultParser; 34 | import org.apache.commons.cli.HelpFormatter; 35 | import org.apache.commons.cli.Option; 36 | import org.apache.commons.cli.Options; 37 | import org.apache.commons.cli.ParseException; 38 | import org.apache.logging.log4j.LogManager; 39 | import org.apache.logging.log4j.Logger; 40 | import io.fixprotocol._2020.orchestra.repository.Repository; 41 | 42 | public class ProtoGen { 43 | 44 | static Logger logger = LogManager.getLogger(ProtoGen.class); 45 | 46 | public Map generateProtos(String repoFileName, CodegenSettings settings) 47 | throws FileNotFoundException, IOException, JAXBException 48 | { 49 | Repository rootElement = null; 50 | ValidationEventCollector evHandler = new JAXBValidator(); 51 | JAXBContext jc = JAXBContext.newInstance("io.fixprotocol._2020.orchestra.repository"); 52 | Unmarshaller unmarshaller = jc.createUnmarshaller(); 53 | unmarshaller.setEventHandler(evHandler); 54 | FileInputStream fis = new FileInputStream(repoFileName); 55 | rootElement = (Repository) (unmarshaller.unmarshal(fis)); 56 | fis.close(); 57 | ModelFactory pf = null; 58 | switch(settings.getSchemaLanguage()) { 59 | case PROTO2: pf = new ProtobufModelFactory(rootElement, settings); break; 60 | case PROTO3: pf = new ProtobufModelFactory(rootElement, settings); break; 61 | case CAPNPROTO: pf = new CapnpModelFactory(rootElement, settings); break; 62 | case FLATBUFFERS: pf = new CapnpModelFactory(rootElement, settings); break; 63 | } 64 | IModel protoModel = pf.buildModel(); 65 | Map fileSet = protoModel.toFileSet(); 66 | return fileSet; 67 | } 68 | 69 | public static void main(String[] args) { 70 | 71 | CodegenSettings codegenSettings = new CodegenSettings(); 72 | String outputPath = "./"; 73 | String repoFileName = null; 74 | 75 | final String LANG_KEYSTR = "lang"; 76 | final String OPATH_KEYSTR = "opath"; 77 | final String NOSORT_KEYSTR = "nosort"; 78 | final String ALTFILESET_KEYSTR = "altfs"; 79 | 80 | Options cmdLineOptions = new Options(); 81 | 82 | Option langOpt = new Option(LANG_KEYSTR, null, true, "Schema language (valid args: proto2 proto3 capnp)"); 83 | langOpt.setRequired(false); 84 | cmdLineOptions.addOption(langOpt); 85 | Option outputDirOpt = new Option(OPATH_KEYSTR, null, true, "Output directory"); 86 | outputDirOpt.setRequired(false); 87 | cmdLineOptions.addOption(outputDirOpt); 88 | Option sortOpt = new Option(NOSORT_KEYSTR, null, false, "Maintain repo field ordering"); 89 | sortOpt.setRequired(false); 90 | cmdLineOptions.addOption(sortOpt); 91 | Option altFilePackagingOpt = new Option(ALTFILESET_KEYSTR, null, false, "Use alternate output file packaging"); 92 | altFilePackagingOpt.setRequired(false); 93 | cmdLineOptions.addOption(altFilePackagingOpt); 94 | 95 | Option help = new Option("help", "Print this message"); 96 | cmdLineOptions.addOption(help); 97 | 98 | Option version = new Option("version", "Print version"); 99 | cmdLineOptions.addOption(version); 100 | 101 | CommandLineParser parser = new DefaultParser(); 102 | HelpFormatter formatter = new HelpFormatter(); 103 | try { 104 | CommandLine cmd = parser.parse(cmdLineOptions, args); 105 | if(cmd.hasOption("help")) { 106 | formatter.printHelp("fixprotogen [options] \n Options:\n", cmdLineOptions); 107 | System.exit(1); 108 | } 109 | if(cmd.hasOption("version")) { 110 | System.out.println("FIX Proto Schema Generator 0.0.1"); 111 | System.exit(1); 112 | } 113 | if(cmd.hasOption(LANG_KEYSTR)) { 114 | String langStr = cmd.getOptionValue(LANG_KEYSTR); 115 | if(langStr.equalsIgnoreCase("proto2")) { 116 | codegenSettings.schemaLanguage = CodegenSettings.SchemaLanguage.PROTO2; 117 | outputPath = "generated_v2_protos"; 118 | } 119 | else if(langStr.equalsIgnoreCase("proto3")) { 120 | codegenSettings.schemaLanguage = CodegenSettings.SchemaLanguage.PROTO3; 121 | outputPath = "generated_v3_protos"; 122 | } 123 | else if(langStr.equalsIgnoreCase("capnp")) { 124 | codegenSettings.schemaLanguage = CodegenSettings.SchemaLanguage.CAPNPROTO; 125 | outputPath = "generated_capnps"; 126 | } 127 | else if(langStr.equalsIgnoreCase("flatb")) { 128 | codegenSettings.schemaLanguage = CodegenSettings.SchemaLanguage.FLATBUFFERS; 129 | outputPath = "generated_flatbs"; 130 | } 131 | else { 132 | System.err.println("Error: illegal lang option: " + langStr); 133 | System.exit(1); 134 | } 135 | } 136 | else { 137 | codegenSettings.schemaLanguage = CodegenSettings.SchemaLanguage.PROTO3; 138 | outputPath = "generated_v3_protos"; 139 | } 140 | if(cmd.hasOption(OPATH_KEYSTR)) { 141 | outputPath = cmd.getOptionValue(OPATH_KEYSTR); 142 | } 143 | codegenSettings.useAltOutputPackaging = cmd.hasOption(ALTFILESET_KEYSTR) ? true : false; 144 | codegenSettings.maintainRepoFieldOrder = cmd.hasOption(NOSORT_KEYSTR) ? true : false; 145 | List srcFiles = cmd.getArgList(); 146 | if(srcFiles.isEmpty()) { 147 | System.err.println("Error: missing repo file arg."); 148 | formatter.printHelp("fixprotogen [options] \n Options:\n", cmdLineOptions); 149 | System.exit(1); 150 | } 151 | else { 152 | repoFileName = srcFiles.get(0); 153 | } 154 | } catch (ParseException e) { 155 | System.out.println(e.getMessage()); 156 | formatter.printHelp("fixprotogen [options] \n Options:\n", cmdLineOptions); 157 | System.exit(1); 158 | } catch (Exception e) { 159 | System.out.println(e.getMessage()); 160 | } 161 | 162 | ProtoGen protoGen = new ProtoGen(); 163 | 164 | try { 165 | Map fileSet = protoGen.generateProtos(repoFileName, codegenSettings); 166 | File dir = new File(outputPath); 167 | if(!dir.exists()) { 168 | dir.mkdir(); 169 | } 170 | for(Map.Entry entry : fileSet.entrySet()) { 171 | String targetFile = outputPath + "//" + entry.getKey(); 172 | String protoText = entry.getValue().toString(); 173 | FileWriter fstream = new FileWriter(targetFile); 174 | BufferedWriter out = new BufferedWriter(fstream); 175 | out.write(protoText); 176 | out.close(); 177 | } 178 | } 179 | catch (FileNotFoundException e) { 180 | logger.error("FileNotFoundException: " + e.getMessage()); 181 | e.printStackTrace(); 182 | } 183 | catch (IOException e) { 184 | logger.error("IOException: " + e.getMessage()); 185 | e.printStackTrace(); 186 | } 187 | catch (JAXBException e) { 188 | logger.error("JAXBException: " + e.getMessage()); 189 | e.printStackTrace(); 190 | } 191 | /* 192 | catch (SecurityException e) { 193 | logger.error("Security Exception: " + e.getMessage()); 194 | e.printStackTrace(); 195 | } 196 | */ 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/ProtobufModelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.Collections; 21 | import java.util.List; 22 | import io.fixprotocol._2020.orchestra.repository.CodeSetType; 23 | import io.fixprotocol._2020.orchestra.repository.CodeSets; 24 | import io.fixprotocol._2020.orchestra.repository.CodeType; 25 | import io.fixprotocol._2020.orchestra.repository.ComponentRefType; 26 | import io.fixprotocol._2020.orchestra.repository.ComponentType; 27 | import io.fixprotocol._2020.orchestra.repository.Components; 28 | import io.fixprotocol._2020.orchestra.repository.Datatype; 29 | import io.fixprotocol._2020.orchestra.repository.Datatypes; 30 | import io.fixprotocol._2020.orchestra.repository.FieldRefType; 31 | import io.fixprotocol._2020.orchestra.repository.FieldType; 32 | import io.fixprotocol._2020.orchestra.repository.GroupRefType; 33 | import io.fixprotocol._2020.orchestra.repository.GroupType; 34 | import io.fixprotocol._2020.orchestra.repository.Groups; 35 | import io.fixprotocol._2020.orchestra.repository.MessageType; 36 | import io.fixprotocol._2020.orchestra.repository.MessageType.Structure; 37 | import io.fixprotocol._2020.orchestra.repository.Messages; 38 | import io.fixprotocol._2020.orchestra.repository.Repository; 39 | import io.fixprotocol._2020.orchestra.repository.UnionDataTypeT; 40 | import io.fixprotocol.orchestra2proto.protobuf.Enum; 41 | import io.fixprotocol.orchestra2proto.protobuf.EnumField; 42 | import io.fixprotocol.orchestra2proto.protobuf.Extension; 43 | import io.fixprotocol.orchestra2proto.protobuf.ExtensionField; 44 | import io.fixprotocol.orchestra2proto.protobuf.Message; 45 | import io.fixprotocol.orchestra2proto.protobuf.MessageField; 46 | import io.fixprotocol.orchestra2proto.protobuf.Option; 47 | import io.fixprotocol.orchestra2proto.protobuf.ProtobufModel; 48 | import io.fixprotocol.orchestra2proto.protobuf.ScalarType; 49 | 50 | public class ProtobufModelFactory extends ModelFactory { 51 | 52 | public ProtobufModelFactory(Repository repoParam, CodegenSettings appSettingsParam) { 53 | super(repoParam, appSettingsParam); 54 | } 55 | 56 | protected ProtobufModel buildModel() { 57 | return buildProtobufModel(); 58 | } 59 | 60 | protected ProtobufModel buildProtobufModel() { 61 | /* 62 | * We are going to add everything from the repo to our proto schema. 63 | * It is here where we decide how many files we want to generate and which messages and which enums they contain. 64 | */ 65 | ProtobufModel.Syntax syntax = codegenSettings.getSchemaLanguage() == CodegenSettings.SchemaLanguage.PROTO2 ? ProtobufModel.Syntax.PROTO2 : ProtobufModel.Syntax.PROTO3; 66 | 67 | ProtobufModel protoSchema = new ProtobufModel(repo.getName(), syntax); 68 | 69 | Extension fileExtension = new Extension("google.protobuf.FileOptions"); 70 | fileExtension.addField(new ExtensionField(ScalarType.STRING, "category", 53001)); 71 | fileExtension.homePackage = codegenSettings.useAltOutputPackaging ? "extended-gpb-options" : "fix"; 72 | protoSchema.extensions.add(fileExtension); 73 | 74 | Extension msgExtension = new Extension("google.protobuf.MessageOptions"); 75 | msgExtension.addField(new ExtensionField(ScalarType.STRING, "msg_type_value", 52001)); 76 | msgExtension.homePackage = codegenSettings.useAltOutputPackaging ? "extended-gpb-options" : "fix"; 77 | protoSchema.extensions.add(msgExtension); 78 | 79 | if(codegenSettings.useAltOutputPackaging) { 80 | 81 | Extension ext = new Extension("google.protobuf.FieldOptions"); 82 | ext.addField(new ExtensionField(ScalarType.FIXED32, "tag", 50001)); 83 | ext.addField(new ExtensionField("Version", "field_added", 50002)); 84 | ext.addField(new ExtensionField(ScalarType.SFIXED32, "field_added_ep", 50003)); 85 | ext.addField(new ExtensionField("Version", "field_deprecated", 50004)); 86 | ext.addField(new ExtensionField(ScalarType.FIXED32, "min_len", 50005)); 87 | ext.addField(new ExtensionField(ScalarType.FIXED32, "max_len", 50006)); 88 | ext.addField(new ExtensionField(ScalarType.SFIXED64, "min_value", 50007)); 89 | ext.addField(new ExtensionField(ScalarType.SFIXED64, "max_value", 50008)); 90 | ext.addField(new ExtensionField(ScalarType.FIXED32, "group_tag", 50009)); 91 | ext.addField(new ExtensionField("Datatype", "type", 50010)); 92 | ext.addField(new ExtensionField("TimeUnitFieldOption", "time_unit", 50011)); 93 | ext.addField(new ExtensionField("EpochFieldOption", "epoch", 50012)); 94 | ext.homePackage = "extended-gpb-options"; 95 | protoSchema.extensions.add(ext); 96 | 97 | ext = new Extension("google.protobuf.EnumValueOptions"); 98 | ext.addField(new ExtensionField("Version", "enum_added", 51001)); 99 | ext.addField(new ExtensionField(ScalarType.SFIXED32, "enum_added_ep", 51002)); 100 | ext.addField(new ExtensionField("Version", "enum_deprecated", 51003)); 101 | ext.addField(new ExtensionField(ScalarType.STRING, "enum_value", 51004)); 102 | ext.homePackage = "extended-gpb-options"; 103 | protoSchema.extensions.add(ext); 104 | } 105 | else { 106 | Extension ext = new Extension("google.protobuf.FieldOptions"); 107 | ext.addField(new ExtensionField(ScalarType.FIXED32, "tag", 50001)); 108 | ext.addField(new ExtensionField("Version", "field_added", 50002)); 109 | ext.addField(new ExtensionField(ScalarType.SFIXED32, "field_added_ep", 50003)); 110 | ext.addField(new ExtensionField("Version", "field_deprecated", 50004)); 111 | ext.addField(new ExtensionField(ScalarType.FIXED32, "group_tag", 50009)); 112 | ext.addField(new ExtensionField("Datatype", "type", 50010)); 113 | ext.homePackage = "fix"; 114 | protoSchema.extensions.add(ext); 115 | 116 | ext = new Extension("google.protobuf.FieldOptions"); 117 | ext.addField(new ExtensionField(ScalarType.FIXED32, "min_len", 50005)); 118 | ext.addField(new ExtensionField(ScalarType.FIXED32, "max_len", 50006)); 119 | ext.addField(new ExtensionField(ScalarType.SFIXED64, "min_value", 50007)); 120 | ext.addField(new ExtensionField(ScalarType.SFIXED64, "max_value", 50008)); 121 | ext.addField(new ExtensionField("TimeUnitFieldOption", "time_unit", 50011)); 122 | ext.addField(new ExtensionField("EpochFieldOption", "epoch", 50012)); 123 | ext.homePackage = "meta"; 124 | protoSchema.extensions.add(ext); 125 | 126 | ext = new Extension("google.protobuf.EnumValueOptions"); 127 | ext.addField(new ExtensionField("Version", "enum_added", 51001)); 128 | ext.addField(new ExtensionField(ScalarType.SFIXED32, "enum_added_ep", 51002)); 129 | ext.addField(new ExtensionField("Version", "enum_deprecated", 51003)); 130 | ext.addField(new ExtensionField(ScalarType.STRING, "enum_value", 51004)); 131 | ext.homePackage = "fix"; 132 | protoSchema.extensions.add(ext); 133 | } 134 | 135 | /* 136 | * Build proto enums from the CodeSets 137 | */ 138 | CodeSets codeSets = repo.getCodeSets(); 139 | List codeSetTypes = codeSets.getCodeSet(); 140 | for(CodeSetType codeSetType : codeSetTypes) { 141 | Enum protoEnum = buildEnum(codeSetType); 142 | protoEnum.homePackage = codegenSettings.useAltOutputPackaging ? "supporting-messages" : "fix"; 143 | protoSchema.enums.add(protoEnum); 144 | } 145 | /* 146 | * Build proto messages from the FIX components. 147 | */ 148 | Components components = repo.getComponents(); 149 | List componentTypes = components.getComponent(); 150 | for(ComponentType componentType : componentTypes) { 151 | Message protoMsg = buildMessage(componentType); 152 | protoMsg.homePackage = componentType.getCategory(); 153 | protoSchema.messages.add(protoMsg); 154 | } 155 | /* 156 | * Build proto messages from the FIX messages. 157 | */ 158 | Messages messages = repo.getMessages(); 159 | List messageTypes = messages.getMessage(); 160 | for(MessageType messageType : messageTypes) { 161 | Message protoMsg = buildMessage(messageType); 162 | protoMsg.homePackage = messageType.getCategory(); 163 | protoSchema.messages.add(protoMsg); 164 | } 165 | /* 166 | * Build proto messages from the FIX groups 167 | */ 168 | Groups groups = repo.getGroups(); 169 | List groupTypes = groups.getGroup(); 170 | for(GroupType groupType : groupTypes) { 171 | Message protoMsg = buildMessage(groupType); 172 | protoMsg.homePackage = groupType.getCategory(); 173 | protoSchema.messages.add(protoMsg); 174 | } 175 | /* 176 | * Build the supporting messages. 177 | */ 178 | protoSchema.messages.add(buildDecimal32()); 179 | protoSchema.messages.add(buildDecimal64()); 180 | protoSchema.messages.add(buildTimestamp()); 181 | protoSchema.messages.add(buildTimeOnly()); 182 | protoSchema.messages.add(buildLocalTimestamp()); 183 | protoSchema.messages.add(buildLocalTimeOnly()); 184 | protoSchema.messages.add(buildTenor()); 185 | /* 186 | * Build the supporting enums. 187 | */ 188 | protoSchema.enums.add(buildTimeUnit()); 189 | protoSchema.enums.add(buildEpoch()); 190 | protoSchema.enums.add(buildDatatype(repo.getDatatypes())); 191 | protoSchema.enums.add(buildVersion()); 192 | 193 | return protoSchema; 194 | } 195 | 196 | private Enum buildEnum(CodeSetType codeSet) { 197 | Enum protoEnum = new Enum(); 198 | protoEnum.name = toProtoEnumName(codeSet.getName()); 199 | List fields = new ArrayList(); 200 | for(CodeType codeType : codeSet.getCode()) { 201 | String sort = codeType.getSort(); 202 | if(sort == null || sort == "") { 203 | sort = codeType.getValue(); 204 | logger.error(String.format("sort is blank: CodeType: name='%s', id='%d', value='%s', sort='%s'", codeType.getName(), codeType.getId(), codeType.getValue(), codeType.getSort())); 205 | } 206 | if(sort != sort.trim()) { 207 | logger.error(String.format("unexpected whitespace in attribute: CodeType: name='%s', id='%d', value='%s', sort='%s'", codeType.getName(), codeType.getId(), codeType.getValue(), codeType.getSort())); 208 | sort = sort.trim(); 209 | } 210 | EnumField f = new EnumField(); 211 | f.fieldName = toProtoEnumFieldName(codeSet.getName(), codeType.getName()); 212 | f.fieldNum = Integer.parseInt(sort); // for now 213 | 214 | // "UNSPECIFIED" is a reserved default enum value for the generated protos, must make value unique 215 | if(f.fieldName.contains("_UNSPECIFIED")) { 216 | f.fieldName = f.fieldName + "_VALUE"; 217 | } 218 | 219 | if(codeType.getAdded() != null) { 220 | String added = toVersionFieldName(codeType.getAdded()); 221 | f.fieldOptions.add(new Option("enum_added", added, Option.ValueType.ENUM_LITERAL)); 222 | } 223 | if(codeType.getAddedEP() != null) { 224 | String added_ep = codeType.getAddedEP().toString(); 225 | f.fieldOptions.add(new Option("enum_added_ep", added_ep, Option.ValueType.NUMERIC)); 226 | } 227 | if(codeType.getDeprecated() != null) { 228 | String s = toVersionFieldName(codeType.getDeprecated()); 229 | f.fieldOptions.add(new Option("enum_deprecated", s, Option.ValueType.ENUM_LITERAL)); 230 | // Deprecations may cause enum value duplication for the generated protos, must make values unique 231 | f.fieldName = f.fieldName + "_DEPRECATED"; 232 | } 233 | if(codeType.getValue() != null) { 234 | String s = codeType.getValue(); 235 | f.fieldOptions.add(new Option("enum_value", s, Option.ValueType.QUOTED_STRING)); 236 | } 237 | fields.add(f); 238 | } 239 | FieldComparator fieldComparator = new FieldComparator(FieldComparator.SortOrder.NONE); 240 | Collections.sort(fields, fieldComparator); 241 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSet.getName(), null)); 242 | defaultField.fieldNum = 0; 243 | protoEnum.fields.add(defaultField); 244 | for(int i=0; i msgItems = group.getComponentRefOrGroupRefOrFieldRef(); 256 | processMessageItems(protoMsg, msgItems); 257 | Collections.sort(protoMsg.fields, fieldCmp); 258 | for(int i=0; i msgItems = component.getComponentRefOrGroupRefOrFieldRef(); 268 | processMessageItems(protoMsg, msgItems); 269 | Collections.sort(protoMsg.fields, fieldCmp); 270 | for(int i=0; i msgItems = msgStructure.getComponentRefOrGroupRefOrFieldRef(); 283 | processMessageItems(protoMsg, msgItems); 284 | Collections.sort(protoMsg.fields, fieldCmp); 285 | for(int i=0; i msgItems) { 291 | for(Object msgItem : msgItems) { 292 | MessageField protoField = null; 293 | if(msgItem instanceof GroupRefType) { 294 | protoField = buildField((GroupRefType) msgItem); 295 | } 296 | else if(msgItem instanceof ComponentRefType) { 297 | protoField = buildField((ComponentRefType) msgItem); 298 | } 299 | else if(msgItem instanceof FieldRefType) { 300 | protoField = buildField((FieldRefType) msgItem); 301 | if(hasUnionType((FieldRefType) msgItem)) { 302 | MessageField altField = buildAltUnionField((FieldRefType) msgItem); 303 | if(altField != null) { 304 | protoMsg.fields.add(altField); 305 | List unionList = new ArrayList(Arrays.asList(protoField, altField)); 306 | protoMsg.nestedOneOfs.put(protoField.fieldName + "_union", unionList); 307 | } 308 | } 309 | } 310 | else { 311 | logger.error("unknown type: " + msgItem); 312 | } 313 | if(protoField != null) { 314 | protoMsg.fields.add(protoField); 315 | } 316 | } 317 | return protoMsg; 318 | } 319 | 320 | private MessageField buildField(GroupRefType groupRef) { 321 | GroupType group = groupMap.get(groupRef.getId()); 322 | MessageField protoField = new MessageField(group.getName(), toProtoFieldName(group.getName())); 323 | protoField.isRepeating = true; 324 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 325 | if(groupRef.getAdded() != null) { 326 | String s = toVersionFieldName(groupRef.getAdded()); 327 | protoField.fieldOptions.add(new Option("field_added", s, Option.ValueType.ENUM_LITERAL)); 328 | } 329 | if(groupRef.getAddedEP() != null) { 330 | String s = groupRef.getAddedEP().toString(); 331 | protoField.fieldOptions.add(new Option("field_added_ep", s, Option.ValueType.NUMERIC)); 332 | } 333 | if(groupRef.getDeprecated() != null) { 334 | String s = toVersionFieldName(groupRef.getDeprecated()); 335 | protoField.fieldOptions.add(new Option("field_deprecated", s, Option.ValueType.ENUM_LITERAL)); 336 | } 337 | FieldRefType numInGroup = group.getNumInGroup(); 338 | if(numInGroup != null) { 339 | String s = numInGroup.getId().toString(); 340 | protoField.fieldOptions.add(new Option("group_tag", s, Option.ValueType.NUMERIC)); 341 | } 342 | return protoField; 343 | } 344 | 345 | private MessageField buildField(ComponentRefType componentRef) { 346 | ComponentType component = componentMap.get(componentRef.getId()); 347 | if(component == null) { 348 | logger.error(String.format("ComponentType is null: ComponentRefType: id='%d'", componentRef.getId())); 349 | } 350 | else { 351 | logger.debug(String.format("Component: name='%s', id='%d'", component.getName(), component.getId())); 352 | } 353 | MessageField protoField = new MessageField(component.getName(), toProtoFieldName(component.getName())); 354 | protoField.isRepeating = false; 355 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 356 | if(componentRef.getAdded() != null) { 357 | String s = toVersionFieldName(componentRef.getAdded()); 358 | protoField.fieldOptions.add(new Option("field_added", s, Option.ValueType.ENUM_LITERAL)); 359 | } 360 | if(componentRef.getAddedEP() != null) { 361 | String s = componentRef.getAddedEP().toString(); 362 | protoField.fieldOptions.add(new Option("field_added_ep", s, Option.ValueType.NUMERIC)); 363 | } 364 | if(componentRef.getDeprecated() != null) { 365 | String s = toVersionFieldName(componentRef.getDeprecated()); 366 | protoField.fieldOptions.add(new Option("field_deprecated", s, Option.ValueType.ENUM_LITERAL)); 367 | } 368 | return protoField; 369 | } 370 | 371 | private MessageField buildField(FieldRefType fieldRef) { 372 | FieldType field = fieldMap.get(fieldRef.getId()); 373 | MessageField protoField = new MessageField(); 374 | /* 375 | * Determine whether a CodeSet. If so, handle accordingly, otherwise it's just a regular FIX type. 376 | */ 377 | if(codeSetMap.containsKey(field.getType())) { 378 | CodeSetType codeSet = codeSetMap.get(field.getType()); 379 | String typeName = toProtoEnumName(codeSet.getName()); 380 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 381 | protoField.typeName = typeName; 382 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoEnum; 383 | protoField.isRepeating = codeSet.getType().equals("MultipleCharValue") || codeSet.getType().equals("MultipleStringValue"); 384 | 385 | if(codeSet.getType() != null) { 386 | String s = toProtoEnumFieldName("Datatype", codeSet.getType()); 387 | protoField.fieldOptions.add(new Option("type", s, Option.ValueType.ENUM_LITERAL)); 388 | } 389 | } 390 | /* 391 | * Just a regular FIX type. 392 | */ 393 | else { 394 | if(field.getType().equals("int")) { 395 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 396 | protoField.scalarType = ScalarType.FIXED32; 397 | protoField.typeName = protoField.scalarType.toString(); 398 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 399 | protoField.isRepeating = false; 400 | } 401 | else if(field.getType().equals("TagNum")) { 402 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 403 | protoField.scalarType = ScalarType.FIXED32; 404 | protoField.typeName = protoField.scalarType.toString(); 405 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 406 | protoField.isRepeating = false; 407 | } 408 | else if(field.getType().equals("NumInGroup")) { 409 | return null; 410 | } 411 | else if(field.getType().equals("SeqNum")) { 412 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 413 | protoField.scalarType = ScalarType.FIXED32; 414 | protoField.typeName = protoField.scalarType.toString(); 415 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 416 | protoField.isRepeating = false; 417 | } 418 | else if(field.getType().equals("Length")) { 419 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 420 | protoField.scalarType = ScalarType.FIXED32; 421 | protoField.typeName = protoField.scalarType.toString(); 422 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 423 | protoField.isRepeating = false; 424 | } 425 | else if(field.getType().equals("DayOfMonth")) { 426 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 427 | protoField.scalarType = ScalarType.FIXED32; 428 | protoField.typeName = protoField.scalarType.toString(); 429 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 430 | protoField.isRepeating = false; 431 | } 432 | else if(field.getType().equals("float")) { 433 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 434 | protoField.typeName = "Decimal32"; // this will depend on enc attrs 435 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 436 | protoField.isRepeating = false; 437 | } 438 | else if(field.getType().equals("Qty")) { 439 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 440 | protoField.typeName = "Decimal64"; // this will depend on enc attrs 441 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 442 | protoField.isRepeating = false; 443 | } 444 | else if(field.getType().equals("Price")) { 445 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 446 | protoField.typeName = "Decimal64"; // this will depend on enc attrs 447 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 448 | protoField.isRepeating = false; 449 | } 450 | else if(field.getType().equals("PriceOffset")) { 451 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 452 | protoField.typeName = "Decimal32"; // this will depend on enc attrs 453 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 454 | protoField.isRepeating = false; 455 | } 456 | else if(field.getType().equals("Amt")) { 457 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 458 | protoField.typeName = "Decimal32"; // this will depend on enc attrs 459 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 460 | protoField.isRepeating = false; 461 | } 462 | else if(field.getType().equals("Percentage")) { 463 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 464 | protoField.typeName = "Decimal32"; // this will depend on enc attrs 465 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 466 | protoField.isRepeating = false; 467 | } 468 | else if(field.getType().equals("char")) { 469 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 470 | protoField.scalarType = ScalarType.BYTES; 471 | protoField.typeName = protoField.scalarType.toString(); 472 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 473 | protoField.isRepeating = false; 474 | } 475 | else if(field.getType().equals("Boolean")) { 476 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 477 | protoField.scalarType = ScalarType.BOOL; 478 | protoField.typeName = protoField.scalarType.toString(); 479 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 480 | protoField.isRepeating = false; 481 | } 482 | else if(field.getType().equals("String")) { 483 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 484 | protoField.scalarType = ScalarType.STRING; 485 | protoField.typeName = protoField.scalarType.toString(); 486 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 487 | protoField.isRepeating = false; 488 | } 489 | else if(field.getType().equals("MultipleCharValue")) { 490 | // This case never occurs. 491 | logger.info(getFieldName(fieldRef) + " is a MultipleCharValue"); 492 | } 493 | else if(field.getType().equals("MultipleStringValue")) { 494 | // This case never occurs. 495 | logger.info(getFieldName(fieldRef) + " is a MultipleStringValue"); 496 | } 497 | else if(field.getType().equals("Country")) { 498 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 499 | protoField.scalarType = ScalarType.STRING; 500 | protoField.typeName = protoField.scalarType.toString(); 501 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 502 | protoField.isRepeating = false; 503 | } 504 | else if(field.getType().equals("Currency")) { 505 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 506 | protoField.scalarType = ScalarType.STRING; 507 | protoField.typeName = protoField.scalarType.toString(); 508 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 509 | protoField.isRepeating = false; 510 | } 511 | else if(field.getType().equals("Exchange")) { 512 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 513 | protoField.scalarType = ScalarType.STRING; 514 | protoField.typeName = protoField.scalarType.toString(); 515 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 516 | protoField.isRepeating = false; 517 | } 518 | else if(field.getType().equals("MonthYear")) { 519 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 520 | protoField.scalarType = ScalarType.SFIXED32; 521 | protoField.typeName = protoField.scalarType.toString(); 522 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 523 | protoField.isRepeating = false; 524 | } 525 | else if(field.getType().equals("UTCTimestamp")) { 526 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 527 | protoField.typeName = "Timestamp"; 528 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 529 | protoField.isRepeating = false; 530 | } 531 | else if(field.getType().equals("UTCTimeOnly")) { 532 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 533 | protoField.typeName = "TimeOnly"; 534 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 535 | protoField.isRepeating = false; 536 | } 537 | else if(field.getType().equals("UTCDateOnly")) { 538 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 539 | protoField.scalarType = ScalarType.SFIXED32; 540 | protoField.typeName = protoField.scalarType.toString(); 541 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 542 | protoField.isRepeating = false; 543 | } 544 | else if(field.getType().equals("LocalMktDate")) { 545 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 546 | protoField.scalarType = ScalarType.SFIXED32; 547 | protoField.typeName = protoField.scalarType.toString(); 548 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 549 | protoField.isRepeating = false; 550 | } 551 | else if(field.getType().equals("TZTimeOnly")) { 552 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 553 | protoField.typeName = "LocalTimeOnly"; 554 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 555 | protoField.isRepeating = false; 556 | } 557 | else if(field.getType().equals("TZTimestamp")) { 558 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 559 | protoField.typeName = "LocalTimestamp"; 560 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 561 | protoField.isRepeating = false; 562 | } 563 | else if(field.getType().equals("data")) { 564 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 565 | protoField.scalarType = ScalarType.STRING; 566 | protoField.typeName = protoField.scalarType.toString(); 567 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 568 | protoField.isRepeating = false; 569 | } 570 | else if(field.getType().equals("Pattern")) { 571 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 572 | protoField.scalarType = ScalarType.STRING; 573 | protoField.typeName = protoField.scalarType.toString(); 574 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 575 | protoField.isRepeating = false; 576 | } 577 | else if(field.getType().equals("Tenor")) { 578 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 579 | protoField.typeName = "Tenor"; // this will depend on enc attrs 580 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 581 | protoField.isRepeating = false; 582 | } 583 | else if(field.getType().equals("XMLData")) { 584 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 585 | protoField.scalarType = ScalarType.STRING; 586 | protoField.typeName = protoField.scalarType.toString(); 587 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 588 | protoField.isRepeating = false; 589 | } 590 | else if(field.getType().equals("Language")) { 591 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 592 | protoField.scalarType = ScalarType.STRING; 593 | protoField.typeName = protoField.scalarType.toString(); 594 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 595 | protoField.isRepeating = false; 596 | } 597 | else if(field.getType().equals("XID")) { 598 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 599 | protoField.scalarType = ScalarType.STRING; 600 | protoField.typeName = protoField.scalarType.toString(); 601 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 602 | protoField.isRepeating = false; 603 | } 604 | else if(field.getType().equals("XIDRef")) { 605 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef)); 606 | protoField.scalarType = ScalarType.STRING; 607 | protoField.typeName = protoField.scalarType.toString(); 608 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 609 | protoField.isRepeating = false; 610 | } 611 | else { 612 | logger.info(field.getName() + ": unrecognized type: " + field.getType()); 613 | return null; 614 | } 615 | if(field.getType() != null) { 616 | String s = toProtoEnumFieldName("Datatype", field.getType()); 617 | protoField.fieldOptions.add(new Option("type", s, Option.ValueType.ENUM_LITERAL)); 618 | } 619 | } 620 | if(fieldRef.getAdded() != null) { 621 | String added = toVersionFieldName(fieldRef.getAdded()); 622 | protoField.fieldOptions.add(new Option("field_added", added, Option.ValueType.ENUM_LITERAL)); 623 | } 624 | if(fieldRef.getAddedEP() != null) { 625 | String added_ep = fieldRef.getAddedEP().toString(); 626 | protoField.fieldOptions.add(new Option("field_added_ep", added_ep, Option.ValueType.NUMERIC)); 627 | } 628 | if(fieldRef.getDeprecated() != null) { 629 | String s = toVersionFieldName(fieldRef.getDeprecated()); 630 | protoField.fieldOptions.add(new Option("field_deprecated", s, Option.ValueType.ENUM_LITERAL)); 631 | } 632 | if(fieldRef.getId() != null) { 633 | String s = fieldRef.getId().toString(); 634 | protoField.fieldOptions.add(new Option("tag", s, Option.ValueType.NUMERIC)); 635 | } 636 | return protoField; 637 | } 638 | 639 | 640 | 641 | private boolean hasUnionType(FieldRefType fieldRef) { 642 | FieldType field = fieldMap.get(fieldRef.getId()); 643 | return field.getUnionDataType() != null; 644 | } 645 | 646 | private MessageField buildAltUnionField(FieldRefType fieldRef) { 647 | FieldType field = fieldMap.get(fieldRef.getId()); 648 | MessageField protoField = null; 649 | if(field.getUnionDataType() != null) { 650 | UnionDataTypeT unionType = field.getUnionDataType(); 651 | if(unionType == UnionDataTypeT.QTY) { 652 | protoField = new MessageField(); 653 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef) + unionType.value()); 654 | protoField.typeName = "Decimal64"; 655 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 656 | protoField.isRepeating = false; 657 | } 658 | else if(unionType == UnionDataTypeT.RESERVED_1000_PLUS || 659 | unionType == UnionDataTypeT.RESERVED_100_PLUS || 660 | unionType == UnionDataTypeT.RESERVED_4000_PLUS) { 661 | protoField = new MessageField(); 662 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef) + unionType.value()); 663 | protoField.scalarType = ScalarType.SFIXED32; 664 | protoField.typeName = protoField.scalarType.toString(); 665 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoScalar; 666 | protoField.isRepeating = false; 667 | } 668 | else if(unionType == UnionDataTypeT.TENOR) { 669 | protoField = new MessageField(); 670 | protoField.fieldName = toProtoFieldName(getFieldName(fieldRef) + unionType.value()); 671 | protoField.typeName = "Tenor"; // this will depend on enc attrs 672 | protoField.scalarOrEnumOrMsg = MessageField.ScalarOrEnumOrMsg.ProtoMsg; 673 | protoField.isRepeating = false; 674 | } 675 | if(protoField != null) { 676 | if(field.getType() != null) { 677 | String s = toProtoEnumFieldName("Datatype", unionType.value()); 678 | protoField.fieldOptions.add(new Option("type", s, Option.ValueType.ENUM_LITERAL)); 679 | } 680 | if(fieldRef.getAdded() != null) { 681 | String added = toVersionFieldName(fieldRef.getAdded()); 682 | protoField.fieldOptions.add(new Option("field_added", added, Option.ValueType.ENUM_LITERAL)); 683 | } 684 | if(fieldRef.getAddedEP() != null) { 685 | String added_ep = fieldRef.getAddedEP().toString(); 686 | protoField.fieldOptions.add(new Option("field_added_ep", added_ep, Option.ValueType.NUMERIC)); 687 | } 688 | if(fieldRef.getDeprecated() != null) { 689 | String s = toVersionFieldName(fieldRef.getDeprecated()); 690 | protoField.fieldOptions.add(new Option("field_deprecated", s, Option.ValueType.ENUM_LITERAL)); 691 | } 692 | if(fieldRef.getId() != null) { 693 | String s = fieldRef.getId().toString(); 694 | protoField.fieldOptions.add(new Option("tag", s, Option.ValueType.NUMERIC)); 695 | } 696 | } 697 | else { 698 | logger.info("Alternate union data type " + unionType.name() + " is not supported."); 699 | } 700 | } 701 | else { 702 | logger.error(fieldRef.toString() + ": attempt to build alternate union field failed."); 703 | } 704 | return protoField; 705 | } 706 | 707 | /* 708 | * Factory routines to build supporting message types. 709 | */ 710 | private Message buildDecimal32() { 711 | Message protoMsg = new Message(); 712 | protoMsg.name = "Decimal32"; 713 | protoMsg.homePackage = codegenSettings.useAltOutputPackaging ? "supporting-messages" : "fix"; 714 | protoMsg.fields.add(new MessageField(ScalarType.SFIXED32, "mantissa")); 715 | protoMsg.fields.add(new MessageField(ScalarType.SFIXED32, "exponent")); 716 | for(int i=0; i unionFields = new ArrayList(); 797 | for(int i=0; i fields = new ArrayList(); 813 | for(Datatype datatype : datatypes.getDatatype()) { 814 | EnumField f = new EnumField(); 815 | f.fieldName = toProtoEnumFieldName(codeSetName, datatype.getName()); 816 | if(datatype.getAdded() != null) { 817 | String added = toVersionFieldName(datatype.getAdded()); 818 | f.fieldOptions.add(new Option("enum_added", added, Option.ValueType.ENUM_LITERAL)); 819 | } 820 | if(datatype.getAddedEP() != null) { 821 | String added_ep = datatype.getAddedEP().toString(); 822 | f.fieldOptions.add(new Option("enum_added_ep", added_ep, Option.ValueType.NUMERIC)); 823 | } 824 | if(datatype.getDeprecated() != null) { 825 | String s = datatype.getDeprecated(); 826 | f.fieldOptions.add(new Option("enum_deprecated", s, Option.ValueType.QUOTED_STRING)); 827 | } 828 | fields.add(f); 829 | } 830 | Collections.sort(fields, fieldCmp); 831 | /* For supporting Enums we will not include the default field. This is because 832 | * these enums are intended for custom option values and are never transmitted 833 | * over the wire. 834 | * WHAT HAPPENS IN OUT CPP CODE WHEN WE ACCESS AN OPTION AND IT'S NOT THERE??? 835 | */ 836 | // testing with it now. 837 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSetName, null)); 838 | defaultField.fieldNum = 0; 839 | protoEnum.fields.add(defaultField); 840 | 841 | for(int i=0; i values = Arrays.asList( 850 | "FIX_2_7", 851 | "FIX_3_0", 852 | "FIX_4_0", 853 | "FIX_4_1", 854 | "FIX_4_2", 855 | "FIX_4_3", 856 | "FIX_4_4", 857 | "FIX_5_0", 858 | "FIXT_1_1", 859 | "FIX_5_0SP1", 860 | "FIX_5_0SP2", 861 | "FIX_LATEST" 862 | ); 863 | Enum protoEnum = new Enum(); 864 | String codeSetName = "Version"; // mock-up a code set name so we can build like the other enums. 865 | protoEnum.name = toProtoEnumName(codeSetName); 866 | protoEnum.homePackage = codegenSettings.useAltOutputPackaging ? "extended-gpb-options" : "fix"; 867 | List fields = new ArrayList(); 868 | for(String v : values) { 869 | fields.add(new EnumField(toProtoEnumFieldName(codeSetName, v))); 870 | } 871 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSetName, null)); 872 | defaultField.fieldNum = 0; 873 | protoEnum.fields.add(defaultField); 874 | for(int i=0; i values = Arrays.asList( 883 | "MIDNIGHT", 884 | "UNIX", 885 | "1900", 886 | "2000" 887 | ); 888 | Enum protoEnum = new Enum(); 889 | String codeSetName = "EpochFieldOption"; // mock-up a code set name so we can build like the other enums. 890 | protoEnum.name = toProtoEnumName(codeSetName); 891 | protoEnum.homePackage = codegenSettings.useAltOutputPackaging ? "extended-gpb-options" : "meta"; 892 | List fields = new ArrayList(); 893 | for(String v : values) { 894 | fields.add(new EnumField(toProtoEnumFieldName(codeSetName, v))); 895 | } 896 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSetName, null)); 897 | defaultField.fieldNum = 0; 898 | protoEnum.fields.add(defaultField); 899 | for(int i=0; i values = Arrays.asList( 908 | "DAYS", 909 | "SECONDS", 910 | "MILLISECONDS", 911 | "MICROSECONDS", 912 | "NANOSECONDS", 913 | "PICOSECONDS" 914 | ); 915 | Enum protoEnum = new Enum(); 916 | String codeSetName = "TimeUnitFieldOption"; // mock-up a code set name so we can build like the other enums. 917 | protoEnum.name = toProtoEnumName(codeSetName); 918 | protoEnum.homePackage = codegenSettings.useAltOutputPackaging ? "extended-gpb-options" : "meta"; 919 | List fields = new ArrayList(); 920 | for(String v : values) { 921 | fields.add(new EnumField(toProtoEnumFieldName(codeSetName, v))); 922 | } 923 | 924 | EnumField defaultField = new EnumField(toProtoEnumFieldName(codeSetName, null)); 925 | defaultField.fieldNum = 0; 926 | protoEnum.fields.add(defaultField); 927 | 928 | for(int i=0; i 1) 991 | sb.append("_"); 992 | sb.append(w); 993 | } 994 | String u = sb.toString(); 995 | StringBuilder sb2 = new StringBuilder(); 996 | regex = "(?<=[a-z,A-Z])(?=[0-9])"; 997 | i = 0; 998 | for(String w : u.split(regex)) { 999 | if(++i > 1) 1000 | sb2.append("_"); 1001 | sb2.append(w); 1002 | } 1003 | return sb2.toString(); 1004 | } 1005 | 1006 | private String toVersionFieldName(String fixVersion) { 1007 | /* 1008 | * The FIX repository represents a FIX version as String with a "." delimiter to separate its various 1009 | * components. Our naming convention requires us to use underscore delimiters. And we also have to 1010 | * account for the enum name "Version". So, for example, "FIX.4.4" will become "VERSION_FIX_4_4". 1011 | */ 1012 | return toProtoEnumFieldName("Version", fixVersion.replace('.', '_')); 1013 | } 1014 | 1015 | } 1016 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/Annotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | public class Annotation { 19 | // Todo: make this simpler. Make value an Object. Get rid of valueType. 20 | 21 | public boolean isStandard; 22 | public String name; 23 | public String value; 24 | public enum ValueType { 25 | QUOTED_STRING, 26 | NUMERIC, 27 | ENUM_LITERAL, 28 | BOOLEAN, 29 | STRUCT // I'm not sure how a struct would work but I'll leave it as a placeholder. 30 | }; 31 | public ValueType valueType; 32 | public Annotation(String name, String value, ValueType valueType) { 33 | this.name = name; 34 | this.value = value; 35 | this.valueType = valueType; 36 | isStandard = false; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | StringBuilder sb = new StringBuilder(); 42 | if(valueType == ValueType.QUOTED_STRING) { 43 | sb.append("$").append(name).append("(\"").append(value).append("\")"); 44 | } 45 | else { 46 | sb.append("$").append(name).append("(").append(value).append(")"); 47 | } 48 | return sb.toString(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/AnnotationDecl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import java.util.List; 19 | import java.util.ArrayList; 20 | 21 | public class AnnotationDecl { 22 | 23 | public enum Target { 24 | FILE, STRUCT, FIELD, UNION, GROUP, ENUM, ENUMERANT, INTERFACE, PARAMETER, ANNOTATION, CONST 25 | } 26 | 27 | private final String dfltHomePkg = "annotation-decls"; 28 | 29 | public String name; 30 | public Object type; // reference to a struct, enum or built-in type (which includes Void). 31 | public List targets; 32 | public String homePackage; 33 | 34 | public AnnotationDecl(String name) { 35 | this.name = name; 36 | targets = new ArrayList(); 37 | homePackage = dfltHomePkg; 38 | } 39 | 40 | public AnnotationDecl(String name, Object type) { 41 | this.name = name; 42 | this.type = type; 43 | targets = new ArrayList(); 44 | homePackage = dfltHomePkg; 45 | } 46 | 47 | public void addTarget(Target target) { 48 | targets.add(target); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | StringBuilder sb = new StringBuilder(); 54 | sb.append("annotation ").append(name).append("("); 55 | int remain = targets.size(); 56 | for(Target t : targets) { 57 | sb.append(t.toString().toLowerCase()); 58 | if(--remain > 0) 59 | sb.append(", "); 60 | } 61 | sb.append(")").append(" :").append(type).append(";"); 62 | return sb.toString(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/CapnpModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import io.fixprotocol.orchestra2proto.IModel; 19 | import io.fixprotocol.orchestra2proto.capnp.Annotation; 20 | import io.fixprotocol.orchestra2proto.capnp.AnnotationDecl; 21 | import io.fixprotocol.orchestra2proto.capnp.Enum; 22 | import io.fixprotocol.orchestra2proto.capnp.EnumField; 23 | 24 | import java.time.ZonedDateTime; 25 | import java.time.format.DateTimeFormatter; 26 | import java.util.ArrayList; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.UUID; 31 | 32 | public class CapnpModel implements IModel { 33 | 34 | public String repoName; 35 | public List enums; 36 | public List messages; 37 | public List annotationDecls; 38 | private final String fileSfx = ".capnp"; 39 | 40 | public CapnpModel(String repoName) { 41 | this.repoName = repoName; 42 | enums = new ArrayList(); 43 | messages = new ArrayList(); 44 | annotationDecls = new ArrayList(); 45 | } 46 | 47 | //public Map toFileSet(boolean singlePackage) { return new HashMap(); }; 48 | 49 | public Map toFileSet() { 50 | 51 | class ProtoFile { 52 | String pkgName; 53 | StringBuilder body; 54 | List requiredImports; 55 | ProtoFile() { 56 | pkgName = "undefined-pkg"; 57 | body = new StringBuilder(); 58 | requiredImports = new ArrayList(); 59 | } 60 | } 61 | Map fileMap = new HashMap(); 62 | 63 | for(AnnotationDecl annDecl : annotationDecls) { 64 | ProtoFile f; 65 | String fileName = annDecl.homePackage == null ? "undefined-pkg.capnp" : annDecl.homePackage.toLowerCase() + fileSfx; 66 | String pkgName = "fix"; 67 | if(!fileMap.containsKey(fileName)) { 68 | f = new ProtoFile(); 69 | f.pkgName = pkgName; 70 | f.body.append("using Cxx = import \"/capnp/c++.capnp\";\n"); 71 | f.body.append("$Cxx.namespace(\"fix::").append(repoName).append("\");\n"); 72 | fileMap.put(fileName, f); 73 | } 74 | else { 75 | f = fileMap.get(fileName); 76 | } 77 | f.body.append(annDecl.toString()); 78 | f.body.append("\n"); 79 | } 80 | 81 | for(Message msg : messages) { 82 | ProtoFile f; 83 | String fileName = msg.homePackage == null ? "undefined-pkg.capnp" : msg.homePackage.toLowerCase() + fileSfx; 84 | String pkgName = "fix"; 85 | if(!fileMap.containsKey(fileName)) { 86 | f = new ProtoFile(); 87 | f.pkgName = pkgName; 88 | fileMap.put(fileName, f); 89 | } 90 | else { 91 | f = fileMap.get(fileName); 92 | } 93 | f.body.append(msg.toString()); 94 | f.body.append("\n"); 95 | for(MessageField field : msg.fields) { 96 | if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoMsg) { 97 | String msgRefName = field.typeName; 98 | for(Message item : messages) { 99 | if(item.name.equals(msgRefName)) { 100 | String itemPkg = item.homePackage; 101 | if(!itemPkg.equals(msg.homePackage)) { 102 | String itemFileName = itemPkg.toLowerCase() + fileSfx; 103 | String itemName = "\"" + itemFileName + "\"" + "." + msgRefName; 104 | if(!f.requiredImports.contains(itemName)) 105 | f.requiredImports.add(itemName); 106 | } 107 | } 108 | } 109 | } 110 | else if(field.scalarOrEnumOrMsg == MessageField.ScalarOrEnumOrMsg.ProtoEnum) { 111 | String enumRefName = field.typeName; 112 | for(Enum item : enums) { 113 | if(item.name.equals(enumRefName)) { 114 | String itemPkg = item.homePackage; 115 | if(!itemPkg.equals(msg.homePackage)) { 116 | String itemFileName = itemPkg.toLowerCase() + fileSfx; 117 | String itemName = "\"" + itemFileName + "\"" + "." + enumRefName; 118 | if(!f.requiredImports.contains(itemName)) 119 | f.requiredImports.add(itemName); 120 | } 121 | } 122 | } 123 | } 124 | // 125 | // Now we need to know if there are annotations and what the annotationDecl homePackages are. 126 | // 127 | for(Annotation ann : field.annotations) { 128 | if(!ann.isStandard) { 129 | for(AnnotationDecl annDecl : annotationDecls) { 130 | if(annDecl.name.equals(ann.name)) { 131 | if(!annDecl.homePackage.equals(msg.homePackage)) { 132 | String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx; 133 | String itemName = "\"" + itemFileName + "\"" + "." + ann.name; 134 | if(!f.requiredImports.contains(itemName)) 135 | f.requiredImports.add(itemName); 136 | } 137 | } 138 | } 139 | } 140 | } 141 | } 142 | // 143 | // Now we need to know if there are annotations and what the annotationDecl homePackages are. 144 | // 145 | for(Annotation ann : msg.annotations) { 146 | if(!ann.isStandard) { 147 | for(AnnotationDecl annDecl : annotationDecls) { 148 | if(annDecl.name.equals(ann.name)) { 149 | if(!annDecl.homePackage.equals(msg.homePackage)) { 150 | String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx; 151 | String itemName = "\"" + itemFileName + "\"" + "." + ann.name; 152 | if(!f.requiredImports.contains(itemName)) 153 | f.requiredImports.add(itemName); 154 | } 155 | } 156 | } 157 | } 158 | } 159 | } 160 | 161 | for(Enum e : enums) { 162 | ProtoFile f; 163 | String fileName = e.homePackage == null ? "undefined-pkg.proto" : e.homePackage.toLowerCase() + fileSfx; 164 | String pkgName = "fix"; 165 | if(!fileMap.containsKey(fileName)) { 166 | f = new ProtoFile(); 167 | f.pkgName = pkgName; 168 | fileMap.put(fileName, f); 169 | } 170 | else { 171 | f = fileMap.get(fileName); 172 | } 173 | f.body.append(e.toString()); 174 | f.body.append("\n"); 175 | for(EnumField field : e.fields) { 176 | // 177 | // Now we need to know if there are annotations and what the annotationDecl homePackages are. 178 | // 179 | for(Annotation ann : field.annotations) { 180 | if(!ann.isStandard) { 181 | for(AnnotationDecl annDecl : annotationDecls) { 182 | if(annDecl.name.equals(ann.name)) { 183 | if(!annDecl.homePackage.equals(e.homePackage)) { 184 | String itemFileName = annDecl.homePackage.toLowerCase() + fileSfx; 185 | String itemName = "\"" + itemFileName + "\"" + "." + ann.name; 186 | if(!f.requiredImports.contains(itemName)) 187 | f.requiredImports.add(itemName); 188 | } 189 | } 190 | } 191 | } 192 | } 193 | } 194 | } 195 | 196 | Map sbMap = new HashMap(); 197 | 198 | for(Map.Entry entry : fileMap.entrySet()) { 199 | String fileName = entry.getKey(); 200 | ProtoFile protoFile = entry.getValue(); 201 | StringBuilder sb = new StringBuilder(); 202 | sb.append(makeFileHeader(fileName, protoFile.pkgName, protoFile.requiredImports)); 203 | sb.append(protoFile.body); 204 | sbMap.put(fileName, sb); 205 | } 206 | 207 | return sbMap; 208 | } 209 | 210 | private StringBuilder makeFileHeader(String fileName, String pkgName, List imports) { 211 | StringBuilder sb = new StringBuilder(); 212 | String dateTimeString = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME); 213 | sb.append("#").append("\n"); 214 | sb.append("#\t").append("FIX 2016 Repository mapping to Cap'n Proto").append("\n"); 215 | sb.append("#").append("\n"); 216 | sb.append("#\t").append("Copyright (c) FIX Trading Community. All Rights Reserved.").append("\n"); 217 | sb.append("#").append("\n"); 218 | sb.append("#\t").append("File:\t\t\t").append(fileName).append("\n"); 219 | sb.append("#\t").append("Source repository:\t" + repoName).append("\n"); 220 | sb.append("#\t").append("Created:\t\t" + dateTimeString).append("\n"); 221 | sb.append("#").append("\n\n"); 222 | 223 | String fid = "0x" + Long.toHexString(UUID.randomUUID().getLeastSignificantBits()); 224 | sb.append("@").append(fid).append(";\n\n"); 225 | 226 | //sb.append("package " + pkgName + ";\n\n"); 227 | 228 | String quotedFileName = "\"" + fileName + "\""; 229 | for(String importName : imports) { 230 | if(!importName.startsWith(quotedFileName)) 231 | sb.append("using import " + importName + ";\n"); 232 | } 233 | sb.append("\n"); 234 | 235 | return sb; 236 | } 237 | 238 | } 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/Enum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import io.fixprotocol.orchestra2proto.capnp.Annotation; 19 | import io.fixprotocol.orchestra2proto.capnp.EnumField; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class Enum { 25 | public String name; 26 | public String homePackage; 27 | public List fields; 28 | public List annotationInstances; 29 | public Enum() { 30 | fields = new ArrayList(); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | final String Indent = " "; 36 | StringBuilder sb = new StringBuilder(); 37 | sb.append("enum "); 38 | sb.append(name); 39 | sb.append(" {\n"); 40 | 41 | // for each field, f, call f.toString(); 42 | int n = 0; 43 | for(EnumField field : fields) { 44 | field.num = n++; 45 | sb.append(Indent); 46 | sb.append(field.toString()); 47 | sb.append("\n"); 48 | } 49 | 50 | sb.append("}\n"); 51 | return sb.toString(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/EnumField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import io.fixprotocol.orchestra2proto.capnp.Annotation; 19 | 20 | import java.util.ArrayList; 21 | 22 | public class EnumField extends Field { 23 | public EnumField() { 24 | annotations = new ArrayList(); 25 | } 26 | public EnumField(String name) { 27 | annotations = new ArrayList(); 28 | this.name = name; 29 | } 30 | @Override 31 | public String toString() { 32 | StringBuilder sb = new StringBuilder(); 33 | sb.append(getNameByConvention()).append(" @").append(num); 34 | int optCount = annotations.size(); 35 | if(optCount > 0) { 36 | sb.append(" "); 37 | int optRemain = optCount; 38 | for(Annotation opt : annotations) { 39 | sb.append(opt.toString()); 40 | if(--optRemain > 0) 41 | sb.append(" "); 42 | } 43 | } 44 | sb.append(";"); 45 | return sb.toString(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import java.util.List; 19 | 20 | public abstract class Field { 21 | public String name; 22 | public Integer num; 23 | public List annotations; 24 | public List comments; 25 | 26 | public String getNameByConvention() { 27 | return name.substring(0, 1).toLowerCase() + name.substring(1); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | public class Message { 24 | public String name; 25 | public String homePackage; 26 | public List annotations; 27 | public List fields; 28 | public List nestedMessages; 29 | public Map> nestedUnions; 30 | 31 | public Message() { 32 | annotations = new ArrayList(); 33 | fields = new ArrayList(); 34 | nestedUnions = new HashMap>(); 35 | } 36 | 37 | public String toString() { 38 | final String Indent = " "; 39 | StringBuilder sb = new StringBuilder(); 40 | sb.append("struct "); 41 | sb.append(name); 42 | sb.append(" "); 43 | for(Annotation ann : annotations) { 44 | sb.append(ann.toString()).append(" "); 45 | } 46 | sb.append("{\n"); 47 | 48 | List processedUnions = new ArrayList(); // Use to track whether already written. 49 | for(MessageField field : fields) { 50 | boolean oneOfMember = false; 51 | for(Map.Entry> entry : nestedUnions.entrySet()) { 52 | String unionName = entry.getKey(); 53 | List unionFieldList = entry.getValue(); 54 | for(Field uf : unionFieldList) { 55 | if(uf == field) { // reference to the same object 56 | oneOfMember = true; 57 | unionName = entry.getKey(); 58 | break; 59 | } 60 | } 61 | if(oneOfMember) { 62 | if(!processedUnions.contains(unionName)) { 63 | sb.append(Indent); 64 | sb.append(makeUnionNameByConvention(unionName)).append(" :union {\n"); 65 | for(MessageField unionField : unionFieldList) { 66 | sb.append(Indent).append(Indent).append(unionField.toString()).append("\n"); 67 | } 68 | sb.append(Indent).append("}\n"); 69 | processedUnions.add(unionName); 70 | } 71 | break; 72 | } 73 | } 74 | if(!oneOfMember) { 75 | sb.append(Indent).append(field.toString()).append("\n"); 76 | } 77 | } 78 | sb.append("}\n"); 79 | return sb.toString(); 80 | } 81 | 82 | public static String makeUnionNameByConvention(String name) { 83 | return name.substring(0, 1).toLowerCase() + name.substring(1) + "Union"; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/MessageField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class MessageField extends Field { 21 | 22 | /* 23 | Consider not implementing toString(). Put a writeMe(MessageField) function into the specific ModelFactory instead. 24 | */ 25 | 26 | public enum ScalarOrEnumOrMsg { ProtoScalar, ProtoEnum, ProtoMsg }; // Maybe call this TypeOfType. MetaType? 27 | public ScalarOrEnumOrMsg scalarOrEnumOrMsg; 28 | 29 | public String typeName; // type fieldName whether type is a scalar, an enum or a message 30 | public ScalarType scalarType; // applicable when is scalar is true 31 | public boolean isRepeating; 32 | 33 | // Let's replace the previous three with just one Object. 34 | public Object typeRef; // will be a Scalar, Enum or Message. Consider create an interface called IFieldTypeCandidate. 35 | 36 | private void init() { 37 | annotations = new ArrayList(); 38 | comments = new ArrayList(); 39 | num = 0; 40 | } 41 | 42 | public MessageField() { 43 | init(); 44 | } 45 | 46 | public MessageField(String name) { 47 | init(); 48 | this.name = name; 49 | } 50 | 51 | public MessageField(String name, ScalarType scalarType) { 52 | init(); 53 | this.name = name; 54 | this.scalarType = scalarType; 55 | typeName = scalarType.toString(); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | StringBuilder sb = new StringBuilder(); 61 | 62 | if(isRepeating) { 63 | sb.append(getNameByConvention()).append(" @").append(num).append(" :List(").append(typeName).append(")"); 64 | } 65 | else { 66 | sb.append(getNameByConvention()).append(" @").append(num).append(" :").append(typeName); 67 | } 68 | 69 | int optCount = annotations.size(); 70 | if(optCount > 0) { 71 | sb.append(" "); 72 | int optRemain = optCount; 73 | for(Annotation opt : annotations) { 74 | sb.append(opt.toString()); 75 | if(--optRemain > 0) 76 | sb.append(" "); 77 | } 78 | } 79 | sb.append(";"); 80 | return sb.toString(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/ScalarType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.capnp; 17 | 18 | public enum ScalarType { 19 | VOID, 20 | BOOL, 21 | INT8, 22 | INT16, 23 | INT32, 24 | INT64, 25 | UINT8, 26 | UINT16, 27 | UINT32, 28 | UINT64, 29 | FLOAT32, 30 | FLOAT64, 31 | TEXT, 32 | DATA; 33 | public String toString() { 34 | return name().substring(0, 1) + name().substring(1).toLowerCase(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/capnp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | /** 17 | * @author gmala 18 | * 19 | */ 20 | package io.fixprotocol.orchestra2proto.capnp; -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | /** 17 | * @author gmala 18 | * 19 | */ 20 | package io.fixprotocol.orchestra2proto; -------------------------------------------------------------------------------- /src/main/java/io/fixprotocol/orchestra2proto/protobuf/Enum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 FIX Protocol Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package io.fixprotocol.orchestra2proto.protobuf; 17 | 18 | import java.util.List; 19 | import java.util.ArrayList; 20 | 21 | public class Enum { 22 | public String name; 23 | public String homePackage; 24 | public List fields; 25 | public List