Skip to content

Commit 8557944

Browse files
committed
[Java/cpp]: Added semanticVersion to IR.
1 parent 95ad4ad commit 8557944

File tree

19 files changed

+263
-76
lines changed

19 files changed

+263
-76
lines changed

examples/java/uk/co/real_logic/sbe/examples/OtfExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(final String[] args) throws Exception
5151

5252
// Now lets decode the schema IR so we have IR objects.
5353
encodedSchemaBuffer.flip();
54-
final IntermediateRepresentation ir = decodeIr(encodedSchemaBuffer);
54+
final Ir ir = decodeIr(encodedSchemaBuffer);
5555

5656
// From the IR we can create OTF decoder for message headers.
5757
final OtfHeaderDecoder headerDecoder = new OtfHeaderDecoder(ir.headerStructure());
@@ -90,7 +90,7 @@ private static void encodeSchema(final ByteBuffer buffer)
9090
try (final InputStream in = new FileInputStream("examples/resources/TestSchema.xml"))
9191
{
9292
final MessageSchema schema = XmlSchemaParser.parse(in);
93-
final IntermediateRepresentation ir = new IrGenerator().generate(schema);
93+
final Ir ir = new IrGenerator().generate(schema);
9494
new IrEncoder(buffer, ir).encode();
9595
}
9696
}
@@ -112,7 +112,7 @@ private static void encodeTestMessage(final ByteBuffer buffer)
112112
buffer.position(bufferOffset);
113113
}
114114

