Class GSM7BitPacking


  • public class GSM7BitPacking
    extends Object
    Utilities for packing and unpacking 7-bit values according to the rules for SMS/CBS and USSD.

    The common "unpacked" format stores one 7-bit value per byte. This is the format expected by the GSM7BitAlphabet class.

    See 3GPP TS 23.038 section 6.1.2 for further details on the packing rules used.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getPackedSMSSize​(int count)
      Compute the number of bytes needed for SMS/CBS packing.
      static int getPackedUSSDSize​(byte[] src, int srcpos, int count)
      Compute the number of bytes needed for USSD packing.
      static int getUnpackedSMSSize​(int count)
      Compute the number of bytes needed for SMS/CBS unpacking.
      static int getUnpackedUSSDSize​(byte[] src, int srcpos, int bytecount)
      Compute the number of bytes needed for USSD unpacking.
      static void packSMS​(byte[] src, int srcpos, byte[] dst, int dstpos, int count)
      Pack from bytes to 7-bit fields, using the SMS/CBS packing rules.
      static int packUSSD​(byte[] src, int srcpos, byte[] dst, int dstpos, int count)
      Pack from bytes to 7-bit fields, using the USSD packing rules.
      static void unpackSMS​(byte[] src, int srcpos, byte[] dst, int dstpos, int count)
      Unpack a 7-bit packed value to a series of 8-bit aligned values, using the SMS/CBS packing rules.
      static int unpackUSSD​(byte[] src, int srcpos, byte[] dst, int dstpos, int bytecount)
      Unpack a 7-bit packed value to a series of 8-bit aligned values, using the USSD packing rules.
    • Method Detail

      • unpackSMS

        public static void unpackSMS​(byte[] src,
                                     int srcpos,
                                     byte[] dst,
                                     int dstpos,
                                     int count)
        Unpack a 7-bit packed value to a series of 8-bit aligned values, using the SMS/CBS packing rules.
        Parameters:
        src - the array to unpack from
        srcpos - the offset within src (in bytes) to start at
        dst - the array to unpack to
        dstpos - the offset within dst (in bytes) to start at
        count - the number of values to unpack
      • unpackUSSD

        public static int unpackUSSD​(byte[] src,
                                     int srcpos,
                                     byte[] dst,
                                     int dstpos,
                                     int bytecount)
        Unpack a 7-bit packed value to a series of 8-bit aligned values, using the USSD packing rules.
        Parameters:
        src - the array to unpack from
        srcpos - the offset within src (in bytes) to start at
        dst - the array to unpack to
        dstpos - the offset within dst (in bytes) to start at
        bytecount - the number of *bytes* to unpack
        Returns:
        the number of values actually unpacked
      • packSMS

        public static void packSMS​(byte[] src,
                                   int srcpos,
                                   byte[] dst,
                                   int dstpos,
                                   int count)
        Pack from bytes to 7-bit fields, using the SMS/CBS packing rules.
        Parameters:
        src - the array to pack from
        srcpos - the offset within src (in bytes) to start at
        dst - the array to pack to
        dstpos - the offset within dst (in bytes) to start at
        count - the number of values to pack
      • packUSSD

        public static int packUSSD​(byte[] src,
                                   int srcpos,
                                   byte[] dst,
                                   int dstpos,
                                   int count)
        Pack from bytes to 7-bit fields, using the USSD packing rules.
        Parameters:
        src - the array to pack from
        srcpos - the offset within src (in bytes) to start at
        dst - the array to pack to
        dstpos - the offset within dst (in bytes) to start at
        count - the number of values to pack
        Returns:
        the number of bytes actually written
      • getUnpackedSMSSize

        public static int getUnpackedSMSSize​(int count)
        Compute the number of bytes needed for SMS/CBS unpacking. Unlike USSD, this is independent of the actual data contents.
        Parameters:
        count - the number of values to unpack
        Returns:
        the actual number of bytes that unpackSMS(byte[], int, byte[], int, int) will use given the same parameters
      • getPackedSMSSize

        public static int getPackedSMSSize​(int count)
        Compute the number of bytes needed for SMS/CBS packing. Unlike USSD, this is independent of the actual data contents.
        Parameters:
        count - the number of values to pack
        Returns:
        the actual number of bytes that packSMS(byte[], int, byte[], int, int) will use given the same parameters
      • getUnpackedUSSDSize

        public static int getUnpackedUSSDSize​(byte[] src,
                                              int srcpos,
                                              int bytecount)
        Compute the number of bytes needed for USSD unpacking.
        Parameters:
        src - the array to unpack from
        srcpos - the offset within src (in bytes) to start at
        bytecount - the number of *bytes* to unpack
        Returns:
        the actual number of bytes that unpackUSSD(byte[], int, byte[], int, int) will use given the same parameters
      • getPackedUSSDSize

        public static int getPackedUSSDSize​(byte[] src,
                                            int srcpos,
                                            int count)
        Compute the number of bytes needed for USSD packing.
        Parameters:
        src - the array to pack from
        srcpos - the offset within src (in bytes) to start at
        count - the number of values to pack
        Returns:
        the actual number of bytes that packUSSD(byte[], int, byte[], int, int) will use given the same parameters