Skip to content

Commit 02362e6

Browse files
committed
[Java] ref types did not carry through there type into the IR. Now added at Token.referencedName() and use in JavaGenerator. Issue #435.
1 parent 73c6015 commit 02362e6

16 files changed

+337
-91
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ private void generateDataTypedEncoder(
951951
private void generateBitSet(final List<Token> tokens) throws IOException
952952
{
953953
final Token token = tokens.get(0);
954-
final String bitSetName = formatClassName(token.name());
954+
final String bitSetName = formatClassName(token.contextualTypeName());
955955
final String decoderName = decoderName(bitSetName);
956956
final String encoderName = encoderName(bitSetName);
957957
final List<Token> messageBody = getMessageBody(tokens);
@@ -1000,7 +1000,7 @@ private void generateCompositeFlyweightHeader(
10001000

10011001
private void generateEnum(final List<Token> tokens) throws IOException
10021002
{
1003-
final String enumName = formatClassName(tokens.get(0).name());
1003+
final String enumName = formatClassName(tokens.get(0).contextualTypeName());
10041004

10051005
try (Writer out = outputManager.createOutput(enumName))
10061006
{
@@ -1019,7 +1019,7 @@ private void generateEnum(final List<Token> tokens) throws IOException
10191019
private void generateComposite(final List<Token> tokens) throws IOException
10201020
{
10211021
final Token token = tokens.get(0);
1022-
final String compositeName = formatClassName(token.name());
1022+
final String compositeName = formatClassName(token.contextualTypeName());
10231023
final String decoderName = decoderName(compositeName);
10241024
final String encoderName = encoderName(compositeName);
10251025

@@ -1033,7 +1033,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
10331033
{
10341034
final Token encodingToken = tokens.get(i);
10351035
final String propertyName = formatPropertyName(encodingToken.name());
1036-
final String typeName = formatClassName(decoderName(encodingToken.name()));
1036+
final String typeName = formatClassName(decoderName(encodingToken.contextualTypeName()));
10371037

10381038
final StringBuilder sb = new StringBuilder();
10391039
generateEncodingOffsetMethod(sb, propertyName, encodingToken.offset(), BASE_INDENT);
@@ -1083,7 +1083,7 @@ private void generateComposite(final List<Token> tokens) throws IOException
10831083
{
10841084
final Token encodingToken = tokens.get(i);
10851085
final String propertyName = formatPropertyName(encodingToken.name());
1086-
final String typeName = formatClassName(encoderName(encodingToken.name()));
1086+
final String typeName = formatClassName(encoderName(encodingToken.contextualTypeName()));
10871087

10881088
final StringBuilder sb = new StringBuilder();
10891089
generateEncodingOffsetMethod(sb, propertyName, encodingToken.offset(), BASE_INDENT);
@@ -2256,7 +2256,7 @@ private CharSequence generateEnumDecoder(
22562256
final Token token,
22572257
final String indent)
22582258
{
2259-
final String enumName = formatClassName(token.name());
2259+
final String enumName = formatClassName(token.contextualTypeName());
22602260
final Encoding encoding = token.encoding();
22612261

22622262
if (token.isConstantEncoding())
@@ -2296,7 +2296,7 @@ private CharSequence generateEnumEncoder(
22962296
return "";
22972297
}
22982298

2299-
final String enumName = formatClassName(token.name());
2299+
final String enumName = formatClassName(token.contextualTypeName());
23002300
final Encoding encoding = token.encoding();
23012301
final int offset = token.offset();
23022302

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private static int captureMessage(final List<Token> tokens, final int index, fin
151151

152152
private void decodeFrame()
153153
{
154-
frameDecoder.wrap(directBuffer, offset, frameDecoder.sbeBlockLength(), 0);
154+
frameDecoder.wrap(directBuffer, offset, frameDecoder.sbeBlockLength(), FrameCodecDecoder.SCHEMA_VERSION);
155155

156156
irId = frameDecoder.irId();
157157

@@ -183,7 +183,7 @@ private Token decodeToken()
183183
final Token.Builder tokenBuilder = new Token.Builder();
184184
final Encoding.Builder encBuilder = new Encoding.Builder();
185185

186-
tokenDecoder.wrap(directBuffer, offset, tokenDecoder.sbeBlockLength(), 0);
186+
tokenDecoder.wrap(directBuffer, offset, tokenDecoder.sbeBlockLength(), TokenCodecDecoder.SCHEMA_VERSION);
187187

188188
tokenBuilder
189189
.offset(tokenDecoder.tokenOffset())
@@ -222,6 +222,9 @@ private Token decodeToken()
222222
final String description = tokenDecoder.description();
223223
tokenBuilder.description(description.isEmpty() ? null : description);
224224

225+
final String referencedName = tokenDecoder.referencedName();
226+
tokenBuilder.referencedName(referencedName.isEmpty() ? null : referencedName);
227+
225228
offset += tokenDecoder.encodedLength();
226229

227230
return tokenBuilder.encoding(encBuilder.build()).build();

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrEncoder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ private int encodeToken(final Token token)
194194

195195
final byte[] descriptionBytes = getBytes(token.description(), descriptionCharacterEncoding());
196196
tokenEncoder.putDescription(descriptionBytes, 0, descriptionBytes.length);
197+
198+
final byte[] referencedNameBytes = getBytes(token.referencedName(), referencedNameCharacterEncoding());
199+
tokenEncoder.putReferencedName(referencedNameBytes, 0, referencedNameBytes.length);
197200
}
198201
catch (final UnsupportedEncodingException ex)
199202
{

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public enum VersionContext
9898

9999
private final Signal signal;
100100
private final String name;
101+
private final String referencedName;
101102
private final String description;
102103
private final int id;
103104
private final int version;
@@ -112,6 +113,7 @@ public enum VersionContext
112113
*
113114
* @param signal for the token role.
114115
* @param name of the token in the message.
116+
* @param referencedName of the type when created from a ref in a composite.
115117
* @param description of what the token is for.
116118
* @param id as the identifier in the message declaration.
117119
* @param version application within the template.
@@ -124,6 +126,7 @@ public enum VersionContext
124126
public Token(
125127
final Signal signal,
126128
final String name,
129+
final String referencedName,
127130
final String description,
128131
final int id,
129132
final int version,
@@ -139,6 +142,7 @@ public Token(
139142

140143
this.signal = signal;
141144
this.name = name;
145+
this.referencedName = referencedName;
142146
this.description = description;
143147
this.id = id;
144148
this.version = version;
@@ -169,6 +173,16 @@ public String name()
169173
return name;
170174
}
171175

176+
/**
177+
* Get the name of the type when this is from a reference.
178+
*
179+
* @return the name of the type when this is from a reference.
180+
*/
181+
public String referencedName()
182+
{
183+
return referencedName;
184+
}
185+
172186
/**
173187
* Description for what the token is to be used for.
174188
*
@@ -210,6 +224,16 @@ public int deprecated()
210224
return deprecated;
211225
}
212226

227+
/**
228+
* Get the name of the type that should be used in context.
229+
*
230+
* @return the name of the type that should be used in context.
231+
*/
232+
public String contextualTypeName()
233+
{
234+
return null == referencedName ? name : referencedName;
235+
}
236+
213237
/**
214238
* The context in which the version field should be interpreted.
215239
*
@@ -344,6 +368,7 @@ public String toString()
344368
return "Token{" +
345369
"signal=" + signal +
346370
", name='" + name + '\'' +
371+
", referencedName='" + referencedName + '\'' +
347372
", description='" + description + '\'' +
348373
", id=" + id +
349374
", version=" + version +
@@ -359,6 +384,7 @@ public static class Builder
359384
{
360385
private Signal signal;
361386
private String name;
387+
private String referencedName;
362388
private String description;
363389
private int id = INVALID_ID;
364390
private int version = 0;
@@ -380,6 +406,12 @@ public Builder name(final String name)
380406
return this;
381407
}
382408

409+
public Builder referencedName(final String referencedName)
410+
{
411+
this.referencedName = referencedName;
412+
return this;
413+
}
414+
383415
public Builder description(final String description)
384416
{
385417
this.description = description;
@@ -431,7 +463,17 @@ public Builder encoding(final Encoding encoding)
431463
public Token build()
432464
{
433465
return new Token(
434-
signal, name, description, id, version, deprecated, size, offset, componentTokenCount, encoding);
466+
signal,
467+
name,
468+
referencedName,
469+
description,
470+
id,
471+
version,
472+
deprecated,
473+
size,
474+
offset,
475+
componentTokenCount,
476+
encoding);
435477
}
436478
}
437479
}

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecDecoder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class FrameCodecDecoder
1111
public static final int BLOCK_LENGTH = 12;
1212
public static final int TEMPLATE_ID = 1;
1313
public static final int SCHEMA_ID = 1;
14-
public static final int SCHEMA_VERSION = 1;
14+
public static final int SCHEMA_VERSION = 0;
1515

1616
private final FrameCodecDecoder parentMessage = this;
1717
private DirectBuffer buffer;
@@ -522,30 +522,30 @@ public StringBuilder appendTo(final StringBuilder builder)
522522
}
523523
builder.append(BLOCK_LENGTH);
524524
builder.append("):");
525-
//Token{signal=BEGIN_FIELD, name='irId', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
526-
//Token{signal=ENCODING, name='int32', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
525+
//Token{signal=BEGIN_FIELD, name='irId', referencedName='null', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
526+
//Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
527527
builder.append("irId=");
528528
builder.append(irId());
529529
builder.append('|');
530-
//Token{signal=BEGIN_FIELD, name='irVersion', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=4, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
531-
//Token{signal=ENCODING, name='int32', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=4, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
530+
//Token{signal=BEGIN_FIELD, name='irVersion', referencedName='null', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=4, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
531+
//Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=4, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
532532
builder.append("irVersion=");
533533
builder.append(irVersion());
534534
builder.append('|');
535-
//Token{signal=BEGIN_FIELD, name='schemaVersion', description='null', id=3, version=0, deprecated=0, encodedLength=0, offset=8, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
536-
//Token{signal=ENCODING, name='int32', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=8, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
535+
//Token{signal=BEGIN_FIELD, name='schemaVersion', referencedName='null', description='null', id=3, version=0, deprecated=0, encodedLength=0, offset=8, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
536+
//Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=8, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
537537
builder.append("schemaVersion=");
538538
builder.append(schemaVersion());
539539
builder.append('|');
540-
//Token{signal=BEGIN_VAR_DATA, name='packageName', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=12, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
540+
//Token{signal=BEGIN_VAR_DATA, name='packageName', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=12, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
541541
builder.append("packageName=");
542542
builder.append(packageName());
543543
builder.append('|');
544-
//Token{signal=BEGIN_VAR_DATA, name='namespaceName', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
544+
//Token{signal=BEGIN_VAR_DATA, name='namespaceName', referencedName='null', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
545545
builder.append("namespaceName=");
546546
builder.append(namespaceName());
547547
builder.append('|');
548-
//Token{signal=BEGIN_VAR_DATA, name='semanticVersion', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
548+
//Token{signal=BEGIN_VAR_DATA, name='semanticVersion', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}}
549549
builder.append("semanticVersion=");
550550
builder.append(semanticVersion());
551551

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class FrameCodecEncoder
1111
public static final int BLOCK_LENGTH = 12;
1212
public static final int TEMPLATE_ID = 1;
1313
public static final int SCHEMA_ID = 1;
14-
public static final int SCHEMA_VERSION = 1;
14+
public static final int SCHEMA_VERSION = 0;
1515

1616
private final FrameCodecEncoder parentMessage = this;
1717
private MutableDirectBuffer buffer;

0 commit comments

Comments
 (0)