115-
private static IntermediateRepresentation decodeIr(final ByteBuffer buffer)
115+
private static Ir decodeIr(final ByteBuffer buffer)
116116
throws IOException
117117
{
118118
final IrDecoder irDecoder = new IrDecoder(buffer);

main/cpp/otf_api/IrCollection.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace on_the_fly {
4545

4646
/**
4747
* \brief Collection that holds the Ir for several message template IDs as well as a header for
48-
* dispatching them. Equivalent to the Java IntermediateRepresentation class.
48+
* dispatching them. Equivalent to the Java Ir class.
4949
*/
5050
class IrCollection
5151
{
@@ -200,11 +200,13 @@ class IrCollection
200200
char tmp[256];
201201

202202
frame.wrapForDecode(buffer_, offset, frame.blockLength(), frame.templateVersion());
203-
tmpLen = frame.getPackageName(tmp, sizeof(tmp));
204-
frame.getNamespaceName(tmp, sizeof(tmp));
205203

204+
tmpLen = frame.getPackageName(tmp, sizeof(tmp));
206205
::std::cout << "Reading IR package=\"" << std::string(tmp, tmpLen) << "\"" << ::std::endl;
207206

207+
frame.getNamespaceName(tmp, sizeof(tmp));
208+
frame.getSemanticVersion(tmp, sizeof(tmp));
209+
208210
offset += frame.size();
209211

210212
headerLength_ = readHeader(offset);

main/cpp/otf_api/Listener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int Listener::subscribe(OnNext *onNext,
111111
{
112112
char message[1024];
113113

114-
::snprintf(message, sizeof(message)-1, "no IR found for message with templateId=%lld and version=%lld", templateId_, templateVersion_);
114+
::snprintf(message, sizeof(message)-1, "no IR found for message with templateId=%ld and version=%ld", templateId_, templateVersion_);
115115
onError_->onError(Error(message));
116116
result = -1;
117117
}

main/cpp/uk_co_real_logic_sbe_ir_generated/FrameCodec.hpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,74 @@ class FrameCodec
339339
position(position() + (sbe_uint64_t)length);
340340
return length;
341341
}
342+
343+
static const char *semanticVersionCharacterEncoding()
344+
{
345+
return "UTF-8";
346+
}
347+
348+
static int semanticVersionSinceVersion(void)
349+
{
350+
return 0;
351+
}
352+
353+
bool semanticVersionInActingVersion(void)
354+
{
355+
return (actingVersion_ >= 0) ? true : false;
356+
}
357+
358+
static int semanticVersionSchemaId(void)
359+
{
360+
return 5;
361+
}
362+
363+
364+
static const char *semanticVersionMetaAttribute(const MetaAttribute::Attribute metaAttribute)
365+
{
366+
switch (metaAttribute)
367+
{
368+
case MetaAttribute::EPOCH: return "unix";
369+
case MetaAttribute::TIME_UNIT: return "nanosecond";
370+
case MetaAttribute::SEMANTIC_TYPE: return "";
371+
}
372+
373+
return "";
374+
}
375+
376+
sbe_int64_t semanticVersionLength(void) const
377+
{
378+
return (*((sbe_uint8_t *)(buffer_ + position())));
379+
}
380+
381+
const char *semanticVersion(void)
382+
{
383+
const char *fieldPtr = (buffer_ + position() + 1);
384+
position(position() + 1 + *((sbe_uint8_t *)(buffer_ + position())));
385+
return fieldPtr;
386+
}
387+
388+
int getSemanticVersion(char *dst, const int length)
389+
{
390+
sbe_uint64_t sizeOfLengthField = 1;
391+
sbe_uint64_t lengthPosition = position();
392+
position(lengthPosition + sizeOfLengthField);
393+
sbe_int64_t dataLength = (*((sbe_uint8_t *)(buffer_ + lengthPosition)));
394+
int bytesToCopy = (length < dataLength) ? length : dataLength;
395+
::memcpy(dst, buffer_ + position(), bytesToCopy);
396+
position(position() + (sbe_uint64_t)dataLength);
397+
return bytesToCopy;
398+
}
399+
400+
int putSemanticVersion(const char *src, const int length)
401+
{
402+
sbe_uint64_t sizeOfLengthField = 1;
403+
sbe_uint64_t lengthPosition = position();
404+
*((sbe_uint8_t *)(buffer_ + lengthPosition)) = ((sbe_uint8_t)length);
405+
position(lengthPosition + sizeOfLengthField);
406+
::memcpy(buffer_ + position(), src, length);
407+
position(position() + (sbe_uint64_t)length);
408+
return length;
409+
}
342410
};
343411
}
344412
#endif

main/csharp/ir/generated/FrameCodec.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,46 @@ public int SetNamespaceName(byte[] src, int srcOffset, int length)
214214

215215
return length;
216216
}
217+
218+
public const int SemanticVersionSchemaId = 5;
219+
220+
public const string SemanticVersionCharacterEncoding = "UTF-8";
221+
222+
223+
public static string SemanticVersionMetaAttribute(MetaAttribute metaAttribute)
224+
{
225+
switch (metaAttribute)
226+
{
227+
case MetaAttribute.Epoch: return "unix";
228+
case MetaAttribute.TimeUnit: return "nanosecond";
229+
case MetaAttribute.SemanticType: return "";
230+
}
231+
232+
return "";
233+
}
234+
235+
public int GetSemanticVersion(byte[] dst, int dstOffset, int length)
236+
{
237+
const int sizeOfLengthField = 1;
238+
int limit = Limit;
239+
_buffer.CheckLimit(limit + sizeOfLengthField);
240+
int dataLength = _buffer.Uint8Get(limit);
241+
int bytesCopied = Math.Min(length, dataLength);
242+
Limit = limit + sizeOfLengthField + dataLength;
243+
_buffer.GetBytes(limit + sizeOfLengthField, dst, dstOffset, bytesCopied);
244+
245+
return bytesCopied;
246+
}
247+
248+
public int SetSemanticVersion(byte[] src, int srcOffset, int length)
249+
{
250+
const int sizeOfLengthField = 1;
251+
int limit = Limit;
252+
Limit = limit + sizeOfLengthField + length;
253+
_buffer.Uint8Put(limit, (byte)length);
254+
_buffer.SetBytes(limit + sizeOfLengthField, src, srcOffset, length);
255+
256+
return length;
257+
}
217258
}
218259
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import uk.co.real_logic.sbe.generation.CodeGenerator;
2020
import uk.co.real_logic.sbe.generation.TargetCodeGenerator;
21+
import uk.co.real_logic.sbe.ir.Ir;
2122
import uk.co.real_logic.sbe.ir.IrDecoder;
2223
import uk.co.real_logic.sbe.ir.IrEncoder;
23-
import uk.co.real_logic.sbe.ir.IntermediateRepresentation;
2424
import uk.co.real_logic.sbe.xml.IrGenerator;
2525
import uk.co.real_logic.sbe.xml.MessageSchema;
2626
import uk.co.real_logic.sbe.xml.XmlSchemaParser;
@@ -98,7 +98,7 @@ public static void main(final String[] args) throws Exception
9898

