Class BCDPlacesStringCodec<T>

  • All Implemented Interfaces:
    StringCodec<T>, Serializable

    public class BCDPlacesStringCodec<T>
    extends BCDStringCodec<T>
    Implements a StringCodec for the case of decimal digits encoded in semi-octets, with the encoding being aligned around particular numbers of digits before and after the decimal point, which is elided from the encoding. Allows a lax variant to be obtained, for use when there are invalid digits.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      BCDPlacesStringCodec​(int before, int after)
      Constructs a 3GPP standards-based BCDPlacesStringCodec customised to the given numbers of digits before and after the decimal point.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String decodeString​(byte[] encoded)
      Decodes a String containing a decimal number from a byte array, positioning the decimal point between before and after numbers of digits, and eliding leading 0s.
      String decodeString​(byte[] encoded, StringIndicators indicators)
      Decodes a String containing a decimal number from a byte array, positioning the decimal point between before and after numbers of digits, and eliding leading 0s.
      byte[] encodeString​(String string)
      Encodes a String containing a decimal number to a byte array, with each digit being encoded in a semi-octet, aligning the encoding around particular numbers of digits before and after the decimal point, which itself is not explicitly encoded, padding with 0s before and after.
      byte[] encodeString​(String string, StringIndicators indicators)
      Encodes a String containing a decimal number to a byte array, with each digit being encoded in a semi-octet, aligning the encoding around particular numbers of digits before and after the decimal point, which itself is not explicitly encoded, padding with 0s before and after.
      BCDPlacesStringCodec<T> getLaxDecoder()
      Gets a BCDPlacesStringCodec that decodes invalid characters to hex digits instead of throwing an exception.
    • Constructor Detail

      • BCDPlacesStringCodec

        public BCDPlacesStringCodec​(int before,
                                    int after)
        Constructs a 3GPP standards-based BCDPlacesStringCodec customised to the given numbers of digits before and after the decimal point.
        Parameters:
        before - number of digits before the decimal point
        after - number of digits after the decimal point
    • Method Detail

      • getLaxDecoder

        public BCDPlacesStringCodec<T> getLaxDecoder()
        Gets a BCDPlacesStringCodec that decodes invalid characters to hex digits instead of throwing an exception. Its encodeString() method does nothing useful. The lax variant of a lax variant is itself (idempotent).
        Specified by:
        getLaxDecoder in interface StringCodec<T>
        Overrides:
        getLaxDecoder in class BCDStringCodec<T>
        Returns:
        BCDPlacesStringCodec
      • encodeString

        public byte[] encodeString​(String string,
                                   StringIndicators indicators)
        Encodes a String containing a decimal number to a byte array, with each digit being encoded in a semi-octet, aligning the encoding around particular numbers of digits before and after the decimal point, which itself is not explicitly encoded, padding with 0s before and after. Excess digits before or after the decimal point are ignored. Sets indicators to assist decoding by this or other StringCodecs.
        Specified by:
        encodeString in interface StringCodec<T>
        Overrides:
        encodeString in class BCDStringCodec<T>
        Parameters:
        string - the String to be encoded to a byte array
        indicators - the StringIndicators object in which to set the indicators
        Returns:
        the encoded byte array
        Throws:
        UnsupportedDigitException - if any character of the given String is not decimal or the '.'
      • encodeString

        public byte[] encodeString​(String string)
        Encodes a String containing a decimal number to a byte array, with each digit being encoded in a semi-octet, aligning the encoding around particular numbers of digits before and after the decimal point, which itself is not explicitly encoded, padding with 0s before and after. Excess digits before or after the decimal point are ignored.
        Specified by:
        encodeString in interface StringCodec<T>
        Overrides:
        encodeString in class BCDStringCodec<T>
        Parameters:
        string - the String to be encoded to a byte array
        Returns:
        the encoded byte array
        Throws:
        UnsupportedDigitException - if any character of the given String is not decimal or the '.'
      • decodeString

        public String decodeString​(byte[] encoded,
                                   StringIndicators indicators)
        Decodes a String containing a decimal number from a byte array, positioning the decimal point between before and after numbers of digits, and eliding leading 0s. Trailing 0s are kept. The given indicators should include numSemiOctets, with odd being used if numSemiOctets is inconsistent with the length of the encoded form.
        Specified by:
        decodeString in interface StringCodec<T>
        Overrides:
        decodeString in class BCDStringCodec<T>
        Parameters:
        encoded - the byte array to be decoded to a String
        indicators - indicator values needed for decoding
        Returns:
        the decoded String
        Throws:
        UnsupportedDigitException - if any encoded content cannot be decoded by this codec
      • decodeString

        public String decodeString​(byte[] encoded)
        Decodes a String containing a decimal number from a byte array, positioning the decimal point between before and after numbers of digits, and eliding leading 0s. Trailing 0s are kept.
        Specified by:
        decodeString in interface StringCodec<T>
        Overrides:
        decodeString in class BCDStringCodec<T>
        Parameters:
        encoded - the byte array to be decoded to a String
        Returns:
        the decoded String
        Throws:
        UnsupportedDigitException - if any encoded content cannot be decoded by this codec