Repository: openhft/chronicle-wire
Issue: There's no way to encode a "zero" value in the SymbolsLongConverters

We take numeric zero to mean empty string which means strings that consist entirely of the "zero" character can't be round-tripped.

e.g. the following both fail
`assertEquals(Base85LongConverter.INSTANCE.asText(Base85LongConverter.INSTANCE.parse("0")), "0");`
`assertEquals(Base85LongConverter.INSTANCE.asText(Base85LongConverter.INSTANCE.parse("00000")), "00000");`

a similar problem exists for values with leading "zero" values e.g.
`assertEquals(Base85LongConverter.INSTANCE.asText(Base85LongConverter.INSTANCE.parse("00012")), "00012");`

Not sure if this is a bug, or just a limitation to be aware of when using them to encode strings. Perhaps it's something we need to be explicit about in our docs?


Changed files:
src/main/java/net/openhft/chronicle/wire/converter/SymbolsLongConverter.java, src/test/java/net/openhft/chronicle/wire/Base85LongConverterTest.java

diff --git a/src/main/java/net/openhft/chronicle/wire/converter/SymbolsLongConverter.java b/src/main/java/net/openhft/chronicle/wire/converter/SymbolsLongConverter.java
index 747abebb..e0750a12 100644
--- a/src/main/java/net/openhft/chronicle/wire/converter/SymbolsLongConverter.java
+++ b/src/main/java/net/openhft/chronicle/wire/converter/SymbolsLongConverter.java
@@ -63,6 +63,11 @@ public class SymbolsLongConverter implements LongConverter {
 
     @Override
     public void append(StringBuilder text, long value) {
+        if (value == 0) {
+            text.append(decode[0]);
+            return;
+        }
+
         final int start = text.length();
         if (value < 0) {
             int v = (int) Long.remainderUnsigned(value, factor);
diff --git a/src/test/java/net/openhft/chronicle/wire/Base85LongConverterTest.java b/src/test/java/net/openhft/chronicle/wire/Base85LongConverterTest.java
index aaf0fbd2..1c0cd5f3 100644
--- a/src/test/java/net/openhft/chronicle/wire/Base85LongConverterTest.java
+++ b/src/test/java/net/openhft/chronicle/wire/Base85LongConverterTest.java
@@ -34,7 +34,7 @@ public class Base85LongConverterTest extends WireTestCommon {
     public void parse() {
         LongConverter c = Base85LongConverter.INSTANCE;
         // System.out.println(c.asString(-1L));
-        for (String s : ",a,ab,abc,abcd,ab.de,123=56,1234567,12345678,zzzzzzzzz,+ko2&)z.0".split(",")) {
+        for (String s : "a,ab,abc,abcd,ab.de,123=56,1234567,12345678,zzzzzzzzz,+ko2&)z.0".split(",")) {
             long v = c.parse(s);
             StringBuilder sb = new StringBuilder();
             c.append(sb, v);
@@ -91,6 +91,20 @@ public class Base85LongConverterTest extends WireTestCommon {
         allSafeChars(wire);
     }
 
+    @Test
+    public void willParseEmptyStringAsZero() {
+        assertEquals(0, Base85LongConverter.INSTANCE.converter.parse(""));
+    }
+
+    @Test
+    public void testEncodeAndDecodeZero() {
+        assertEquals(0, Base85LongConverter.INSTANCE.converter.parse("0"));
+        assertEquals("0", Base85LongConverter.INSTANCE.converter.asText(0).toString());
+        StringBuilder b = new StringBuilder();
+        Base85LongConverter.INSTANCE.append(b, 0);
+        assertEquals("0", b.toString());
+    }
+
     private void allSafeChars(Wire wire) {
         final Base85LongConverter converter = Base85LongConverter.INSTANCE;
         for (long i = 0; i <= 85 * 85; i++) {