public override byte[] EncodeValue(ScalarValue v) { if (v == ScalarValue.Null) { return(NullValueEncoding); } var buffer = new MemoryStream(); var value = (DecimalValue)v; try { if (Math.Abs(value.Exponent) > 63) { Global.ErrorHandler.OnError(null, RepError.LargeDecimal, ""); } byte[] tmp = NullableInteger.Encode(new IntegerValue(value.Exponent)); buffer.Write(tmp, 0, tmp.Length); tmp = Integer.Encode(new LongValue(value.Mantissa)); buffer.Write(tmp, 0, tmp.Length); } catch (IOException e) { throw new RuntimeException(e); } return(buffer.ToArray()); }
public override ScalarValue Decode(Stream inStream) { ScalarValue subtractionLength = NullableInteger.Decode(inStream); if (subtractionLength == null) { return(null); } ScalarValue difference = Ascii.Decode(inStream); return(new TwinValue(subtractionLength, difference)); }
public override ScalarValue Decode(Stream inStream) { ScalarValue exp = NullableInteger.Decode(inStream); if ((exp == null) || exp.IsNull) { return(null); } int exponent = exp.ToInt(); long mantissa = Integer.Decode(inStream).ToLong(); var decimalValue = new DecimalValue(mantissa, exponent); return(decimalValue); }
public override byte[] EncodeValue(ScalarValue value) { if (value.IsNull) { return(NullValueEncoding); } var diff = (TwinValue)value; byte[] subtractionLength = NullableInteger.Encode(diff.First); byte[] difference = Ascii.Encode(diff.Second); var encoded = new byte[subtractionLength.Length + difference.Length]; Array.Copy(subtractionLength, 0, encoded, 0, subtractionLength.Length); Array.Copy(difference, 0, encoded, subtractionLength.Length, difference.Length); return(encoded); }