CN110601794B - ASN.1 coding and decoding module and message data coding and decoding method - Google Patents

ASN.1 coding and decoding module and message data coding and decoding method Download PDF

Info

Publication number
CN110601794B
CN110601794B CN201910768505.5A CN201910768505A CN110601794B CN 110601794 B CN110601794 B CN 110601794B CN 201910768505 A CN201910768505 A CN 201910768505A CN 110601794 B CN110601794 B CN 110601794B
Authority
CN
China
Prior art keywords
decoding
message
class
encoding
type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910768505.5A
Other languages
Chinese (zh)
Other versions
CN110601794A (en
Inventor
葛超
刘元坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hozon New Energy Automobile Co Ltd
Original Assignee
Hozon New Energy Automobile Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hozon New Energy Automobile Co Ltd filed Critical Hozon New Energy Automobile Co Ltd
Priority to CN201910768505.5A priority Critical patent/CN110601794B/en
Publication of CN110601794A publication Critical patent/CN110601794A/en
Application granted granted Critical
Publication of CN110601794B publication Critical patent/CN110601794B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/0001Systems modifying transmission characteristics according to link quality, e.g. power backoff
    • H04L1/0033Systems modifying transmission characteristics according to link quality, e.g. power backoff arrangements specific to the transmitter
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/04Protocols for data compression, e.g. ROHC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/26Special purpose or proprietary protocols or architectures

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • Quality & Reliability (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

An ASN.1 coding and decoding module and a message data coding and decoding method belong to the technical field of communication. The method comprises the following steps: step S01, receiving the message data sent by TBOX to TCP and analyzing to obtain the byte array of OTA service request or service response; step S02, decoding the message header in the byte array and generating a Java message header object; decoding a message body in the byte array, and generating a Java message body object by contrasting a protocol entity mapping table; decoding protocol body data in the byte array, and generating a Java protocol body data object by contrasting a protocol entity mapping table; step S03, encoding the Java message head object, the Java message main body object and the Java protocol main body data object and generating a byte array; step S04, assembling the message header, the message body and the protocol body data into message data which is sent to the TBOX by the TCP; the decoding and coding of the message body and the protocol body data are realized by adopting an ASN.1 coding and decoding module. The invention can realize the maximum compression ratio of the message, so that the message transmission is safe and reliable and the transmission efficiency is high.

Description

ASN.1 coding and decoding module and message data coding and decoding method
Technical Field
The invention belongs to the technical field of communication, and particularly relates to an ASN.1 coding and decoding module and a message data coding and decoding method.
Background
And message transmission is carried out between a vehicle networking platform (TSP platform for short) and vehicle T-BOX equipment. Because the maximum data packet transmitted between TSPs is 4KB at a time, the maximum compression of the message needs to be satisfied to realize the maximum efficient transmission. In order to make the message transmission more secure, a coding and decoding method with high message transmission efficiency and security is required.
The invention patent application CN1992715A discloses an implementation method for PDU encoding and decoding code automatic generation based on asn.1 definition, which specifically comprises: firstly, determining definition rules and marking rules of data types used in a self-defined header file, and generating the header file according to the definition rules and the marking rules; then according to the definition rule and the labeling rule of the data type, a header file analysis tool and a corresponding code generation tool are generated by encoding; scanning each header file by using the header file analysis tool, and analyzing the data structure name and the relation between the structures defined in each header file; and then, automatically generating a PDU structure encoding and decoding code according to the relationship between the data structure name and the structure analyzed from the header file by using the code generation tool. The invention automatically generates a file for encoding and decoding, integrates the universal encoder codes of the ASN.1, and combines the universal encoder codes into an encoder code which can be operated. But only a tool for protocol entity generation.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides an ASN.1 coding and decoding module and a message data coding and decoding method, which can realize the maximum compression ratio of a message, so that the message transmission is safe and reliable and the transmission efficiency is high.
The invention is realized by the following technical scheme:
the invention provides an ASN.1 coding and decoding module which is suitable for an OTA protocol; the module includes:
ASN.1 type library including all base classes for encoding and decoding;
ASN.1 type processing library, including coding and decoding processing method entries corresponding to all coding and decoding types;
the PERALIGNED DECODER class defines a decoding processing method corresponding to all decoding types;
the Decoder class is a father class of the PERALIGNED Decoder class and an implementation class of the IDecoder class;
an IDecoder class, declaring classes for decoded external interfaces;
an IASN1 typeDecoder class which is an interface declaration class of decoding processing methods corresponding to all decoding types;
the PERALIGNED ENCODER class defines the encoding processing method corresponding to all encoding types;
the Encoder class is a father class of the PERALIGNED Encoder class and is an implementation class of the IEncoder class;
IEncoder type, which is an external interface declaration type of codes;
an IASN1TypesEncoder class which is an interface declaration class of the coding processing method corresponding to all coding types;
and the factory class CoderFactory is used for acquiring the IDecoder class or the IEncoder class.
The ASN.1 coding and decoding module defines an ASN.1 coding and decoding mode and provides coding and decoding interfaces of the ASN.1 and OTA. When coding and decoding are carried out, a factory class is utilized to obtain a coding and decoding interface, and a corresponding coding and decoding method is found according to a coding type.
Preferably, the ASN.1 type library comprises a String, an Integer, Boolean, and an Element attribute Element type.
A message data coding and decoding method comprises the following steps:
step S01, receiving message data sent by TBOX to TSP and analyzing to obtain byte array of OTA service request or service response;
step S02, decoding the message header in the byte array and generating a Java message header object; decoding a message main body in the byte array, and generating a Java message main body object corresponding to the OTA message main body by contrasting a protocol entity mapping table; decoding protocol main body data in the byte array, and generating a Java protocol main body data object corresponding to the OTA protocol main body data by contrasting a protocol entity mapping table;
step S03, encoding the Java message head object, the Java message main body object and the Java protocol main body data object and generating a byte array;
step S04, assembling the message header, the message body and the protocol body data as the message data sent to the TBOX by the TSP;
the decoding of the message body and the protocol body data in step S02 and the encoding of the message body and the protocol body data in step S03 are implemented by the asn.1 codec module.
The method of the invention realizes the coding and decoding of the ASN.1 transmitting the message through the transmitting mechanism of Java language. The method uses the unaligned compression coding rule (unaligned-PER) of the ASN.1 to achieve the maximum compression ratio of the message.
Preferably, the decoding process of the header in step S02 is: directly decoding the message header in the byte array into a Java message header object;
the encoding process of the header in step S03 is: and directly coding the Java message header object into a byte array.
Preferably, the decoding process of the message body in step S02 is:
reading binary data of a message body from an input stream, acquiring a decoding external interface statement class IDecoder corresponding to a coding type through a factory class CoderFactory of an ASN.1 coding and decoding module, further acquiring a decoding method corresponding to the decoding type through an ASN.1 type processing library, and further generating a Java message body object;
the encoding process of the message body in step S03 is:
acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java message main body object.
Preferably, the decoding process of the protocol body data in step S02 is:
reading binary data of a protocol body from an input stream, acquiring a decoding external interface statement class IDecoder corresponding to a coding type through a factory class CoderFactory of an ASN.1 coding and decoding module, further acquiring a decoding method corresponding to the decoding type through an ASN.1 type processing library, and further generating a Java protocol body data object;
the encoding process of the protocol body data in step S03 is:
and acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java protocol main body data object.
Preferably, the construction process of the asn.1 type library includes: encoding a String type, an Integer type, a Boolean type and an Element attribute Element type.
Preferably, before encoding the Integer type, the maximum minimum interval of the field is declared:
if the range is less than or equal to 255, encoding a bit field of a minimum size of the range;
if the range happens to be 256, then encode as an octet alignment bit field;
if the range is 257 to 64K, then encoding into two octet aligned bit fields;
if the range is greater than 64K, then the encoding is an octal alignment bit field, which is the minimum octal number of encoded values.
Preferably, the construction process of the ASN.1 type library further comprises the following steps: and checking and verifying the attributes in the class, wherein if the range, the attribute and the length exceed the limits of the OTA protocol, the attribute verification in the class is abnormal.
Preferably, in the coding and decoding process, if the data length exceeds the limitation of the OTA protocol, the coding and decoding are judged to be abnormal.
The invention has the following beneficial effects:
the ASN.1 coding and decoding module and the message data coding and decoding method of the invention remove the dependence on ASN.1 files and are more convenient for problem troubleshooting. Meanwhile, due to the fact that a JAVA annotation mode is used, the ASN.1 object is written more simply and conveniently, the byte array coded by the ASN.1 is directly converted into the object, or the JAVA object is converted into the byte array in the ASN.1 format, the JAVA object is directly operated by service development, the ASN.1 coding does not need to be related, and development is more convenient.
Drawings
FIG. 1 is a schematic diagram of an ASN.1 codec module according to the present invention;
FIG. 2 is a codec having the codec module of FIG. 1;
fig. 3 is a flowchart of a message data encoding and decoding method according to the present invention.
Detailed Description
The following are specific embodiments of the present invention and are further described with reference to the drawings, but the present invention is not limited to these embodiments.
ASN.1 as a high-level abstract description language has the following characteristics:
(1) cross-platform cross-language usage. Which represents the data structure information in a highly abstract form. When data structure information needs to be transmitted in a computer network, the ASN.1 provides corresponding coding and decoding rules and transmits the data structure information through corresponding bit patterns.
(2) ASN.1 makes the standard protocols established by different organizations all adopt the same standard representation form, and ensures interoperability.
(3) Asn.1 provides rich data structures and flexible extension mechanisms, and thus can describe more complex protocol contents.
Therefore, an ASN (application service network) coding and decoding module, a coder and decoder and a message data coding and decoding method suitable for the OTA protocol are constructed based on the ASN.1 language, and the logic of the conversion between the Java object and the ASN.1 coded message is realized by using Java reflection.
Referring to fig. 1, the present invention provides an asn coding/decoding module suitable for OTA protocol; the module includes:
ASN.1 type library including all base classes for encoding and decoding;
ASN.1 type processing library including coding and decoding processing method entries corresponding to all coding and decoding types;
the PERALIGNED DECODER class defines a decoding processing method corresponding to all decoding types;
the Decoder class is a father class of the PERALIGNED Decoder class and an implementation class of the IDecoder class;
an IDecoder class which declares classes for the decoded external interfaces;
an IASN1 typeDecoder class which is an interface declaration class of decoding processing methods corresponding to all decoding types;
the PERALIGNED ENCODER class defines the encoding processing method corresponding to all encoding types;
the Decoder class is a father class of the PERALIGNED ENCODER class and an implementation class of the IEncoder class;
IEncoder type, which is an external interface declaration type of codes;
an IASN1TypesEncoder class which is an interface declaration class of the coding processing method corresponding to all coding types;
and the factory class CoderFactory is used for acquiring the IDecoder class or the IEncoder class.
The ASN.1 type library ASN.1-orientations is a direct or indirect base class of all codecs that provides a definition of classes, with elements injected in annotated form in the protocol mapping entity. The ASN.1 type library comprises basic types such as character String, Integer Integer, Boolean, data set Choice \ Sequence of, NULL type, bit String type BitString, octet String type OctetString, floating point type Real, enumeration type Enum and the like, and Element attribute Element types.
The construction process of the ASN.1 type library comprises the following steps: encoding basic types such as String, Integer, Boolean, data set Choice \ Sequence of, NULL type, bit String type BitString, octet String type OctetString, floating point type Real, enumeration type Enum, and Element attribute Element type.
String type ASN1 String: all String types except BitString and OctetString include PrintableString, BMPString, UTF8String, etc. The present system uses PrintableString by default. The number of bytes occupied by PrintableString after coding is the same as that before coding.
Integer type ASN1 Integer: integer, which includes integers and negatives, may not be-0. The system declares the maximum minimum interval of the field before encoding the shapes. Coding according to different intervals:
1. if the range is less than or equal to 255, encoding a bit field of a minimum size of the range;
2. if the range happens to be 256, the value is encoded as an octet alignment bit field;
3. if the range is 257 to 64K, the value is encoded as a two octet aligned bit field;
4. if the range is greater than 64K, the range is ignored and the value is encoded as an octal alignment bit field, which is the minimum octal number for the value. In the latter case, the latter process also encodes a length field (typically one octet) to indicate the length of the encoding. For other cases, the length of the code is independent of the value being coded and is not explicitly coded.
Boolean ASN1 Boolean: the boolean-coded payload is either all 0 or all 1 octets. The header byte starts with 0x01, the length-encoded byte is 0x01, and the payload content depends on the value of the boolean value.
The data set is of a Choice \ Sequence of type ASN1Choice \ ASN1Sequence of: sequence and set type is a type used to collect related data elements as an independent decodable element, and the content of encoding is determined by the fields and types defined in the protocol entity, and encoding is performed in sequence unless there are fields marked optional (isopotential) or default (hasDefaultValue).
NULL type ASN1 NULL: placeholder type, if present, defaults to 0;
bit string type BitString ASN1 BitString: for use in transferring a single byte, the first bit of the bit string is placed into the 8 th bit of the first payload byte; if the last payload byte is not filled, the empty bits are filled with 0 and the number of 0's is stored in the byte whose header represents the padding data.
Octet string type OctetString ASN1 OctetString: the byte array is passed, similar to the BitString type, with the header encoded and the octets copied directly into the past.
Floating point type Real ASN1 Real: the floating point type comprises special values PLUS-INFINITY (positive INFINITY), MINUS-INFINITY (negative INFINITY) and NOT-A-NUMBER (non-numeric) and an M \ B \ E triplet equation consisting of positive 0 and negative 0, wherein M is a mantissa, B is a radix (can be only 2 or 10), and E is an mutexponent. Different coding schemes are used with different cardinalities:
1. radix =2 coding adopts a hardware floating point conversion coding mode with higher efficiency;
2. the radix =10 coding adopts a binary coded decimal number coding mode.
Enumeration type Enum ASN1 Enum: and traversing and encoding the enumerated values.
Element attribute Element:
ISOPtional: declaring that in an element corresponding to an entity class, the value is true or false, the value is valid when a user transfers Sequence, whether the element is optional is defined, and if true and the element is empty, the value is ignored when the group participates.
hasDefaultValue: and declaring that the value in the element corresponding to the entity class is true or false, wherein the value is valid when the user transfers the Sequence, and defining whether the element has a default value, and if the element is true and the element is empty, ignoring the value when the group parameter exists.
hasTag: declaring whether the value of an element corresponding to the entity class is true or false, defining whether the element needs to define tag, and if true, numbering the types by using the defined tag class and tag.
TagClass: the numbering is valid when the hasTag is true, and four tagClass are available, namely univarial, application, context-specific and private, and the default is context-specific.
Tag: the actual coding start value, valid when hasTag is true, is 0 by default.
isimpiicittag: declaring that in the element corresponding to the entity class, the value is true or false, defining whether the element is valid, and the default is true.
The construction process of the ASN.1 type library further comprises the following steps: and checking and verifying the attributes in the class, wherein if the range, the attribute and the length exceed the limits of the OTA protocol, the attribute verification in the class is abnormal.
The ASN.1 type processing library ASN.1-metadata provides all types of corresponding encoding/decoding processing method entries of the encoder/decoder, and the corresponding metadata class is found by declaring animation in the elements of the mapping entity class.
The PERALIGNED ENCODER and PERALIGNED DECODER define all types of processing methods provided by the codec. Some of the treatments are listed below:
PERALIGNED ENCODER class: during encoding, whether the length, type and range corresponding to the field conform to the protocol mapping or not is checked.
Table one: PERALIGNED ENCODER-LIKE
Figure DEST_PATH_IMAGE002
Table two: PERALIGNED DECoders:
Figure DEST_PATH_IMAGE003
the Encoder and Decoder are fathers of the PERALIGNED ENcoder and the PERALIGNED DECODER respectively, and provide realization of an external interface and realization of a processing method interface.
The IEncoder and the IDecoder are external interface declaration types of encoding/decoding respectively, and the external interface calls the IEncoder and the IDecoder which are generated correspondingly through a factory. Their implementation classes are Encoder and Decode.
The IASN1 typeEncoder and the IASN1 typeDecoder are interface declaration classes of processing methods of the types of the coder/decoder respectively, and define corresponding processing method interfaces of all coding types. Finding out the corresponding metadata class according to the field type in the protocol, and acquiring a specific implementation method through the interface class of the IASN1TypesEncoder and the IASN1 TypesDecoder.
The CoderFactory factory class is used to obtain the IDecoder or IEncoder interface. And also for generating the metadata class corresponding to the IASN1 preparedElementData.
Referring to fig. 2, the present invention provides a codec, which includes an OTA codec module, a protocol entity mapping module, and the asn.1 codec module. The protocol entity mapping module defines entity mapping of all OTA protocols, and specifically comprises a protocol entity mapping table which can acquire Java protocol entities corresponding to the OTA protocol entities. And the OTA coding and decoding module is used for encrypting and decrypting the message data between the TBOX and the TSP.
As shown in fig. 3, the present invention provides a message data encoding and decoding method, which is specifically applied to an OTA encoding and decoding module, and the method includes:
step S01, receiving message data sent by TBOX to TSP and analyzing to obtain byte array of OTA service request or service response;
step S02, decoding the message header in the byte array and generating a Java message header object; decoding a message main body in the byte array, and generating a Java message main body object corresponding to the OTA message main body by contrasting a protocol entity mapping table; decoding protocol main body data in the byte array, and generating a Java protocol main body data object corresponding to the OTA protocol main body data by contrasting a protocol entity mapping table;
step S03, encoding the Java message head object, the Java message main body object and the Java protocol main body data object and generating a byte array;
step S04, assembling the message header, the message body and the protocol body data as the message data sent to the TBOX by the TSP;
the decoding of the message body and the protocol body data in step S02 and the encoding of the message body and the protocol body data in step S03 are implemented by the asn.1 codec module.
In step S01, TBOX _ otareq: the Request class, representing an OTA service Request or response, includes Header, Body and protocol Body data. Firstly, receiving message data sent to the TSP by the TBOX, namely the byte number of the OTA message, and analyzing the message data. And then converting the OTARequest into a byte array.
The decoding process of the header in step S02 is: and directly decoding the message header in the byte array into a Java message header object. TBOX _ DispatcherHeader: the Header of the protocol map contains the total Byte length of the current message, the total number of bytes (Byte) of Dispatcher Header and Dispatcher Body. unwrappidpitcher header (): the DispatcherHeader is decoded without the encoding algorithm. The Header object is returned.
The decoding process of the message body in step S02 is: binary data of a message body is read from an input stream, a decoding external interface statement class IDecoder corresponding to a coding type is obtained through a factory class CoderFactory of an ASN.1 coding and decoding module, a decoding method corresponding to a decoding type is obtained through an ASN.1 type processing library, and a Java message body object is generated. TBOX _ DispatcherBody: the body of the protocol map includes an AID (Application classification indicating transferred Application Data), an MID (unique identification of a message under the same AID), an Event Creation Time (message Creation Time), an Application Data Length (message body Byte Length), and the like. Specifically, unwrappidispatchebody (): binary data is read from the InputStream for decoding and a dispatchbody object is generated.
The decoding process of the protocol body data in step S02 is: reading binary data of a protocol body from an input stream, acquiring a decoding external interface statement class IDecoder corresponding to a coding type through a factory class CoderFactory of an ASN.1 coding and decoding module, further acquiring a decoding method corresponding to a decoding type through an ASN.1 type processing library, and further generating a Java protocol body data object. Specifically, unwrappalindrordata (): binary data is read from the InputStream for decoding, and a java protocol body data object is generated. And acquiring an IDecoder method corresponding to a fixed coding type (fixed as PER/Unaligned) through CoderFactory, wherein the transmission parameter is a JAVA object class for receiving decoded data. And reading the data in the InputStream for decoding.
The encoding process of the header in step S03 is: and directly coding the Java message header object into a byte array. wrapppitcher header (): and (3) coding the DispatcherHeader, and directly converting the TBOX _ DispatcherHeader class of the group in the parameter into a byte [ ] array without a coding algorithm.
The encoding process of the message body in step S03 is: acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java message main body object. Specifically, bob needs to perform asn.1 encoding separately, and performs different instance encoding according to different instances.
The encoding process of the protocol body data in step S03 is: and acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java protocol main body data object. Specifically, a JAVA protocol main data object is coded, an IEncoder method corresponding to a fixed coding type (here, fixed as PER/Unaligned) is obtained through CoderFactory, a parameter is a JAVA object class needing coding, and after the coding is completed, data is written into BitAlrayOutputStream.
In step S04, the total data length including Header, Body, and appdata is calculated and set in the Header, and finally, the complete data message is output.
In addition, the method of the invention also comprises the step of judging that the coding and the decoding are abnormal when the data length exceeds the limitation of the OTA protocol in the coding and decoding process. Different exceptions may be captured during encoding/decoding of different data types, for example, when encoding an Integer type, if the data Length exceeds 0x4000, an exception reminder "Not supported for this version. When the enumeration type is decoded, if the data length < =0, then an "Unable to present and item!" exception reminder, etc. is thrown. OTA encoding/decoding defines TBOX _ AdapterException exception class, and the class inherits RuntimeException.
The invention uses the Unaligned compression coding rule (Unaligned-PER) of the ASN.1 to achieve the maximum compression ratio of the message. The invention can realize the coding modes of BER, DER, PER and the like at the same time, but mainly uses Unaligned-PER as the main mode.
The invention solves the dependence on the ASN.1 file and is more convenient to carry out problem troubleshooting. Meanwhile, due to the fact that a JAVA annotation mode is used, the ASN.1 object is written more simply and conveniently, the byte array coded by the ASN.1 is directly converted into the object, or the JAVA object is converted into the byte array in the ASN.1 format, the JAVA object is directly operated by service development, the ASN.1 coding does not need to be related, and development is more convenient.
It will be appreciated by persons skilled in the art that the embodiments of the invention described above and shown in the drawings are given by way of example only and are not limiting of the invention. The objects of the present invention have been fully and effectively accomplished. The functional and structural principles of the present invention have been shown and described in the examples, and any variations or modifications of the embodiments of the present invention may be made without departing from the principles.

Claims (9)

1. A message data coding and decoding method is characterized in that the method uses the non-alignment compression coding rule of ASN.1, and comprises the following steps:
step S01, receiving message data sent by TBOX to TSP and analyzing to obtain byte array of OTA service request or service response;
step S02, decoding the message header in the byte array and generating a Java message header object; decoding a message main body in the byte array, and generating a Java message main body object corresponding to the OTA message main body by contrasting a protocol entity mapping table; decoding protocol main body data in the byte array, and generating a Java protocol main body data object corresponding to the OTA protocol main body data by contrasting a protocol entity mapping table; the protocol entity mapping table can obtain a Java protocol entity corresponding to the OTA protocol entity;
step S03, encoding the Java message head object, the Java message main body object and the Java protocol main body data object and generating a byte array;
step S04, assembling the message header, the message body and the protocol body data as the message data sent to the TBOX by the TSP;
wherein, the decoding of the message body and the protocol body data in the step S02 and the encoding of the message body and the protocol body data in the step S03 are realized by using an asn.1 encoding and decoding module; the ASN.1 coding and decoding module is suitable for OTA protocol and comprises:
ASN.1 type library including all base classes for encoding and decoding;
ASN.1 type processing library, including coding and decoding processing method entries corresponding to all coding and decoding types;
the PERALIGNED DECODER class defines a decoding processing method corresponding to all decoding types;
the Decoder class is a father class of the PERALIGNED Decoder class and an implementation class of the IDecoder class;
an IDecoder class, declaring classes for decoded external interfaces;
an IASN1 typeDecoder class which is an interface declaration class of decoding processing methods corresponding to all decoding types;
PERALIGNED ENCODER class, which defines the coding processing method corresponding to all coding types;
the Encoder class is a father class of the PERALIGNED Encoder class and is an implementation class of the IEncoder class;
IEncoder type, which is an external interface declaration type of codes;
an IASN1TypesEncoder class which is an interface declaration class of the coding processing method corresponding to all coding types;
and the factory class CoderFactory is used for acquiring the IDecoder class or the IEncoder class.
2. The message data encoding and decoding method according to claim 1,
the decoding process of the header in step S02 is: directly decoding the message header in the byte array into a Java message header object;
the encoding process of the header in step S03 is: and directly coding the Java message header object into a byte array.
3. The message data encoding and decoding method according to claim 1,
the decoding process of the message body in step S02 is:
reading binary data of a message body from an input stream, acquiring a decoding external interface statement class IDecoder corresponding to a coding type through a factory class CoderFactory of an ASN.1 coding and decoding module, further acquiring a decoding method corresponding to the decoding type through an ASN.1 type processing library, and further generating a Java message body object;
the encoding process of the message body in step S03 is:
acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java message main body object.
4. The message data encoding and decoding method according to claim 1,
the decoding process of the protocol body data in step S02 is:
reading binary data of a protocol body from an input stream, acquiring a decoding external interface statement class IDecoder corresponding to a coding type through a factory class CoderFactory of an ASN.1 coding and decoding module, further acquiring a decoding method corresponding to the decoding type through an ASN.1 type processing library, and further generating a Java protocol body data object;
the encoding process of the protocol body data in step S03 is:
and acquiring an encoding external interface statement class IEncoder corresponding to the encoding type through a factory class CoderFactory, further acquiring an encoding method corresponding to the encoding type through an ASN.1 type processing library, and further encoding the Java protocol main body data object.
5. The method of claim 1, wherein the process of constructing the asn.1 type base includes: encoding a String type, an Integer type, a Boolean type and an Element attribute Element type.
6. The method of claim 5, wherein before coding the Integer type, declaring a maximum minimum interval of fields:
if the range is less than or equal to 255, encoding into a bit field of minimum size for the range;
if the range happens to be 256, then encode as an octet alignment bit field;
if the range is 257 to 64K, then encoding into two octet aligned bit fields;
if the range is greater than 64K, then the encoding is an octal alignment bit field, which is the minimum octal number of encoded values.
7. The message data encoding and decoding method according to claim 5, wherein in the process of constructing the ASN.1 type library, further comprising: and checking and verifying the attributes in the class, wherein if the range, the attribute and the length exceed the limits of the OTA protocol, the attribute verification in the class is abnormal.
8. The message data encoding and decoding method according to claim 1, wherein in the encoding and decoding process, if the data length exceeds the limitation of the OTA protocol, it is determined that the encoding and decoding are abnormal.
9. The message data encoding and decoding method according to claim 1, wherein the asn.1 type library includes String, Integer, Boolean, Element attribute Element types.
CN201910768505.5A 2019-08-20 2019-08-20 ASN.1 coding and decoding module and message data coding and decoding method Active CN110601794B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910768505.5A CN110601794B (en) 2019-08-20 2019-08-20 ASN.1 coding and decoding module and message data coding and decoding method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910768505.5A CN110601794B (en) 2019-08-20 2019-08-20 ASN.1 coding and decoding module and message data coding and decoding method

Publications (2)

Publication Number Publication Date
CN110601794A CN110601794A (en) 2019-12-20
CN110601794B true CN110601794B (en) 2022-05-24

Family

ID=68854815

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910768505.5A Active CN110601794B (en) 2019-08-20 2019-08-20 ASN.1 coding and decoding module and message data coding and decoding method

Country Status (1)

Country Link
CN (1) CN110601794B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112188211B (en) * 2020-08-21 2024-09-17 北京新媒传信科技有限公司 Transcoding realization method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1359065A (en) * 2000-12-15 2002-07-17 国际商业机器公司 Method and system for converting abstract syntax notation 1 data model to object model
CN101197818A (en) * 2006-12-08 2008-06-11 中兴通讯股份有限公司 ASN.1 packet object oriented processing method
CN101222365A (en) * 2008-01-23 2008-07-16 中兴通讯股份有限公司 Similar C structure interface packet processing method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2004318284B2 (en) * 2004-04-09 2008-10-30 Huawei Technologies Co., Ltd. ASN.1 protocol processor and method for ASN.1 protocol processing

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1359065A (en) * 2000-12-15 2002-07-17 国际商业机器公司 Method and system for converting abstract syntax notation 1 data model to object model
CN101197818A (en) * 2006-12-08 2008-06-11 中兴通讯股份有限公司 ASN.1 packet object oriented processing method
CN101222365A (en) * 2008-01-23 2008-07-16 中兴通讯股份有限公司 Similar C structure interface packet processing method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"ASN.1介绍";大漠落日;《http://www.cppblog.com/smagle/archive/2011/05/10/146088.html》;20110510;全文 *

Also Published As

Publication number Publication date
CN110601794A (en) 2019-12-20

Similar Documents

Publication Publication Date Title
Freed et al. Multipurpose internet mail extensions (MIME) part one: Format of internet message bodies
KR100424130B1 (en) Data compression apparatus, database system, data communication system, data compression method, storage medium and program transmission apparatus
CN112333186B (en) Data communication method, device, equipment and storage medium
CN110597814B (en) Structured data serialization and deserialization method and device
CN110601794B (en) ASN.1 coding and decoding module and message data coding and decoding method
CN114492316B (en) Data exchange coding and decoding method and system
CN110381056B (en) Netty-based private protocol coding and decoding method and apparatus
CN100493046C (en) Coding/decoding method for communication system information and coder/decoder
CN113742294A (en) Method, system, device and medium for decoding ASN.1-PER signaling message
US8954400B2 (en) Method, system and program product for managing structured data
Mitra Efficient Encoding Rules for ASN. 1‐Based Protocols
CN116244361B (en) Method and system for dynamic persistence processing of database connection
CN110839022A (en) Vehicle-mounted control software communication protocol analysis method based on xml language
CN112486885B (en) Data frame generation method, storage medium and computer equipment
CN111064560B (en) Data encryption transmission method and device, terminal and data encryption transmission system
CN101257387B (en) X509 digital certificate quick analyzing and verifying method
CN114025024A (en) Data transmission method and device
KR101142322B1 (en) ASN.1 Compiler
CN111510159B (en) Intelligent coding method and coder following general information exchange protocol specification
CN100589358C (en) Metod and system for processing messages, and message sending end and message receiving end
Jander et al. Compact and efficient agent messaging
CN111913714B (en) Method and device for mapping substation control layer communication service of transformer substation based on Thrift
KR20060057008A (en) Method and system for monitoring communication and monitoring protocol
CN114390032B (en) Outlet gateway request method, device, equipment and medium
CN118174891A (en) Protocol data processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 314500 988 Tong Tong Road, Wu Tong Street, Tongxiang, Jiaxing, Zhejiang

Patentee after: Hozon New Energy Automobile Co., Ltd.

Address before: 314500 room 206, No. 999, Qingfeng South Road, Tongxiang Economic Development Zone, Tongxiang City, Jiaxing City, Zhejiang Province

Patentee before: Hozon New Energy Automobile Co., Ltd.

CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: 314500 988 Tong Tong Road, Wu Tong Street, Tongxiang, Jiaxing, Zhejiang

Patentee after: United New Energy Automobile Co.,Ltd.

Address before: 314500 988 Tong Tong Road, Wu Tong Street, Tongxiang, Jiaxing, Zhejiang

Patentee before: Hozon New Energy Automobile Co., Ltd.