/** * Calculates the checksum for the given message * (excluding existing checksum field, if one exists). * The {@link CharsetSupport#setCharset global charset} is used. * * @param message the message to calculate the checksum on * @return the calculated checksum */ public static int checksum(String message) { return checksum(CharsetSupport.getCharsetInstance(), message, true); }
/** * Returns the checksum of this field's FIX-encoded bytes (tag=value), * including the trailing SOH byte. * * @return the checksum of this field's encoded bytes */ /*package*/ int getChecksum() { calculate(); return ((dataBytes != null ? MessageUtils.checksum(dataBytes, false) : MessageUtils.checksum(CharsetSupport.getCharsetInstance(), data, false)) + 1) & 0xFF; }
/** * Returns the checksum of this field's FIX-encoded bytes (tag=value), * including the trailing SOH byte. * * @return the checksum of this field's encoded bytes */ /*package*/ int getChecksum() { calculate(); return ((dataBytes != null ? MessageUtils.checksum(dataBytes, false) : MessageUtils.checksum(CharsetSupport.getCharsetInstance(), data, false)) + 1) & 0xFF; }
/** * Calculates the checksum for the given message * (excluding existing checksum field, if one exists). * The {@link CharsetSupport#setCharset global charset} is used. * * @param message the message to calculate the checksum on * @return the calculated checksum */ public static int checksum(String message) { return checksum(CharsetSupport.getCharsetInstance(), message, true); }
/** * Returns the checksum of this field's FIX-encoded bytes (tag=value), * including the trailing SOH byte. * * @return the checksum of this field's encoded bytes */ /*package*/ int getChecksum() { calculate(); return ((dataBytes != null ? MessageUtils.checksum(dataBytes, false) : MessageUtils.checksum(CharsetSupport.getCharsetInstance(), data, false)) + 1) & 0xFF; }
/** * Calculates the checksum for the given message * (excluding existing checksum field, if one exists). * The {@link CharsetSupport#setCharset global charset} is used. * * @param message the message to calculate the checksum on * @return the calculated checksum */ public static int checksum(String message) { return checksum(CharsetSupport.getCharsetInstance(), message, true); }
private void validateCheckSum(String messageData) throws InvalidMessage { try { // Body length is checked at the protocol layer final int checksum = trailer.getInt(CheckSum.FIELD); if (checksum != MessageUtils.checksum(messageData)) { // message will be ignored if checksum is wrong or missing throw MessageUtils.newInvalidMessageException("Expected CheckSum=" + MessageUtils.checksum(messageData) + ", Received CheckSum=" + checksum + " in " + messageData, this); } } catch (final FieldNotFound e) { throw MessageUtils.newInvalidMessageException("Field not found: " + e.field + " in " + messageData, this); } }
private void validateCheckSum(String messageData) throws InvalidMessage { try { // Body length is checked at the protocol layer final int checksum = trailer.getInt(CheckSum.FIELD); if (checksum != MessageUtils.checksum(messageData)) { // message will be ignored if checksum is wrong or missing throw new InvalidMessage("Expected CheckSum=" + MessageUtils.checksum(messageData) + ", Received CheckSum=" + checksum + " in " + messageData); } } catch (final FieldNotFound e) { throw new InvalidMessage("Field not found: " + e.field + " in " + messageData); } }
/** * Calculates the checksum for the given data. * * @param charset the charset used in encoding the data * @param data the data to calculate the checksum on * @param isEntireMessage specifies whether the data is an entire message; * if true, and it ends with a checksum field, that checksum * field is excluded from the current checksum calculation * @return the calculated checksum */ public static int checksum(Charset charset, String data, boolean isEntireMessage) { if (CharsetSupport.isStringEquivalent(charset)) { // optimization - skip charset encoding int sum = 0; int end = isEntireMessage ? data.lastIndexOf("\00110=") : -1; int len = end > -1 ? end + 1 : data.length(); for (int i = 0; i < len; i++) { sum += data.charAt(i); } return sum & 0xFF; // better than sum % 256 since it avoids overflow issues } return checksum(data.getBytes(charset), isEntireMessage); }
/** * Calculates the checksum for the given data. * * @param charset the charset used in encoding the data * @param data the data to calculate the checksum on * @param isEntireMessage specifies whether the data is an entire message; * if true, and it ends with a checksum field, that checksum * field is excluded from the current checksum calculation * @return the calculated checksum */ public static int checksum(Charset charset, String data, boolean isEntireMessage) { if (CharsetSupport.isStringEquivalent(charset)) { // optimization - skip charset encoding int sum = 0; int end = isEntireMessage ? data.lastIndexOf("\00110=") : -1; int len = end > -1 ? end + 1 : data.length(); for (int i = 0; i < len; i++) { sum += data.charAt(i); } return sum & 0xFF; // better than sum % 256 since it avoids overflow issues } return checksum(data.getBytes(charset), isEntireMessage); }
/** * Calculates the checksum for the given data. * * @param charset the charset used in encoding the data * @param data the data to calculate the checksum on * @param isEntireMessage specifies whether the data is an entire message; * if true, and it ends with a checksum field, that checksum * field is excluded from the current checksum calculation * @return the calculated checksum */ public static int checksum(Charset charset, String data, boolean isEntireMessage) { if (CharsetSupport.isStringEquivalent(charset)) { // optimization - skip charset encoding int sum = 0; int end = isEntireMessage ? data.lastIndexOf("\00110=") : -1; int len = end > -1 ? end + 1 : data.length(); for (int i = 0; i < len; i++) { sum += data.charAt(i); } return sum & 0xFF; // better than sum % 256 since it avoids overflow issues } return checksum(data.getBytes(charset), isEntireMessage); }
private void validateCheckSum(String messageData) throws InvalidMessage { try { // Body length is checked at the protocol layer final int checksum = trailer.getInt(CheckSum.FIELD); if (checksum != MessageUtils.checksum(messageData)) { // message will be ignored if checksum is wrong or missing throw MessageUtils.newInvalidMessageException("Expected CheckSum=" + MessageUtils.checksum(messageData) + ", Received CheckSum=" + checksum + " in " + messageData, this); } } catch (final FieldNotFound e) { throw MessageUtils.newInvalidMessageException("Field not found: " + e.field + " in " + messageData, this); } }