Skip to content

Commit 924711e

Browse files
committed
[Java]: Make time unit a string in the IR to be interpreted by layer 7 applications.
1 parent 2f4e6e4 commit 924711e

File tree

5 files changed

+15
-77
lines changed

5 files changed

+15
-77
lines changed

main/java/uk/co/real_logic/sbe/ir/Encoding.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import uk.co.real_logic.sbe.util.Verify;
2121

2222
import java.nio.ByteOrder;
23-
import java.util.concurrent.TimeUnit;
2423

2524
/**
2625
* Optional encoding settings that can be associated with {@link Token}s.
@@ -51,7 +50,7 @@ public static enum Presence
5150
private final PrimitiveValue constVal;
5251
private final String characterEncoding;
5352
private final String epoch;
54-
private final TimeUnit timeUnit;
53+
private final String timeUnit;
5554
private final String semanticType;
5655

5756
public Encoding()
@@ -78,7 +77,7 @@ public Encoding(final PrimitiveType primitiveType,
7877
final PrimitiveValue constVal,
7978
final String characterEncoding,
8079
final String epoch,
81-
final TimeUnit timeUnit,
80+
final String timeUnit,
8281
final String semanticType)
8382
{
8483
Verify.notNull(presence, "presence");
@@ -234,11 +233,11 @@ public String epoch()
234233
}
235234

236235
/**
237-
* The {@link TimeUnit} of the timestamp.
236+
* The time unit of the timestamp.
238237
*
239-
* @return the {@link TimeUnit} of the timestamp.
238+
* @return the time unit of the timestamp.
240239
*/
241-
public TimeUnit timeUnit()
240+
public String timeUnit()
242241
{
243242
return timeUnit;
244243
}
@@ -284,7 +283,7 @@ public static class Builder
284283
private PrimitiveValue constVal = null;
285284
private String characterEncoding = "";
286285
private String epoch = null;
287-
private TimeUnit timeUnit = null;
286+
private String timeUnit = null;
288287
private String semanticType = null;
289288

290289
public Builder primitiveType(final PrimitiveType primitiveType)
@@ -341,7 +340,7 @@ public Builder epoch(final String epoch)
341340
return this;
342341
}
343342

344-
public Builder timeUnit(final TimeUnit timeUnit)
343+
public Builder timeUnit(final String timeUnit)
345344
{
346345
this.timeUnit = timeUnit;
347346
return this;

main/java/uk/co/real_logic/sbe/xml/Field.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Field
4444
private int computedOffset; // used to hold the calculated offset of this field from top level <message> or <group>
4545
private int computedBlockLength; // used to hold the calculated block length of this group
4646
private final String epoch; // optional, epoch from which a timestamps start, defaults to "unix"
47-
private final TimeUnit timeUnit; // optional, defaults to TimeUnit.NANOSECOND.
47+
private final String timeUnit; // optional, defaults to "nanosecond".
4848

4949
public Field(final String name,
5050
final String description,
@@ -58,7 +58,7 @@ public Field(final String name,
5858
final boolean variableLength,
5959
final int sinceVersion,
6060
final String epoch,
61-
final TimeUnit timeUnit)
61+
final String timeUnit)
6262
{
6363
this.name = name;
6464
this.description = description;
@@ -176,7 +176,7 @@ public String epoch()
176176
return epoch;
177177
}
178178

179-
public TimeUnit timeUnit()
179+
public String timeUnit()
180180
{
181181
return timeUnit;
182182
}
@@ -217,7 +217,7 @@ public static class Builder
217217
private boolean variableLength;
218218
private int sinceVersion = 0;
219219
private String epoch;
220-
private TimeUnit timeUnit;
220+
private String timeUnit;
221221

222222
public Builder name(final String name)
223223
{
@@ -291,7 +291,7 @@ public Builder epoch(final String epoch)
291291
return this;
292292
}
293293

294-
public Builder timeUnit(final TimeUnit timeUnit)
294+
public Builder timeUnit(final String timeUnit)
295295
{
296296
this.timeUnit = timeUnit;
297297
return this;

main/java/uk/co/real_logic/sbe/xml/IrGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,13 @@ private void add(final EncodedDataType type, final int offset, final Field field
293293
final Encoding.Builder encodingBuilder = new Encoding.Builder()
294294
.primitiveType(type.primitiveType())
295295
.byteOrder(byteOrder)
296+
.semanticType(semanticTypeOf(type, field))
296297
.characterEncoding(type.characterEncoding());
297298

298-
encodingBuilder.semanticType(semanticTypeOf(type, field));
299-
300299
if (null != field)
301300
{
302301
encodingBuilder.epoch(field.epoch());
303-
encodingBuilder.timeUnit(field.timeUnit() != null ? field.timeUnit().jucTimeUnit() : null);
302+
encodingBuilder.timeUnit(field.timeUnit());
304303
}
305304

306305
final Token.Builder tokenBuilder = new Token.Builder()

main/java/uk/co/real_logic/sbe/xml/Message.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private Field parseField(final NodeList nodeList, final int nodeIndex)
248248
.presence(Presence.get(getAttributeValue(nodeList.item(nodeIndex), "presence", "required")))
249249
.sinceVersion(Integer.parseInt(getAttributeValue(nodeList.item(nodeIndex), "sinceVersion", "0")))
250250
.epoch(getAttributeValue(nodeList.item(nodeIndex), "epoch", "unix"))
251-
.timeUnit(TimeUnit.get(getAttributeValue(nodeList.item(nodeIndex), "timeUnit", "nanosecond")))
251+
.timeUnit(getAttributeValue(nodeList.item(nodeIndex), "timeUnit", "nanosecond"))
252252
.type(fieldType)
253253
.build();
254254

main/java/uk/co/real_logic/sbe/xml/TimeUnit.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)