9999
for (final String fileName : args)
100100
{
101-
IntermediateRepresentation ir = null;
101+
Ir ir = null;
102102

103103
if (fileName.endsWith(".xml"))
104104
{
@@ -159,7 +159,7 @@ public static MessageSchema parseSchema(final String messageSchemaFileName) thro
159159
* @param targetLanguage for the generated code.
160160
* @throws Exception if an error occurs while generating the code.
161161
*/
162-
public static void generate(final IntermediateRepresentation ir,
162+
public static void generate(final Ir ir,
163163
final String outputDirName,
164164
final String targetLanguage)
165165
throws Exception

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import uk.co.real_logic.sbe.generation.cpp98.NamespaceOutputManager;
2222
import uk.co.real_logic.sbe.generation.java.JavaGenerator;
2323
import uk.co.real_logic.sbe.generation.java.PackageOutputManager;
24-
import uk.co.real_logic.sbe.ir.IntermediateRepresentation;
24+
import uk.co.real_logic.sbe.ir.Ir;
2525

2626
import java.io.IOException;
2727

@@ -32,7 +32,7 @@ public enum TargetCodeGenerator
3232
{
3333
JAVA()
3434
{
35-
public CodeGenerator newInstance(final IntermediateRepresentation ir, final String outputDir)
35+
public CodeGenerator newInstance(final Ir ir, final String outputDir)
3636
throws IOException
3737
{
3838
return new JavaGenerator(ir, new PackageOutputManager(outputDir, ir.applicableNamespace()));
@@ -41,7 +41,7 @@ public CodeGenerator newInstance(final IntermediateRepresentation ir, final Stri
4141

4242
CPP98()
4343
{
44-
public CodeGenerator newInstance(final IntermediateRepresentation ir, final String outputDir)
44+
public CodeGenerator newInstance(final Ir ir, final String outputDir)
4545
throws IOException
4646
{
4747
return new Cpp98Generator(ir, new NamespaceOutputManager(outputDir, ir.applicableNamespace()));
@@ -50,7 +50,7 @@ public CodeGenerator newInstance(final IntermediateRepresentation ir, final Stri
5050

5151
CSHARP()
5252
{
53-
public CodeGenerator newInstance(final IntermediateRepresentation ir, final String outputDir)
53+
public CodeGenerator newInstance(final Ir ir, final String outputDir)
5454
throws IOException
5555
{
5656
return new CSharpGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
@@ -66,7 +66,7 @@ public CodeGenerator newInstance(final IntermediateRepresentation ir, final Stri
6666
* @return a new instance of a {@link CodeGenerator} for the given target language.
6767
* @throws IOException if an error occurs when dealing with the output directory.
6868
*/
69-
public abstract CodeGenerator newInstance(final IntermediateRepresentation ir, final String outputDir) throws IOException;
69+
public abstract CodeGenerator newInstance(final Ir ir, final String outputDir) throws IOException;
7070

7171
/**
7272
* Do a case insensitive lookup of a target language for code generation.

main/java/uk/co/real_logic/sbe/generation/cpp98/Cpp98Generator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import uk.co.real_logic.sbe.generation.CodeGenerator;
2020
import uk.co.real_logic.sbe.generation.OutputManager;
2121
import uk.co.real_logic.sbe.ir.Encoding;
22-
import uk.co.real_logic.sbe.ir.IntermediateRepresentation;
22+
import uk.co.real_logic.sbe.ir.Ir;
2323
import uk.co.real_logic.sbe.ir.Signal;
2424
import uk.co.real_logic.sbe.ir.Token;
2525
import uk.co.real_logic.sbe.util.Verify;
@@ -39,10 +39,10 @@ public class Cpp98Generator implements CodeGenerator
3939
private static final String BASE_INDENT = "";
4040
private static final String INDENT = " ";
4141

42-
private final IntermediateRepresentation ir;
42+
private final Ir ir;
4343
private final OutputManager outputManager;
4444

45-
public Cpp98Generator(final IntermediateRepresentation ir, final OutputManager outputManager)
45+
public Cpp98Generator(final Ir ir, final OutputManager outputManager)
4646
throws IOException
4747
{
4848
Verify.notNull(ir, "ir");

main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import uk.co.real_logic.sbe.generation.CodeGenerator;
2121
import uk.co.real_logic.sbe.generation.OutputManager;
2222
import uk.co.real_logic.sbe.ir.Encoding;
23-
import uk.co.real_logic.sbe.ir.IntermediateRepresentation;
23+
import uk.co.real_logic.sbe.ir.Ir;
2424
import uk.co.real_logic.sbe.ir.Signal;
2525
import uk.co.real_logic.sbe.ir.Token;
2626
import uk.co.real_logic.sbe.util.Verify;
@@ -43,10 +43,10 @@ public class CSharpGenerator implements CodeGenerator
4343
private static final String BASE_INDENT = "";
4444
private static final String INDENT = " ";
4545

46-
private final IntermediateRepresentation ir;
46+
private final Ir ir;
4747
private final OutputManager outputManager;
4848

49-
public CSharpGenerator(final IntermediateRepresentation ir, final OutputManager outputManager)
49+
public CSharpGenerator(final Ir ir, final OutputManager outputManager)
5050
throws IOException
5151
{
5252
Verify.notNull(ir, "ir");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public class JavaGenerator implements CodeGenerator
3838
private static final String BASE_INDENT = "";
3939
private static final String INDENT = " ";
4040

41-
private final IntermediateRepresentation ir;
41+
private final Ir ir;
4242
private final OutputManager outputManager;
4343

44-
public JavaGenerator(final IntermediateRepresentation ir, final OutputManager outputManager)
44+
public JavaGenerator(final Ir ir, final OutputManager outputManager)
4545
throws IOException
4646
{
4747
Verify.notNull(ir, "ir");

0 commit comments

Comments
 (0)