tag:blogger.com,1999:blog-6758669929503282355.post9157189876523285992..comments2023-06-01T10:31:31.089+03:00Comments on A BLOG BY FATIH BATUK: Java Asn1 Compiler (open source)Fatih Batukhttp://www.blogger.com/profile/18358190963052593214noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-6758669929503282355.post-87513774654476046612010-06-22T13:49:18.990+03:002010-06-22T13:49:18.990+03:00Hi Fatih,
Thanks for this great parser. I am tryi...Hi Fatih,<br /><br />Thanks for this great parser. I am trying to use JAC for parsing some HUAWEI CDR files. I have recreated the essential parts where I am facing problems in the following ASN1 file.<br /><br />Data DEFINITIONS IMPLICIT TAGS::= <br />BEGIN<br /><br />MyChc ::= CHOICE {<br /> myString11 [APPLICATION 5] EXPLICIT OCTET STRING,<br /> myString22 [APPLICATION 6] EXPLICIT OCTET STRING<br />}<br /> <br />Report ::= SEQUENCE {<br /> message-Identifier INTEGER (0 .. 65535),<br /> choice-list SEQUENCE OF MyChc<br />}<br /> <br />END<br /><br />This is the function to test it:<br /><br /> public static void main(String[] args) throws IOException {<br /><br /> //outputstream for encoding<br /> ByteArrayOutputStream outStream = new ByteArrayOutputStream();<br /> BerOutputStream out = new BerOutputStream(outStream);<br /><br /> //input stream for decoding<br /> ByteArrayInputStream inputStream;<br /> BerInputStream in;<br /><br /> MyChc chc1 = new MyChc();<br /> chc1.myString22.setValue(new byte[]{9,2,6,11,21});<br /> MyChc chc2 = new MyChc();<br /> chc2.myString11.setValue(new byte[]{6,11,21});<br /><br /> Report report = new Report();<br /> report.message_Identifier.setValue(3);<br /> report.choice_list.setComponentType(chc1);<br /> report.choice_list.addElement(chc1);<br /> report.choice_list.addElement(chc2);<br /><br /> //encode:<br /> outStream = new ByteArrayOutputStream();<br /> out = new BerOutputStream(outStream);<br /> report.encode(out);<br /> System.out.print("\n -- SEQUENCE OF INTEGER ");<br /> printHex(outStream.toByteArray());<br /><br /> //decode it:<br /> inputStream = new ByteArrayInputStream(outStream.toByteArray());<br /> in = new BerInputStream(inputStream);<br /> Report generatedReport = new Report();<br /> generatedReport.decode(in);<br /><br /> //check some parameter to see that whether it is decoded succesfully or not:<br /> System.out.println(generatedReport);<br /><br /> }<br /><br /><br />When I run this code with the generated classes, I am able to encode the data to get the following bytestream in hex:<br /><br />30 15 02 01 03 30 10 66 07 04 05 09 02 06 0B 15 65 05 04 03 06 0B 15 <br /><br />however while decoding the same string I am getting an error:<br /><br />Exception in thread "main" java.lang.NullPointerException<br /> at com.chaosinmotion.asn1.BerConstruct.(BerConstruct.java:196)<br /> at com.chaosinmotion.asn1.BerSequence.(BerSequence.java:114)<br /> at com.turkcelltech.jac.AutoParser.readSeq(AutoParser.java:229)<br /> at com.chaosinmotion.asn1.BerConstruct.(BerConstruct.java:120)<br /> at com.chaosinmotion.asn1.BerSequence.(BerSequence.java:102)<br /> at com.turkcelltech.jac.Sequence.decode(Sequence.java:104)<br /> at sequenceOfChoice.testSeqOfChoice.main(testSeqOfChoice.java:42)<br /><br />During debugging I found that the sequenceOf variable does not have it's content set. It would be great if you could identify a method to make this work.<br /><br />Regards,<br />Manish.Unknownhttps://www.blogger.com/profile/09800236136160711102noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-63155101417266878372009-11-23T12:02:06.461+02:002009-11-23T12:02:06.461+02:00Hi,
JAC does not support NUMERICSTRING. In the ...Hi,<br />JAC does not support NUMERICSTRING. In the 'known limitations' part you can find this information. And also it is writing above.Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-2191450236918737602009-11-23T11:48:24.074+02:002009-11-23T11:48:24.074+02:00Hi Fatih,
First thanks for your great asn1 compil...Hi Fatih, <br />First thanks for your great asn1 compiler.<br /><br />I have a little question for you.<br /><br />JAC support the asn1 "NUMERICSTRING"?<br /><br />Thanks,<br />Danydanyhttps://www.blogger.com/profile/11788949378328376677noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-89703057671930494442009-10-15T03:05:26.031+03:002009-10-15T03:05:26.031+03:00Hi Fatih,
First thanks for your great asn1 compil...Hi Fatih, <br />First thanks for your great asn1 compiler. Jac is helping me a lot with my project. <br />Im pretty new to ASN1 (around 1 week) and my first problem is about one ASN1 type: Operation.<br />Is there support available to "operation" on JAC?<br />how can i use that?<br /><br />This is my asn1 code:<br /><br />monitorStart OPERATION ::=<br />{ ARGUMENT MonitorStartArgument<br /> RESULT MonitorStartResult<br /> ERRORS {universalFailure}<br /> CODE local: 71<br />}<br /><br />I've already created the MonitorStartArgument object and the MonitorStartResult object, but how could i describe an operation on JAC?<br /><br />is there some recommended tutorial or forum?<br /><br />Thanks in advance.Eduardonoreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-29724126670320074422009-06-23T19:52:52.456+03:002009-06-23T19:52:52.456+03:00An OctetString is actually an array of 8-bit bytes...An OctetString is actually an array of 8-bit bytes, and not necessarily a printable string. (I've seen protocols use an OctetString as an image, for example.)<br /><br />If you know your OctetString contains a printable string, you can get the value (BerOctetString.getValue()), and convert it to a String using one of the byte array to string conversion constructors.William Woodyhttps://www.blogger.com/profile/14125248910339373710noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-18325076498518253622009-06-17T13:52:17.160+03:002009-06-17T13:52:17.160+03:00Thanks.
You cannot generate C code with JAC. But ...Thanks. <br />You cannot generate C code with JAC. But there are diffrent open source asn1 C compilers on the net.Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-60956217120808231762009-06-17T10:21:17.911+03:002009-06-17T10:21:17.911+03:00Hi, I have worked on your Java version and seems g...Hi, I have worked on your Java version and seems great. Could you pls tell me if I can generate C code also using this compiler.<br /><br />Thanks,<br />AshishUnknownhttps://www.blogger.com/profile/11756818178547944390noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-21451763690794268932009-04-16T15:02:00.000+03:002009-04-16T15:02:00.000+03:00Hi Fatih,
I would appreciate if you could tell ho...Hi Fatih,<br /><br />I would appreciate if you could tell how to print the value of variable of type OctetString. If I use the getValue function it returns me a junk value.<br /><br />Ashishashishhttps://www.blogger.com/profile/00707958217468136543noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-5207851594478026982009-04-16T10:54:00.000+03:002009-04-16T10:54:00.000+03:00Hi Ashish,
Nowadays in my spare times I was worki...Hi Ashish,<br /><br />Nowadays in my spare times I was working on the problem that you specified. In 2.0 version of JAC auto decoding in Choice objects is not supported.<br />But it is almost finished. I will e-mail you the new version when finished. Please contact me via e-mail about this issue (see my blogger profile page for my e-mail)Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-789432541409490392009-04-16T09:57:00.000+03:002009-04-16T09:57:00.000+03:00Hi Fatih,
I am new to ASN and I have been asked t...Hi Fatih,<br /><br />I am new to ASN and I have been asked to research on it. I am exploring your JAC (Java Asn.1 Compiler). It is a great tool but I am stuck with a problem and not able to proceed further. Following is my CDR format -<br /><br /><I>ABC DEFINITIONS IMPLICIT TAGS ::=<br />BEGIN<br /><br /> CallDetailOutputRecord ::= CHOICE {<br /> sCFPDPRecord [0] SCFPDPRecord,<br /> sCFSMSPSMORecord [1] SCFSMSMORecord,<br /> sCFSMSCSMORecord [2] SCFSMSMORecord,<br /> diameterCreditControlRecord [3] DiameterCreditControlRecord,<br /> fBCRatingRecord [4] FBCRatingRecord,<br /> rTCCreditControlRecord [5] RTCCreditControlRecord<br /> }<br /><br /></I>I able to decode like this <br /><br /> CallDetailOutputRecord cdr = new CallDetailOutputRecord();<br /> cdr.diameterCreditControlRecord.decode(in);<br /><br /><br />but in case I donot know if the record is of type SCFPDPRecord,SCFSMSMORecord,SCFSMSMORecord,DiameterCreditControlRecord,FBCRatingRecord or RTCCreditControlRecord because the CallDetailOutputRecord is of type CHOICE, how can I decode the records<br /><br /><br />Thanks<br />AshishAshish Abrolhttps://www.blogger.com/profile/15300353409867927470noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-61728343343843411182009-01-16T09:38:00.000+02:002009-01-16T09:38:00.000+02:00Hi Antonoi Bello,It is really hard to understand y...Hi Antonoi Bello,<BR/>It is really hard to understand your problem. You should tell your problem in detail. This is not sufficient.<BR/><BR/>I do not know your ans1 file but you should be careful for the followings to use the JAC:<BR/>1) JAC does not support the inner type definitions. For example:<BR/><BR/>--------------------------<BR/>CDRProcessed ::= SEQUENCE {<BR/>.......<BR/>cdrProcDedicatedAccounts [31] SEQUENCE (SIZE (1..255)) OF CDRProcDedicatedAccount OPTIONAL,<BR/>......<BR/>....<BR/>}<BR/>--------------------------<BR/><BR/>If you have an inner type definition like above, firstly you should "tune" your asn1 file. Just remove the inner type definitions in your file.<BR/>For example just convert the above line as follows:<BR/><BR/>--------------------------<BR/>CDRProcessed ::= SEQUENCE {<BR/>.......<BR/>cdrProcDedicatedAccounts [31] SequenceOfCDRProcDedicatedAccount OPTIONAL,<BR/>......<BR/>....<BR/>}<BR/><BR/>SequenceOfCDRProcDedicatedAccount ::= SEQUENCE OF CDRProcDedicatedAccount<BR/>--------------------------<BR/><BR/>So that's it. Just modify all the inner type definitions if you have any.<BR/><BR/><BR/>2) Do not forget that:<BR/><BR/>The supported asn.1 data types for JAC are the most common asn.1 types:<BR/>CHOICE, SEQUENCE, SEQUENCE OF, SET, SET OF, BOOLEAN, INTEGER, ENUMERATED, ANY, BIT STRING, IA5String, NULL, OBJECT IDENTIFIER, OCTET STRING, PRINTABLE STRING and UTCTime<BR/><BR/>If you have a different asn.1 definition in your file you cannot use JAC.<BR/><BR/>3) "AUTOMATIC TAGGING", which is not prefered to use in many cases, is not supported.<BR/><BR/>4) JAC does not understand the "imports". All of the definitions should be in 1 file.<BR/><BR/>5) You should clerly read the "JAC.ppt" and "Readme.html" files and examine the "TestProject.java" under the "test" package to understand the use of JAC clearly.Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-27287642024737108332009-01-10T17:09:00.000+02:002009-01-10T17:09:00.000+02:00Hi Wissam,You do not need to write a manual parser...Hi Wissam,<BR/>You do not need to write a manual parser class for your asn1 file above. Just download JAC and import in into your eclipse workspace and put your asn1 file under the project folder and then run the "AsnParser.java" class with correct program arguments.<BR/>The arguments are respectively:<BR/><BR/>-d (target_directory) -p (package_name) (asn.1_file_name) <BR/><BR/>a correct example is:<BR/><BR/> -d C:\JavaAsn1Compiler -p test myAsn1.txt <BR/><BR/>And all of these details are written in the "Readme.html" file.<BR/>And you should implicitly examine the TestParser.java class too see the examples of use of the JAC.Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-12152227598552480052009-01-08T17:21:00.000+02:002009-01-08T17:21:00.000+02:00Hello, I'm working on a project that requires the ...Hello, I'm working on a project that requires the parsing of a file asn.<BR/>When I read Eclipse AsnParser by the message: ASN.1 file successfully parsed.<BR/>Input<BR/>and then the program exits.<BR/>I can not understand why, maybe not seemed fairly my asn.<BR/>I am convinced of this because if the file asn put words in case the message is still the same.<BR/>You could help me? Of course it is unnecessary to specify that with your file asn everything works perfectly.<BR/>Thank you,<BR/>AntonioAntonio Bellohttps://www.blogger.com/profile/17840102002106112754noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-67246682298570724352008-12-03T16:24:00.000+02:002008-12-03T16:24:00.000+02:00Dear Mr.Batuk,Would you please help me with the be...Dear Mr.Batuk,<BR/><BR/>Would you please help me with the below problem:<BR/><BR/>the ASN.1 format is as the below:<BR/>SDPCallDataRecord ::= CHOICE {<BR/> cDRProcessed [1] CDRProcessed,<BR/> accountAdjustment [2] AccountAdjustment,<BR/> negativeBalance [3] NegativeBalance,<BR/> bonusAdjustment [4] BonusAdjustment,<BR/> serviceFeeDeduction [5] ServiceFeeDeduction,<BR/> lifeCycleChange [6] LifeCycleChange,<BR/> negativeBalanceBarred [7] NegativeBalanceBarred,<BR/> valueVoucherExpiry [8] ValueVoucherExpiry,<BR/> periodicAdjustment [9] PeriodicAdjustment,<BR/> periodicReset [10] PeriodicReset,<BR/> temporaryBlock [11] TemporaryBlock<BR/>}<BR/><BR/>CDRProcessed ::= SEQUENCE {<BR/> recordType [1] RecordType,<BR/> sdpID [2] NodeID,<BR/>.<BR/>.<BR/>}<BR/>AccountAdjustment ::= SEQUENCE {<BR/> adjustmentRecordType [1] AdjustmentRecordType,<BR/> sdpID [2] NodeID,<BR/>.<BR/>.<BR/>}<BR/>.<BR/>.<BR/>.<BR/><BR/>I have tried to use the TestParser2 sent by Mr.William with my own specifications but it doesn't work.<BR/>would you please suggest the best strategy to write a parser for the above schema using your JAC library.<BR/><BR/>Thank you very much.<BR/>WissamWissamhttps://www.blogger.com/profile/02683366071833316315noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-36520965885151019092008-11-28T09:17:00.000+02:002008-11-28T09:17:00.000+02:00Hi Naveen,Sorry for my late response. I totally fo...Hi Naveen,<BR/><BR/>Sorry for my late response. I totally forgot your post.<BR/>In your example here, you use the MySequence.java class.<BR/>Instead of that you should use your generated class "DataPacket.java"<BR/>So the true format will be in the following form.<BR/>......<BR/>DataPacket dp = new DataPacket();<BR/>dp.decode(in);<BR/>System.out.println(dp.toString());Fatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-83958058542672339712008-11-20T08:44:00.000+02:002008-11-20T08:44:00.000+02:00Hey thanks for the info. Exactly what I was lookin...Hey thanks for the info. Exactly what I was looking for. I am very glad to receive the whole package compiler and parser. I actually had some custom ASN.1 spec I was implementing for. It had pretty much everything except the application specific tags. I had to write many manual Parser classes because the spec. was quite variable, and included a choice between 6 different complex/universal types. <BR/><BR/>I'm pretty new to ASN.1, so I also incorporated the asn1c project for proofing a general ASN.1 spec and automatically generating a detailed description. From this I ran jac to compile the classes. In my own opinion I think it worked excellent. Its made me a believer in ASN.1. Forget XML I'm going backt to the basics. Write better code and reduce your telcom data footprint/charges.Dave Klassenhttps://www.blogger.com/profile/11963664783187246699noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-53706855445250615352008-11-19T19:13:00.000+02:002008-11-19T19:13:00.000+02:00Dave Klassen:Hi; I'm Bill Woody, the author of the...Dave Klassen:<BR/><BR/>Hi; I'm Bill Woody, the author of the ASN.1 Ber libraries that Fatih Batuk is using in his JAC library.<BR/><BR/>The intent of the 'state' variable in the BerParser.java class was to track the current state--roughly corresponding to the current statement--being parsed, thus allowing you to build an ASN.1 BER parser using just one class deriving from the BerParser.java class.<BR/><BR/>To give an example, suppose we have the following ASN.1 protocol:<BR/><BR/>BEGIN<BR/> A :== CHOICE {<BR/> b B,<BR/> c C<BR/> }<BR/> B :== [APPLICATION 0] SEQUENCE {<BR/> d INTEGER<BR/> e INTEGER<BR/> }<BR/> C :== [APPLICATION 1] SEQUENCE {<BR/> f D,<BR/> g BOOLEAN<BR/> }<BR/> D :== [APPLICATION 2] SEQUENCE {<BR/> h INTEGER<BR/> }<BR/>END<BR/><BR/>(Yeah, this is pretty contrived.)<BR/><BR/>We can write one parser class derived from BerParser as:<BR/><BR/>public class TestParser2 extends BerParser<BR/>{<BR/> private static final int A = BerParser.START;<BR/> private static final int B = 1;<BR/> private static final int C = 2;<BR/> private static final int D = 3;<BR/><BR/> public BerNode create(int tag, int state, BerInputStream stream) throws IOException<BR/> {<BR/> switch (state) {<BR/> case A:<BR/> if (tag == (Tag.APPLICATION | 0)) {<BR/> // reached statement B<BR/> return new BerSequence(tag, B, this, stream);<BR/> } else if (tag == (Tag.APPLICATION | 1)) {<BR/> // reached statement C<BR/> return new BerSequence(tag, C, this, stream);<BR/> } else {<BR/> throw new AsnEncodingException("Unknown tag: " + tag);<BR/> }<BR/> <BR/> case C:<BR/> if (tag == (Tag.APPLICATION | 2)) {<BR/> // reached statement D<BR/> return new BerSequence(tag, D, this, stream);<BR/> } else {<BR/> throw new AsnEncodingException("Unknown tag: " + tag);<BR/> }<BR/> <BR/> case B:<BR/> case D:<BR/> // Because both statements only have primitives if we are called<BR/> // there is an unknown tag in the stream<BR/> throw new AsnEncodingException("Unknown tag: " + tag);<BR/> default:<BR/> throw new AsnEncodingException("Unknown state: " + state); // will never happen<BR/> }<BR/> }<BR/>}<BR/><BR/>Here's what is happening: the 'create' method in my TestParser2 class is only called when an unknown tag is seen in the data stream. (One interesting side effect of this is that the parser will accept any stream of primitive tokens in any of the sequences above--that is, the parser will be overly permissive. So if we send (for statement B) three integers instead of two, the parser will simply accept those three integers.<BR/><BR/>Only when we see the [APPLICATION n] tags will the 'create' method get called. The first time the 'create' statement is called the 'state' variable is set to the constant START; this indicates we are at whatever 'start' state (typically, the first ASN.1 statement in the description). In our contrived example above, it indicates that we're parsing tags that correspond to statement A.<BR/><BR/>Depending on the tag we receive in statement A, we could be parsing an input stream corresponding to a sequence B or a sequence C; we examine the tag and create a BerSequence B or a BerSequence C. If inside a C we see a sequence D, we can create a BerSequence D.<BR/><BR/><BR/>There were a couple of ways that the problem of tracking the current 'state' (that is, where you are in the ASN.1 description) while parsing a token stream. One way is to build a recursive descent parser. This would then involve building an explicit class BerParserA, BerParserB, BerParserC, and BerParserD which can then examine and decide based on the current set of tokens what to do--and has the advantage of not being overly permissive. In this case, the parsing 'state' is implied by the current class being used to parse the stream.<BR/><BR/>I took the tactic of passing a state variable around--this has the advantage of allowing the entire parsing engine for a particular protocol to be rolled into a single class, and to reduce the amount of code that needs to be written--since if I'm receiving a protocol that uses a lot of UNIVERSAL types, parsing UNIVERSAL types can be handled automatically.<BR/><BR/>(Thus, if you have a protocol:<BR/><BR/>BEGIN<BR/> A :== SEQUENCE {<BR/> b B,<BR/> c C<BR/> }<BR/> b :== SEQUENCE {<BR/> d INTEGER<BR/> }<BR/> c :== SEQUENCE {<BR/> f INTEGER<BR/> }<BR/>END<BR/><BR/>-- Yeah, another stupid, contrived example<BR/><BR/>Then you wont have to write any code at all; 'create' can be left blank.)<BR/><BR/><BR/>Unfortunately I haven't had the time to look at Fatih Batuk's ASN.1 parser in detail--my job took me away from playing with ASN.1 around the time Mr. Batuk started writing his code. But having an ASN.1 parser automatically build the network of classes necessary to properly parse a token stream is preferable to my BerParser solution. I created the BerParser solution--modeling it on the Netscape BER parser for their LDAP code--so I could write an LDAP parser quickly and compactly.<BR/><BR/>Hope this helps.William Woodyhttps://www.blogger.com/profile/14125248910339373710noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-1958362446169565902008-11-17T23:49:00.000+02:002008-11-17T23:49:00.000+02:00Hi,Sorry for my late response.Actually, first of a...Hi,<BR/><BR/>Sorry for my late response.<BR/>Actually, first of all you should think why you need to decode your data with a manual parser implementation. If you have already tried to use auto decoding (i.e. using AutoParser.java) that I wrote in my project and if it does not support for you, then you can try writing your own ManualParser for your specific encoded data. Remember that, "sequence of" and "set of" objects even with tagged types can also be decoded by our AutoParser.<BR/><BR/>And your point.. the "state" variable in BerParser.java class... I deleted that variable because it is not necessary in my implementation. Just have a look at the ManualParser.java class to understand the manual decoding algorithm.<BR/><BR/>And if you wanna understand the goal of state variable in the W.Woody's asn1 library you should look to the TestParser.java class in my project. In that class, Woody just gives an example parser implementation just for usage of his pure asn.1 library.<BR/><BR/>Shortly, I tried to simplify the manual decoding mechanism in my project. And I removed the state variable.<BR/>If you look more closer to the code, you will reliaze that Woody handles the decoding issue in a digfferent way. Because of that, the state variable was mandatory for his algorithm.<BR/>If you still want to learn more about to the "state variable" why Woody used it, you may try to ask it to W.Woody (http://chaosinmotion.com/blog/?p=124)<BR/><BR/>I hope this was helpful<BR/>Best Regards<BR/>FatihFatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-64764063558498328292008-11-17T22:02:00.000+02:002008-11-17T22:02:00.000+02:00A BLOG BY FATIH BATUK: Java Asn1 Compiler (open so...A BLOG BY FATIH BATUK: Java Asn1 Compiler (open source)<BR/><BR/>Hi,<BR/>I have downloaded the 2.0 JAC and trying to use it to decode a smiple asn1 packet and i am getting an error called " >> During decoding, the encoded tag value in the byte array does not match with this object's tag number !" . I tried to fix it the way you have explained to Imran but still i get the same error. For reference i am posting the entire asn.1 file i used to create the .java files and the java file which i used to decode.<BR/><BR/>first i used the javacc to create the necessary java files:<BR/>java javacc.AsnParser -d /home/login95/asnParser -p small small.asn // this created a directory and inside it created relevant java files<BR/><BR/>My asn file format is as below (small.asn)<BR/>SDI DEFINITIONS IMPLICIT TAGS ::=<BR/><BR/>BEGIN<BR/><BR/>DataPacket ::= SEQUENCE {<BR/> operation [0] OCTET STRING,<BR/> parameters [1] Packet <BR/>}<BR/><BR/>Packet ::= SEQUENCE {<BR/> retrieve [0] RetrievePacket<BR/>}<BR/><BR/>RetrievePacket ::= SEQUENCE {<BR/> dataOID [0] OCTET STRING<BR/>}<BR/><BR/>END<BR/><BR/>//sample datapacket<BR/>30 0D // DataPacket<BR/> 80 01 FF // Operation<BR/> A0 08 //Retrieve<BR/> 80 06 380101020101 //DataOID<BR/><BR/><BR/>Next i switched to this directory and wrote a small java file (TestFile.java)<BR/>package small;<BR/><BR/>import java.io.*;<BR/>import java.util.BitSet;<BR/>import java.util.Date;<BR/>import examples.*;<BR/><BR/>import com.turkcelltech.jac.*;<BR/>import com.chaosinmotion.asn1.*;<BR/><BR/>public class TestFile<BR/>{<BR/> public static void main(String[] args)<BR/> {<BR/> try{<BR/><BR/> FileInputStream fs = new FileInputStream(new File("/root/asnParser/vault/small/mypacket.ber"));<BR/> BerInputStream in = new BerInputStream(fs);<BR/> MySequence seq = new MySequence();<BR/> seq.decode(in);<BR/> System.out.println(seq.toString());<BR/><BR/> }catch(Exception ex){<BR/> System.err.println("encode: Exception: " + ex.getMessage());<BR/> }<BR/> }<BR/>}<BR/><BR/><BR/>Waiting for you help .....Naveenhttps://www.blogger.com/profile/15487538287711266950noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-38066784361544613762008-11-13T07:51:00.000+02:002008-11-13T07:51:00.000+02:00What is your philosophical view point about why th...What is your philosophical view point about why the state variable existed in the choasinmotion distribution? and... Do you think that the according to the ASN.1 spec 'state' should not be a part of a parser library (That is as much as I could conclude after reading the code and creating my own manual parser classes.). <BR/><BR/>I am thinking that any code depending on the parser jar, should decide how to handle state, not the parser library itself (Using callbacks etc.). What I am asking for is your opinion on how you would handle state if such a thing were necessary in a dependent application. Or your philosophy about why you made the change, and moving forward for dependent projects, how do you suggest applications that require state incorporate such a thing?Dave Klassenhttps://www.blogger.com/profile/11963664783187246699noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-13065881155648641612008-06-05T14:45:00.000+03:002008-06-05T14:45:00.000+03:00Many many many thanks for your help its working as...Many many many thanks for your help its working as I want, it was really great experience to interact with you. I learned lot from you.<BR/><BR/>I have added you in my yahoo IM with id please accept that also.<BR/><BR/>ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-71615918377180914292008-06-05T01:26:00.000+03:002008-06-05T01:26:00.000+03:00Hi Imran,why don't you try the following form :Fil...Hi Imran,<BR/><BR/>why don't you try the following form :<BR/><BR/>FileInputStream fs = new FileInputStream( new File("c:\\ASN.ber") );<BR/>BerInputStream in = new BerInputStream(fs);<BR/><BR/>int number_of_records = 0;<BR/> <BR/>CDR mycdr;<BR/><BR/>while ( in.available() > 0 ) {<BR/> mycdr = new CDR();<BR/> mycdr.roaming_cdr.decode(in);<BR/> number_of_records++;<BR/><BR/> // do your operations with your decoded object "mycdr" ...<BR/>}<BR/> <BR/>Did this solve your problem ? Please acknowledge me<BR/><BR/>RegardsFatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-57814958828457555662008-06-04T00:46:00.000+03:002008-06-04T00:46:00.000+03:00Hi Fatih,Thanks for your response. It solved my de...Hi Fatih,<BR/><BR/>Thanks for your response. It solved my decoding problem.<BR/><BR/>My asn1 encoded file sometimes contain 50 records and sometimes 60 records so to decode that file I require multiple instances of sequence object.<BR/><BR/>My question is that do there any way to get number of records in one file, so I could create array of objects accordingly and by running while loop decode all records.<BR/><BR/>Regards,<BR/>imranAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-84326764338303910492008-06-03T01:24:00.000+03:002008-06-03T01:24:00.000+03:00Hi Imran,I think I understood your problem. In you...Hi Imran,<BR/><BR/>I think I understood your problem. In your asn1 file there is a choice object that contains a roaming_CDR sequence object and it is tagged as "[0]" in the choice record. It is not an exact ROAMING_CDR object. It is an inner object of the choice type CDR<BR/>So your error during decoding is normal.<BR/><BR/>Please try the following :<BR/><BR/>CDR mycdr = new CDR();<BR/>mycdr.roaming_cdr.decode(in);<BR/>System.out.println(mycdr.roaming_cdr.toString());<BR/><BR/>RegardsFatih Batukhttps://www.blogger.com/profile/18358190963052593214noreply@blogger.comtag:blogger.com,1999:blog-6758669929503282355.post-17595898713377794772008-06-02T21:05:00.000+03:002008-06-02T21:05:00.000+03:00Hi Fatih,I successfully generated class files but ...Hi Fatih,<BR/><BR/>I successfully generated class files but when i set my sequence it give me following error<BR/><BR/> FileInputStream fs = new FileInputStream( new File("c:\\ASN.ber") );<BR/> BerInputStream in = new BerInputStream(fs);<BR/> ROAMING_CDR seq = new ROAMING_CDR();<BR/> seq.decode(in);<BR/> System.out.println(seq.toString());<BR/><BR/>Following is error:<BR/><BR/>com.chaosinmotion.asn1.AsnFatalException:<BR/> >> During decoding, the encoded tag value in the byte array does not match with this object's tag number !<BR/> at com.turkcelltech.jac.Sequence.decode(Sequence.java:97)<BR/> at com.turkcelltech.jac.cdr.CDREnc.main(CDREnc.java:72)<BR/><BR/>Following is my CDR format<BR/><BR/> XSENSE-CDR DEFINITIONS IMPLICIT TAGS ::=<BR/> BEGIN<BR/><BR/> CDR ::= CHOICE {<BR/> roaming-cdr [0] ROAMING-CDR<BR/> }<BR/><BR/> ROAMING-CDR ::= SEQUENCE {<BR/> timestamp Timestamp,<BR/> type RoamingCdrType,<BR/> msisdn [0] ISDN-AddressString OPTIONAL,<BR/> imsi [1] IMSI,<BR/> vlr ISDN-AddressString<BR/> }<BR/> <BR/> ;....... other asn1 records<BR/> <BR/> END<BR/> <BR/>And hex encoded CDR in file is like this :<BR/><BR/>[tag for the pdu = a0] [length=27] [timestamp octet string tag = 04] [length = 08] 00 00 00 fe 6d 0c d1 74 [enumerated tag = 0a] [length = 01] 02 [msisdn context specific tag = 80] [length = 06] 64 0784 7076 f0 [imsi context specific tag = 81] [length = 08] 42 00 07 21 00 28 30 f6 [vlr octet string tag = 04] [length = 06] 64 07 17 00 99 f1<BR/><BR/>and my file contains many records.Anonymousnoreply@blogger.com