Skip to content

Commit 4f6e7be

Browse files
committed
[Java] Generate the metadata methods for encoders as we decoders to preserve symmetry. Issue #554.
1 parent f48c615 commit 4f6e7be

File tree

5 files changed

+332
-0
lines changed

5 files changed

+332
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,8 +2308,11 @@ private CharSequence generateEncoderFields(
23082308
final String propertyName = formatPropertyName(fieldToken.name());
23092309
final String typeName = formatClassName(encoderName(typeToken.name()));
23102310

2311+
generateFieldIdMethod(sb, fieldToken, indent);
2312+
generateFieldSinceVersionMethod(sb, fieldToken, indent);
23112313
generateEncodingOffsetMethod(sb, fieldToken.name(), fieldToken.offset(), indent);
23122314
generateEncodingLengthMethod(sb, fieldToken.name(), typeToken.encodedLength(), indent);
2315+
generateFieldMetaAttributeMethod(sb, fieldToken, indent);
23132316

23142317
switch (typeToken.signal())
23152318
{

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public void limit(final int limit)
9494
this.limit = limit;
9595
}
9696

97+
public static int irIdId()
98+
{
99+
return 1;
100+
}
101+
102+
public static int irIdSinceVersion()
103+
{
104+
return 0;
105+
}
106+
97107
public static int irIdEncodingOffset()
98108
{
99109
return 0;
@@ -104,6 +114,19 @@ public static int irIdEncodingLength()
104114
return 4;
105115
}
106116

117+
public static String irIdMetaAttribute(final MetaAttribute metaAttribute)
118+
{
119+
switch (metaAttribute)
120+
{
121+
case EPOCH: return "unix";
122+
case TIME_UNIT: return "nanosecond";
123+
case SEMANTIC_TYPE: return "";
124+
case PRESENCE: return "required";
125+
}
126+
127+
return "";
128+
}
129+
107130
public static int irIdNullValue()
108131
{
109132
return -2147483648;
@@ -126,6 +149,16 @@ public FrameCodecEncoder irId(final int value)
126149
}
127150

128151

152+
public static int irVersionId()
153+
{
154+
return 2;
155+
}
156+
157+
public static int irVersionSinceVersion()
158+
{
159+
return 0;
160+
}
161+
129162
public static int irVersionEncodingOffset()
130163
{
131164
return 4;
@@ -136,6 +169,19 @@ public static int irVersionEncodingLength()
136169
return 4;
137170
}
138171

172+
public static String irVersionMetaAttribute(final MetaAttribute metaAttribute)
173+
{
174+
switch (metaAttribute)
175+
{
176+
case EPOCH: return "unix";
177+
case TIME_UNIT: return "nanosecond";
178+
case SEMANTIC_TYPE: return "";
179+
case PRESENCE: return "required";
180+
}
181+
182+
return "";
183+
}
184+
139185
public static int irVersionNullValue()
140186
{
141187
return -2147483648;
@@ -158,6 +204,16 @@ public FrameCodecEncoder irVersion(final int value)
158204
}
159205

160206

207+
public static int schemaVersionId()
208+
{
209+
return 3;
210+
}
211+
212+
public static int schemaVersionSinceVersion()
213+
{
214+
return 0;
215+
}
216+
161217
public static int schemaVersionEncodingOffset()
162218
{
163219
return 8;
@@ -168,6 +224,19 @@ public static int schemaVersionEncodingLength()
168224
return 4;
169225
}
170226

227+
public static String schemaVersionMetaAttribute(final MetaAttribute metaAttribute)
228+
{
229+
switch (metaAttribute)
230+
{
231+
case EPOCH: return "unix";
232+
case TIME_UNIT: return "nanosecond";
233+
case SEMANTIC_TYPE: return "";
234+
case PRESENCE: return "required";
235+
}
236+
237+
return "";
238+
}
239+
171240
public static int schemaVersionNullValue()
172241
{
173242
return -2147483648;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public static int blockLengthEncodingLength()
4949
return 2;
5050
}
5151

52+
public static int blockLengthSinceVersion()
53+
{
54+
return 0;
55+
}
56+
5257
public static int blockLengthNullValue()
5358
{
5459
return 65535;
@@ -80,6 +85,11 @@ public static int templateIdEncodingLength()
8085
return 2;
8186
}
8287

88+
public static int templateIdSinceVersion()
89+
{
90+
return 0;
91+
}
92+
8393
public static int templateIdNullValue()
8494
{
8595
return 65535;
@@ -111,6 +121,11 @@ public static int schemaIdEncodingLength()
111121
return 2;
112122
}
113123

124+
public static int schemaIdSinceVersion()
125+
{
126+
return 0;
127+
}
128+
114129
public static int schemaIdNullValue()
115130
{
116131
return 65535;
@@ -142,6 +157,11 @@ public static int versionEncodingLength()
142157
return 2;
143158
}
144159

160+
public static int versionSinceVersion()
161+
{
162+
return 0;
163+
}
164+
145165
public static int versionNullValue()
146166
{
147167
return 65535;

0 commit comments

Comments
 (0)