Skip to content

Commit

Permalink
Implement more types in CommonEncoderImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
pcdv committed Jun 19, 2024
1 parent 643a64d commit 3271b7a
Showing 1 changed file with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 3271b7a

Please sign in to comment.