We are defining the Potassium output format, make sure we do not use
Strings to encode Decimal64, just plain binary -- up to 9 bytes.
JIRA: YANGTOOLS-568
Change-Id: If0f42d0b16594fd3ed6703277d41e547ef197302
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import javax.xml.transform.dom.DOMSource;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Either;
import javax.xml.transform.dom.DOMSource;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Either;
+import org.opendaylight.yangtools.concepts.WritableObjects;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
return Uint64.ZERO;
case PotassiumValue.UINT64_4B:
return Uint64.fromLongBits(input.readInt() & 0xFFFFFFFFL);
return Uint64.ZERO;
case PotassiumValue.UINT64_4B:
return Uint64.fromLongBits(input.readInt() & 0xFFFFFFFFL);
- case PotassiumValue.BIGDECIMAL:
- // FIXME: use string -> Decimal64 cache
- return Decimal64.valueOf(input.readUTF());
+ case PotassiumValue.DECIMAL64:
+ return Decimal64.of(input.readByte(), WritableObjects.readLong(input));
case PotassiumValue.STRING_EMPTY:
return "";
case PotassiumValue.STRING_UTF:
case PotassiumValue.STRING_EMPTY:
return "";
case PotassiumValue.STRING_UTF:
import java.io.DataOutput;
import java.io.IOException;
import java.io.StringWriter;
import java.io.DataOutput;
import java.io.IOException;
import java.io.StringWriter;
-import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.Deque;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.Deque;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.jdt.annotation.NonNull;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.WritableObjects;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
output.writeByte(PotassiumValue.EMPTY);
} else if (value instanceof Set<?> set) {
writeValue(set);
output.writeByte(PotassiumValue.EMPTY);
} else if (value instanceof Set<?> set) {
writeValue(set);
- } else if (value instanceof BigDecimal || value instanceof Decimal64) {
- output.writeByte(PotassiumValue.BIGDECIMAL);
- output.writeUTF(value.toString());
+ } else if (value instanceof Decimal64 decimal) {
+ output.writeByte(PotassiumValue.DECIMAL64);
+ output.writeByte(decimal.scale());
+ WritableObjects.writeLong(output, decimal.unscaledValue());
} else {
throw new IOException("Unhandled value type " + value.getClass());
}
} else {
throw new IOException("Unhandled value type " + value.getClass());
}
package org.opendaylight.yangtools.yang.data.codec.binfmt;
import java.io.DataOutput;
package org.opendaylight.yangtools.yang.data.codec.binfmt;
import java.io.DataOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
+import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
* Reference a previously defined QNameModule. Reference number is encoded as {@code int}.
*/
static final byte MODREF_4B = 0x1C;
* Reference a previously defined QNameModule. Reference number is encoded as {@code int}.
*/
static final byte MODREF_4B = 0x1C;
-
- /**
- * A {@link BigDecimal}, encoded through {@link DataOutput#writeUTF(String)}.
- */
- // This is legacy compatibility. At some point we will remove support for writing these.
- static final byte BIGDECIMAL = 0x1D;
- * A {@link BigInteger}, encoded through {@link DataOutput#writeUTF(String)}.
+ * A {@link Decimal64}, encoded with fraction-digits byte and a WritableObjects.writeLong().
- // This is legacy compatibility. At some point we will remove support for writing these.
- static final byte BIGINTEGER = 0x1E;
+ static final byte DECIMAL64 = 0x1D;
@Parameters(name = "{0} {1}")
public static Iterable<Object[]> data() {
return Collections.singletonList(
@Parameters(name = "{0} {1}")
public static Iterable<Object[]> data() {
return Collections.singletonList(
- new Object[] { NormalizedNodeStreamVersion.POTASSIUM, 1_049_589, 2_289_103, 139, 796, 103, 229, 99 });
+ new Object[] { NormalizedNodeStreamVersion.POTASSIUM, 1_049_587, 2_289_103, 139, 794, 103, 229, 99 });