Skip to content

Commit 3614185

Browse files
inject the buffer name property into the Java code generator
1 parent 46ed35f commit 3614185

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

main/java/uk/co/real_logic/sbe/SbeTool.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public class SbeTool
9999
*/
100100
public static final String TARGET_NAMESPACE = "sbe.target.namespace";
101101

102+
/**
103+
* Specifies the name of the Java buffer to wrap
104+
*/
105+
public static final String JAVA_BUFFER = "sbe.java.buffer";
106+
102107
/**
103108
* Main entry point for the SBE Tool.
104109
*
@@ -123,7 +128,7 @@ public static void main(final String[] args) throws Exception
123128
{
124129
validateAgainstSchema(fileName, xsdFilename);
125130
}
126-
131+
127132
ir = new IrGenerator().generate(parseSchema(fileName), System.getProperty(TARGET_NAMESPACE));
128133
}
129134
else if (fileName.endsWith(".sbeir"))

main/java/uk/co/real_logic/sbe/generation/TargetCodeGenerator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
*/
1616
package uk.co.real_logic.sbe.generation;
1717

18+
import uk.co.real_logic.sbe.SbeTool;
19+
import uk.co.real_logic.sbe.codec.java.DirectBuffer;
1820
import uk.co.real_logic.sbe.generation.cpp98.Cpp98Generator;
21+
import uk.co.real_logic.sbe.generation.cpp98.NamespaceOutputManager;
1922
import uk.co.real_logic.sbe.generation.csharp.CSharpGenerator;
2023
import uk.co.real_logic.sbe.generation.csharp.CSharpNamespaceOutputManager;
21-
import uk.co.real_logic.sbe.generation.cpp98.NamespaceOutputManager;
2224
import uk.co.real_logic.sbe.generation.java.JavaGenerator;
2325
import uk.co.real_logic.sbe.generation.java.JavaMockPojoGenerator;
2426
import uk.co.real_logic.sbe.generation.java.PackageOutputManager;
25-
import uk.co.real_logic.sbe.generation.python.PythonGenerator;
2627
import uk.co.real_logic.sbe.generation.python.ModuleOutputManager;
28+
import uk.co.real_logic.sbe.generation.python.PythonGenerator;
2729
import uk.co.real_logic.sbe.ir.Ir;
2830

2931
import java.io.IOException;
@@ -47,7 +49,9 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir)
4749
public CodeGenerator newInstance(final Ir ir, final String outputDir)
4850
throws IOException
4951
{
50-
return new JavaGenerator(ir, new PackageOutputManager(outputDir, ir.applicableNamespace()));
52+
return new JavaGenerator(ir,
53+
System.getProperty(SbeTool.JAVA_BUFFER, DirectBuffer.class.getName()),
54+
new PackageOutputManager(outputDir, ir.applicableNamespace()));
5155
}
5256
},
5357

main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class JavaGenerator implements CodeGenerator
3838
private final Ir ir;
3939
private final OutputManager outputManager;
4040

41-
public JavaGenerator(final Ir ir, final OutputManager outputManager)
41+
public JavaGenerator(final Ir ir, final String bufferImplementation, final OutputManager outputManager)
4242
throws IOException
4343
{
4444
Verify.notNull(ir, "ir");

test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
public class JavaGeneratorTest
4141
{
42+
private static final String DEFAULT_BUFFER_IMPLEMENTATION = DirectBuffer.class.getName();
43+
4244
private static final ByteOrder BYTE_ORDER = ByteOrder.nativeOrder();
4345
private final StringWriterOutputManager outputManager = new StringWriterOutputManager();
4446
private final DirectBuffer mockBuffer = mock(DirectBuffer.class);
@@ -69,7 +71,7 @@ public void shouldGenerateMessageHeaderStub() throws Exception
6971

7072
when(Short.valueOf(mockBuffer.getShort(bufferOffset + templateIdOffset, BYTE_ORDER))).thenReturn(templateId);
7173

72-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
74+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
7375
javaGenerator.generateMessageHeaderStub();
7476

7577
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -93,7 +95,7 @@ public void shouldGenerateUint8EnumStub() throws Exception
9395
final String className = "BooleanType";
9496
final String fqClassName = ir.applicableNamespace() + "." + className;
9597

96-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
98+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
9799
javaGenerator.generateTypeStubs();
98100

99101
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -110,7 +112,7 @@ public void shouldGenerateCharEnumStub() throws Exception
110112
final String className = "Model";
111113
final String fqClassName = ir.applicableNamespace() + "." + className;
112114

113-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
115+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
114116
javaGenerator.generateTypeStubs();
115117

116118
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -132,7 +134,7 @@ public void shouldGenerateChoiceSetStub() throws Exception
132134

133135
when(Byte.valueOf(mockBuffer.getByte(bufferOffset))).thenReturn(bitset);
134136

135-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
137+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
136138
javaGenerator.generateTypeStubs();
137139

138140
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -164,7 +166,7 @@ public void shouldGenerateCompositeStub() throws Exception
164166
when(Short.valueOf(mockBuffer.getShort(capacityFieldOffset, BYTE_ORDER)))
165167
.thenReturn(Short.valueOf((short)expectedEngineCapacity));
166168

167-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
169+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
168170
javaGenerator.generateTypeStubs();
169171

170172
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -197,7 +199,7 @@ public void shouldGenerateBasicMessage() throws Exception
197199
final String className = "Car";
198200
final String fqClassName = ir.applicableNamespace() + "." + className;
199201

200-
final JavaGenerator javaGenerator = new JavaGenerator(ir, outputManager);
202+
final JavaGenerator javaGenerator = new JavaGenerator(ir, DEFAULT_BUFFER_IMPLEMENTATION, outputManager);
201203
javaGenerator.generate();
202204

203205
final Class<?> clazz = CompilerUtil.compileInMemory(fqClassName, outputManager.getSources());
@@ -216,4 +218,4 @@ public void shouldGenerateBasicMessage() throws Exception
216218
final Integer count = (Integer)groupFlyweight.getClass().getDeclaredMethod("count").invoke(groupFlyweight);
217219
assertThat(count, is(Integer.valueOf(0)));
218220
}
219-
}
221+
}

0 commit comments

Comments
 (0)