public static long fixFloatValueOf(final byte[] s, int length) { int start = 0; boolean negative = false; int decimal = -1; long value; final byte c = s[start]; if (c == '-') { ++start; --length; negative = true; } /* * else if (c == '+') { ++start; --length; } */ if (length == 0) throw new NumberFormatException("to short number"); for (decimal = length - 1; decimal >= 0; decimal--) if (s[decimal] == (byte) '.') break; final int decimals = start + length - 1 - decimal; if (decimal > -1) { value = Utils.longValueOf(s, start, decimal - start) * FIX_FLOAT_NUMBER_OF_DECIMALS; final int dec = FIX_FLOAT_NUMBER_OF_DECIMALS_DIGITS < decimals ? FIX_FLOAT_NUMBER_OF_DECIMALS_DIGITS : decimals; value += Utils.intValueOf(s, decimal + 1 < length ? decimal + 1 : length - 1, dec) * Utils.multiplier(FIX_FLOAT_NUMBER_OF_DECIMALS_DIGITS - dec); } else value = Utils.longValueOf(s, start, decimals) * FIX_FLOAT_NUMBER_OF_DECIMALS; if (negative) return -1 * value; return value; }
public static int getTagIntValue(final byte[] msgType, final int tag, final ByteBuffer buf) throws FixSessionException { byte c = SOH; int start = 0; final int end = FIX_MAX_DIGITS; while ((c = buf.get()) != SOH) { digitsBuf[start++] = c; if (start == end) { throw new FixSessionException( SessionRejectReason.VALUE_IS_INCORRECT_OUT_OF_RANGE_FOR_THIS_TAG, ("Value length exceeds maximum number of digits " + FIX_MAX_DIGITS).getBytes(), tag, msgType); } } if (start == 0) throw new FixSessionException( SessionRejectReason.TAG_SPECIFIED_WITHOUT_A_VALUE, "Tag specified without a value".getBytes(), tag, msgType); if (c != SOH) throw new FixSessionException( SessionRejectReason.TAG_SPECIFIED_WITHOUT_A_VALUE, "Message not terminated by SOH".getBytes(), tag, msgType); return Utils.intValueOf(digitsBuf, 0, start); }