static public DataCoding createGeneralGroup()

in ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java [255:285]


    static public DataCoding createGeneralGroup(byte characterEncoding, Byte messageClass, boolean compressed) throws IllegalArgumentException {
        // only default, 8bit, or UCS2 are valid
        if (!(characterEncoding == CHAR_ENC_DEFAULT || characterEncoding == CHAR_ENC_8BIT || characterEncoding == CHAR_ENC_UCS2)) {
            throw new IllegalArgumentException("Invalid characterEncoding [0x" + HexUtil.toHexString(characterEncoding) + "] value used: only default, 8bit, or UCS2 supported for general group");
        }

        // validate the message class (only if non-null)
        if (messageClass != null && (messageClass.byteValue() < 0 || messageClass.byteValue() > 3)) {
            throw new IllegalArgumentException("Invalid messageClass [0x" + HexUtil.toHexString(messageClass) + "] value used: 0x00-0x03 only valid range");
        }

        // need to build this dcs value (top 2 bits are 0, start with 0x00)
        byte dcs = 0;
        if (compressed) {
            dcs |= (byte)0x20;  // turn bit 5 on
        }

        // if a message class is present turn bit 4 on
        if (messageClass != null) {
            dcs |= (byte)0x10;  // turn bit 4 on

            // bits 1 thru 0 is the message class
            // merge in the message class (bottom 2 bits)
            dcs |= messageClass;
        }

        // merge in language encodings (they nicely merge in since only default, 8-bit or UCS2)
        dcs |= characterEncoding;

        return new DataCoding(dcs, Group.GENERAL, characterEncoding, (messageClass == null ? MESSAGE_CLASS_0 : messageClass.byteValue()), compressed);
    }