From 3271b7a9ea28e95512a7cac86dabfdff45a8391a Mon Sep 17 00:00:00 2001 From: pcdv Date: Wed, 19 Jun 2024 11:21:25 +0200 Subject: [PATCH] Implement more types in CommonEncoderImpl --- .../artio/builder/CommonEncoderImpl.java | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/artio-codecs/src/main/java/uk/co/real_logic/artio/builder/CommonEncoderImpl.java b/artio-codecs/src/main/java/uk/co/real_logic/artio/builder/CommonEncoderImpl.java index 12adea47f2..39b567e7d6 100644 --- a/artio-codecs/src/main/java/uk/co/real_logic/artio/builder/CommonEncoderImpl.java +++ b/artio-codecs/src/main/java/uk/co/real_logic/artio/builder/CommonEncoderImpl.java @@ -7,8 +7,12 @@ */ public class CommonEncoderImpl { - // TODO resizable buffer or way to set a size - protected MutableAsciiBuffer customTagsBuffer = new MutableAsciiBuffer(new byte[64]); + protected MutableAsciiBuffer customTagsBuffer = new MutableAsciiBuffer(new byte[128]); + + public void setCustomTagsBuffer(MutableAsciiBuffer customTagsBuffer) + { + this.customTagsBuffer = customTagsBuffer; + } protected int customTagsLength = 0; @@ -20,6 +24,15 @@ private int putTagHeader(final int tag) return pos; } + public CommonEncoderImpl customTag(final int tag, final boolean value) + { + int pos = putTagHeader(tag); + pos += customTagsBuffer.putCharAscii(pos, value ? 'Y' : 'N'); + customTagsBuffer.putSeparator(pos++); + customTagsLength = pos; + return this; + } + public CommonEncoderImpl customTag(final int tag, final int value) { int pos = putTagHeader(tag); @@ -29,6 +42,33 @@ public CommonEncoderImpl customTag(final int tag, final int value) return this; } + public CommonEncoderImpl customTag(final int tag, final char value) + { + int pos = putTagHeader(tag); + pos += customTagsBuffer.putCharAscii(pos, value); + customTagsBuffer.putSeparator(pos++); + customTagsLength = pos; + return this; + } + + public CommonEncoderImpl customTag(final int tag, final long value) + { + int pos = putTagHeader(tag); + pos += customTagsBuffer.putLongAscii(pos, value); + customTagsBuffer.putSeparator(pos++); + customTagsLength = pos; + return this; + } + + public CommonEncoderImpl customTag(final int tag, final double value) + { + int pos = putTagHeader(tag); + pos += customTagsBuffer.putAscii(pos, String.valueOf(value)); + customTagsBuffer.putSeparator(pos++); + customTagsLength = pos; + return this; + } + public CommonEncoderImpl customTagAscii(final int tag, final CharSequence value) { int pos = putTagHeader(tag); @@ -38,6 +78,16 @@ public CommonEncoderImpl customTagAscii(final int tag, final CharSequence value) return this; } + public CommonEncoderImpl customTagAscii(final int tag, final byte[] value) + { + int pos = putTagHeader(tag); + customTagsBuffer.putBytes(pos, value); + pos += value.length; + customTagsBuffer.putSeparator(pos++); + customTagsLength = pos; + return this; + } + public void resetCustomTags() { customTagsLength = 0;