Skip to content

Commit cfc961f

Browse files
committed
mock array fields
1 parent 6eac2be commit cfc961f

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

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

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package uk.co.real_logic.sbe.generation.java;
1717

18+
import uk.co.real_logic.sbe.PrimitiveType;
1819
import uk.co.real_logic.sbe.generation.CodeGenerator;
1920
import uk.co.real_logic.sbe.generation.OutputManager;
2021
import uk.co.real_logic.sbe.ir.Encoding;
@@ -361,12 +362,82 @@ private CharSequence generatePrimitivePropertyMethods(
361362
}
362363
else if (arrayLength > 1)
363364
{
364-
return generateSingleValueProperty(containingClassName, propertyName, javaTypeName+"[]", indent);
365+
return generateArrayProperty(encoding, containingClassName, propertyName, javaTypeName, indent);
365366
}
366367

367368
return "";
368369
}
369370

371+
private CharSequence generateArrayProperty(
372+
final Encoding encoding,
373+
final String containingClassName, final String propertyName,
374+
final String javaTypeName, final String indent)
375+
{
376+
final StringBuilder sb = new StringBuilder();
377+
378+
sb.append(String.format(
379+
"\n" + indent + " private %s[] %s;\n",
380+
javaTypeName,
381+
propertyName
382+
));
383+
384+
sb.append(String.format(
385+
indent + " public %1$s %2$s(final int index)\n" +
386+
indent + " {\n" +
387+
indent + " return %2$s[index];\n" +
388+
indent + " }\n\n",
389+
javaTypeName,
390+
propertyName
391+
));
392+
393+
sb.append(String.format(
394+
indent + " public void %1$s(final int index, final %2$s value)\n" +
395+
indent + " {\n" +
396+
indent + " %1$s[index] = value;\n" +
397+
indent + " }\n",
398+
propertyName,
399+
javaTypeName
400+
));
401+
402+
if (encoding.primitiveType() == PrimitiveType.CHAR)
403+
{
404+
sb.append(String.format(
405+
"\n" +
406+
indent + " public int get%1$s(final byte[] dst, final int dstOffset)\n" +
407+
indent + " {\n" +
408+
indent + " System.arraycopy(%2$s, 0, dst, dstOffset, %2$sLength());\n" +
409+
indent + " return %2$sLength();\n" +
410+
indent + " }\n\n",
411+
JavaUtil.toUpperFirstChar(propertyName),
412+
propertyName
413+
));
414+
415+
sb.append(String.format(
416+
indent + " public %1$s put%2$s(final byte[] src, final int srcOffset)\n" +
417+
indent + " {\n" +
418+
indent + " System.arraycopy(src, srcOffset, %3$s, 0, src.length - srcOffset);\n" +
419+
indent + " return this;\n" +
420+
indent + " }\n",
421+
containingClassName,
422+
JavaUtil.toUpperFirstChar(propertyName),
423+
propertyName
424+
));
425+
426+
sb.append(String.format(
427+
indent + " public %1$s put%2$s(final byte[] src)\n" +
428+
indent + " {\n" +
429+
indent + " %3$s = Arrays.copyOf(src, %3$sLength());\n" +
430+
indent + " return this;\n" +
431+
indent + " }\n",
432+
containingClassName,
433+
JavaUtil.toUpperFirstChar(propertyName),
434+
propertyName
435+
));
436+
}
437+
438+
return sb;
439+
}
440+
370441
private CharSequence generateSingleValueProperty(
371442
final String containingClassName, final String propertyName, final String javaTypeName, final String indent)
372443
{

0 commit comments

Comments
 (0)