def encode_string_with_trailing_spaces(string, target_length)
      length = string.length
      if length < target_length
        return "#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}"
      elsif length == target_length
        return [string].pack(@str)
      else
        raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
      end
    end
def encode_string_with_trailing_spaces(string, target_length)
      length = string.length
      if length < target_length
        return "#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}"
      elsif length == target_length
        return [string].pack(@str)
      else
        raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
      end
    end
Appends a string with trailling spaces to achieve a target length, and encodes it to a binary string.

 @param [String] string a string to be padded
 @param [Integer] target_length the target length of the string
 @return [String] an encoded binary string