2012-02-29 4 views
0

주어진 메시지 형태로 디코딩 할 수있는 방법 :나는 아래에 주어진 소비자가 받았다되는 ActiveMQ는 메시지가

0327700000260000460000010000047000108Full TalkValue Offer! Get talkvalue of Rs.62 on Recharge of Rs.62.Yourlast Call Charge is 1.000.Your Main Balance is Rs 47.000.00001500001291965355668000001800001604952312808659f9

내가 자바를 사용하여 형식을 다음으로이 메시지를 디코딩 할 필요를 :

DIALOG : 032770 
MESSAGE : 000026 
Parameter : 000046 [ UNKNOWN ] Length : 1 
Value : 0 
Parameter : 000047 [ UNKNOWN ] Length : 108 
Value : FullTalkValueOffer!GettalkvalueofRs.62onRechargeofRs.62.YourlastCallChargeis1.000.YourMainBalanceisRs47.000. 
Parameter : 000015 [ MSISDN ] Length : 12 
Value : 919653556680 
Parameter : 000018 [ UNKNOWN ] Length : 16 
Value : 04952312808659f9 

메시지는 다음과 같은 규칙을 사용하여 디코딩 : 메시지의 먼저 6 자 대화하고 NEX를 t 6 문자는 MESSAGE입니다. 그 다음에는 다음 6자를 매개 변수로 선택합니다. 그리고 다음 6 자로 길이를 검색합니다. 0을 무시하고 1을 선택합니다.이 6 자의 임의의 위치에서 그 문자를 선택하면 길이는 이후의 숫자가됩니다 1과 함께 1. 그리고이 길이에 따라, 그것은 값으로 메시지의 다음 문자를 선택합니다. 다음 매개 변수와 해당 길이와 값을 선택합니다.

은 이미 .. 난 누군가가 나에게 논리를 말할 message..plz 더 디코딩하는 논리를 찾을 수 can'nt 문자열 나누었다의 문자열 방법을 사용하여

+0

을 대화와 메시지를 디코딩 한 길이'108'은 문자열'FullTalkValue ... '의 길이와 일치하지 않습니다. 좀 이상하게 보입니다. 인쇄 할 수없는 문자가 삭제되거나 다른 것으로 대체되었을 수도 있습니다. –

답변

1
public class Message { 
    public int dialog; 
    public int message; 
    public Map<Integer, String> parameters; 

    public Message(String input) { 
     int pos = 0; 
     dialog = Integer.parseInt(input.substring(pos,pos+6)); 
     pos += 6; 
     message = Integer.parseInt(input.substring(pos,pos+6)); 
     pos += 6; 
     parameters = new TreeMap<Integer,String>(); 
     while (pos+12 <= input.length()) 
     { 
      int param = Integer.parseInt(input.substring(pos,pos+6)); 
      pos += 6; 
      int len = Integer.parseInt(input.substring(pos,pos+6)); 
      pos += 6; 
      parameters.put(param, input.substring(pos,pos+len)); 
      pos += len; 
     } 
    } 
} 
Message msg = new Message(input); 

System.out.printf("DIALOG : %d\n", msg.dialog); 
System.out.printf("MESSAGE : %d\n", msg.message); 
for (Integer param : msg.parameters.keySet()) { 
    System.out.printf("PARAM %d : \"%s\"\n", param, msg.parameters.get(param)); 
} 
+0

고마워요. ..i 그것을 시도합니다 .. –

+0

값이 계산됩니다 ?? –

+0

무슨 가치가 있니? –

관련 문제