Skip to content

Commit fc5911a

Browse files
committed
[Java] Provide a wrap<var data member> method to allow for easy access for zero copy. Issue aeron-io#600.
1 parent ac16086 commit fc5911a

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,20 @@ private void generateDataDecodeMethods(
769769
byteOrderStr,
770770
indent);
771771

772+
sb.append(String.format("\n" +
773+
indent + " public void wrap%s(final %s wrapBuffer)\n" +
774+
indent + " {\n" +
775+
indent + " final int headerLength = %d;\n" +
776+
indent + " final int limit = parentMessage.limit();\n" +
777+
indent + " final int dataLength = (int)%s;\n" +
778+
indent + " parentMessage.limit(limit + headerLength + dataLength);\n" +
779+
indent + " wrapBuffer.wrap(buffer, limit + headerLength, dataLength);\n" +
780+
indent + " }\n",
781+
propertyName,
782+
readOnlyBuffer,
783+
sizeOfLengthField,
784+
generateGet(lengthType, "limit", byteOrderStr)));
785+
772786
if (null != characterEncoding)
773787
{
774788
sb.append(String.format("\n" +

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ public int getPackageName(final byte[] dst, final int dstOffset, final int lengt
310310
return bytesCopied;
311311
}
312312

313+
public void wrapPackageName(final DirectBuffer wrapBuffer)
314+
{
315+
final int headerLength = 2;
316+
final int limit = parentMessage.limit();
317+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
318+
parentMessage.limit(limit + headerLength + dataLength);
319+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
320+
}
321+
313322
public String packageName()
314323
{
315324
final int headerLength = 2;
@@ -401,6 +410,15 @@ public int getNamespaceName(final byte[] dst, final int dstOffset, final int len
401410
return bytesCopied;
402411
}
403412

413+
public void wrapNamespaceName(final DirectBuffer wrapBuffer)
414+
{
415+
final int headerLength = 2;
416+
final int limit = parentMessage.limit();
417+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
418+
parentMessage.limit(limit + headerLength + dataLength);
419+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
420+
}
421+
404422
public String namespaceName()
405423
{
406424
final int headerLength = 2;
@@ -492,6 +510,15 @@ public int getSemanticVersion(final byte[] dst, final int dstOffset, final int l
492510
return bytesCopied;
493511
}
494512

513+
public void wrapSemanticVersion(final DirectBuffer wrapBuffer)
514+
{
515+
final int headerLength = 2;
516+
final int limit = parentMessage.limit();
517+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
518+
parentMessage.limit(limit + headerLength + dataLength);
519+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
520+
}
521+
495522
public String semanticVersion()
496523
{
497524
final int headerLength = 2;

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ public int getName(final byte[] dst, final int dstOffset, final int length)
628628
return bytesCopied;
629629
}
630630

631+
public void wrapName(final DirectBuffer wrapBuffer)
632+
{
633+
final int headerLength = 2;
634+
final int limit = parentMessage.limit();
635+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
636+
parentMessage.limit(limit + headerLength + dataLength);
637+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
638+
}
639+
631640
public String name()
632641
{
633642
final int headerLength = 2;
@@ -719,6 +728,15 @@ public int getConstValue(final byte[] dst, final int dstOffset, final int length
719728
return bytesCopied;
720729
}
721730

731+
public void wrapConstValue(final DirectBuffer wrapBuffer)
732+
{
733+
final int headerLength = 2;
734+
final int limit = parentMessage.limit();
735+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
736+
parentMessage.limit(limit + headerLength + dataLength);
737+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
738+
}
739+
722740
public String constValue()
723741
{
724742
final int headerLength = 2;
@@ -810,6 +828,15 @@ public int getMinValue(final byte[] dst, final int dstOffset, final int length)
810828
return bytesCopied;
811829
}
812830

831+
public void wrapMinValue(final DirectBuffer wrapBuffer)
832+
{
833+
final int headerLength = 2;
834+
final int limit = parentMessage.limit();
835+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
836+
parentMessage.limit(limit + headerLength + dataLength);
837+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
838+
}
839+
813840
public String minValue()
814841
{
815842
final int headerLength = 2;
@@ -901,6 +928,15 @@ public int getMaxValue(final byte[] dst, final int dstOffset, final int length)
901928
return bytesCopied;
902929
}
903930

931+
public void wrapMaxValue(final DirectBuffer wrapBuffer)
932+
{
933+
final int headerLength = 2;
934+
final int limit = parentMessage.limit();
935+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
936+
parentMessage.limit(limit + headerLength + dataLength);
937+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
938+
}
939+
904940
public String maxValue()
905941
{
906942
final int headerLength = 2;
@@ -992,6 +1028,15 @@ public int getNullValue(final byte[] dst, final int dstOffset, final int length)
9921028
return bytesCopied;
9931029
}
9941030

1031+
public void wrapNullValue(final DirectBuffer wrapBuffer)
1032+
{
1033+
final int headerLength = 2;
1034+
final int limit = parentMessage.limit();
1035+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1036+
parentMessage.limit(limit + headerLength + dataLength);
1037+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1038+
}
1039+
9951040
public String nullValue()
9961041
{
9971042
final int headerLength = 2;
@@ -1083,6 +1128,15 @@ public int getCharacterEncoding(final byte[] dst, final int dstOffset, final int
10831128
return bytesCopied;
10841129
}
10851130

1131+
public void wrapCharacterEncoding(final DirectBuffer wrapBuffer)
1132+
{
1133+
final int headerLength = 2;
1134+
final int limit = parentMessage.limit();
1135+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1136+
parentMessage.limit(limit + headerLength + dataLength);
1137+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1138+
}
1139+
10861140
public String characterEncoding()
10871141
{
10881142
final int headerLength = 2;
@@ -1174,6 +1228,15 @@ public int getEpoch(final byte[] dst, final int dstOffset, final int length)
11741228
return bytesCopied;
11751229
}
11761230

1231+
public void wrapEpoch(final DirectBuffer wrapBuffer)
1232+
{
1233+
final int headerLength = 2;
1234+
final int limit = parentMessage.limit();
1235+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1236+
parentMessage.limit(limit + headerLength + dataLength);
1237+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1238+
}
1239+
11771240
public String epoch()
11781241
{
11791242
final int headerLength = 2;
@@ -1265,6 +1328,15 @@ public int getTimeUnit(final byte[] dst, final int dstOffset, final int length)
12651328
return bytesCopied;
12661329
}
12671330

1331+
public void wrapTimeUnit(final DirectBuffer wrapBuffer)
1332+
{
1333+
final int headerLength = 2;
1334+
final int limit = parentMessage.limit();
1335+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1336+
parentMessage.limit(limit + headerLength + dataLength);
1337+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1338+
}
1339+
12681340
public String timeUnit()
12691341
{
12701342
final int headerLength = 2;
@@ -1356,6 +1428,15 @@ public int getSemanticType(final byte[] dst, final int dstOffset, final int leng
13561428
return bytesCopied;
13571429
}
13581430

1431+
public void wrapSemanticType(final DirectBuffer wrapBuffer)
1432+
{
1433+
final int headerLength = 2;
1434+
final int limit = parentMessage.limit();
1435+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1436+
parentMessage.limit(limit + headerLength + dataLength);
1437+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1438+
}
1439+
13591440
public String semanticType()
13601441
{
13611442
final int headerLength = 2;
@@ -1447,6 +1528,15 @@ public int getDescription(final byte[] dst, final int dstOffset, final int lengt
14471528
return bytesCopied;
14481529
}
14491530

1531+
public void wrapDescription(final DirectBuffer wrapBuffer)
1532+
{
1533+
final int headerLength = 2;
1534+
final int limit = parentMessage.limit();
1535+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1536+
parentMessage.limit(limit + headerLength + dataLength);
1537+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1538+
}
1539+
14501540
public String description()
14511541
{
14521542
final int headerLength = 2;
@@ -1538,6 +1628,15 @@ public int getReferencedName(final byte[] dst, final int dstOffset, final int le
15381628
return bytesCopied;
15391629
}
15401630

1631+
public void wrapReferencedName(final DirectBuffer wrapBuffer)
1632+
{
1633+
final int headerLength = 2;
1634+
final int limit = parentMessage.limit();
1635+
final int dataLength = (int)(buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
1636+
parentMessage.limit(limit + headerLength + dataLength);
1637+
wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
1638+
}
1639+
15411640
public String referencedName()
15421641
{
15431642
final int headerLength = 2;

0 commit comments

Comments
 (0)