The invention relates to the technical field of communication, and provides an ASN.1-PER dynamic and static encoding and decoding method based on a 3GPP protocol, and the method comprises the steps: 100, obtaining a compiling option and an ASN.1 text configured by a user, wherein the compiling option comprises a protocol name, a structural body prefix, a constant type prefix, a
macro definition prefix, an enumeration type prefix and dynamic and static information for controlling dynamic and static states; step 200, taking the ASN.1 text and the compiling options as input, and inputting the ASN.1 text and the compiling options into an ASN.1 text
compiler; step 300, enabling the ASN.1 text
compiler to process the ASN.1 text to generate a required interface file and a
data file; and 400, performing encoding or decoding according to the generated interface file and
data file, and outputting an encoding result after encoding or outputting a decoding result after decoding. The method can improve the flexibility of a product, and has the advantages of small size of a dynamic structure and high efficiency of a
static structure.