byte[] encode(byte[] states) {
        // calculate the number of differences
        int n = 0;
        for (int i = 0; i < states.length; i++) {
            byte state = states[i];
            byte defaultState = this.defaultStates[i];

            if (state == defaultState) {
                continue;
            }

            n++;
        }

        if (n == 0) {
            return new byte[0];
        }

        ByteArrayDataOutput out = ByteStreams.newDataOutput();

        // write the number of differences to "expect"
        out.writeByte((byte) n);

        for (int i = 0; i < states.length; i++) {
            byte state = states[i];
            byte defaultState = this.defaultStates[i];

            if (state == defaultState) {
                continue;
            }

            byte settingOrdinal = (byte) i;
            out.writeByte(settingOrdinal);
            out.writeByte(state);
        }

        return out.toByteArray();
    }
Returns if the given set of states differs from the defaults.

@param states the states to compare
@return true if different
helper/src/main/java/me/lucko/helper/setting/SettingMapFactory.java