Data communication method for relay protection device, relay protection device and medium
By introducing a new encoding format with a variable-length prefix portion for data type and length description in relay protection devices, the problems of resource waste and insufficient flexibility of existing encoding formats are solved, and efficient and flexible data exchange and self-description capabilities are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XUCHANG XJ SOFTWARE TECHNOLOGIES LTD
- Filing Date
- 2025-12-16
- Publication Date
- 2026-05-01
AI Technical Summary
The existing communication coding format of relay protection devices lacks flexibility and self-description capability, resulting in resource waste and difficulty in adapting to the needs of complex data structures. In particular, in scenarios of multi-system integration and cross-platform collaborative work, traditional coding formats are unable to meet the requirements of efficient and flexible data exchange.
A novel encoding format is adopted, which dynamically describes the data type and length by introducing a variable-length prefix in the data type prefix part. It supports flexible encoding of integer, floating-point, string, array, mapping and binary data, and achieves self-description and saves storage space.
It effectively solves the limitations of traditional coding in terms of flexibility, type expression, and support for complex data structures, greatly saves data storage space, and improves data transmission efficiency and system flexibility.
Smart Images

Figure CN121966575A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of communication technology, specifically relating to a data communication method for a relay protection device, as well as the relay protection device and medium. Background Technology
[0002] In terms of communication coding, relay protection devices currently widely adopt compact binary coding, such as fixed-length structures, variable-length structures, and TLV (Tag-Length-Value) forms. In communication scenarios conforming to standards such as 103, 104, and 61850, the coding structure is usually tightly coupled with the protocol. The position, data type, and length of fields are strictly defined to ensure consistency and interoperability between devices. The 103 / 104 protocol achieves remote information transmission through a standardized APDU (Application Protocol Data Unit) structure; while the 61850 MMS (Manufacturing Message Specification) protocol uses ASN.1 coding, which can support more complex data modeling, but the corresponding implementation complexity and resource consumption are also increased.
[0003] Within relay protection devices, such as between function boards, between communication modules and human-machine interfaces, and between storage or printing devices, communication data typically uses manufacturer-defined message formats. These custom formats are primarily designed to achieve specific device functions, minimizing processing overhead while maintaining communication reliability to adapt to resource-constrained embedded operating environments.
[0004] While the aforementioned coding methods demonstrate excellent efficiency and stability, their lack of flexible type expression and self-descriptive structural capabilities limits their ability to address new demands such as complex configuration parameters, dynamic structural changes, and multi-system integration. With the development of intelligent and information-based power systems, communication coding is gradually evolving towards clearer structures, greater scalability, and better cross-platform compatibility to adapt to future flexible and efficient protection and control system architectures.
[0005] The existing communication data encoding format of relay protection devices has the following problems: (1) Lack of structural flexibility: Existing encoding formats mostly adopt fixed-length or variable-length binary formats, and the type, order, and length of fields are strictly defined in the protocol, lacking dynamic expansion capabilities. When it is necessary to add functional fields or adapt to the data exchange needs of different scenarios, it is often necessary to redefine the protocol structure, resulting in high modification costs and poor compatibility. This is mainly because traditional encoding was designed with the premise of limited embedded hardware resources and limited transmission bandwidth, prioritizing data compactness and processing efficiency rather than structural universality and evolvability.
[0006] (2) Limited type expression capabilities and lack of self-description mechanisms: Most traditional encoding formats cannot clearly distinguish complex data types (such as integers and floating-point numbers, enumerations and strings), nor do they possess the inherent semantic information expression capabilities of field meaning, units, and value ranges, heavily relying on documentation and manual parsing. This design philosophy primarily serves low-level data communication rather than high-level system integration and data modeling. Therefore, in the current context of multi-platform and multi-system collaborative work, it is difficult to meet practical needs such as automatic parsing and dynamic adaptation.
[0007] (3) Difficulty in adapting to the demands of complex data structures in technological evolution: From the perspective of the technological evolution of relay protection devices, early devices had relatively simple functions, with communication content mainly consisting of telemetry and remote signaling, and fixed and simple message formats were sufficient to meet the requirements. However, with the development of intelligence and integration, the devices have integrated more complex functions such as logic control, status monitoring, and parameter configuration, and the data structure has also become more complex. The original static and rigid coding methods are difficult to adapt to the current cross-system and cross-platform data exchange scenarios, leading to the evolution of coding technology from a compact structure solely guided by transmission efficiency to a composite coding form that takes into account efficiency, structural expression, and flexible expansion capabilities, in order to better support the development of protection devices towards networking and platformization.
[0008] In the traditional TLV format, regardless of the data to be transmitted, the Tag part representing the data type and the Length part representing the data length always need to occupy one byte each. This allocation of fixed-length space for all data results in a huge waste and leads to low efficiency when processing data containing a large number of small values. Summary of the Invention
[0009] The purpose of this invention is to provide a data communication method for relay protection devices, as well as the relay protection device and medium, to solve the technical problem of resource waste caused by allocating a fixed length of space for all data in the prior art.
[0010] To solve the above-mentioned technical problems, the present invention provides a technical solution for a data communication method for a relay protection device, comprising: a data communication method for a relay protection device, the method comprising: S1. Obtain the data to be transmitted from the relay protection device; S2. Serialize the data to be sent into a byte stream according to a preset encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. S3. Send the byte stream.
[0011] The beneficial effects of the above technical solution are as follows: This invention uses a novel encoding format for data communication. This encoding format, with its unique advantages, effectively solves the inherent limitations of traditional encoding in terms of flexibility, type expression, information self-description, and support for complex data structures. By flexibly setting the encoding of the traditional fixed-byte constant type part as a variable-length prefix part, it greatly saves data storage space. This invention solves the technical problem of resource waste caused by allocating a fixed-length space for all data in the prior art.
[0012] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; When the prefix part of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0013] Furthermore, when the length of the prefix portion of the string is three bits, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the string is one byte, the length of its corresponding length part is one, two, or four bytes.
[0014] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the array or mapping is one byte, the length of its corresponding length part is two or four bytes.
[0015] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0016] Furthermore, for extended data types that allow customization, the byte stream can be a fixed-length encoded byte stream or a variable-length encoded byte stream; The fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric portion through different values, an extended type portion for representing user-defined extended subtypes through different values, and a numeric portion for storing data; The variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length portion through different values, a length portion for representing the length of the numerical portion through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numerical portion for storing data; The prefix portion of the extended type has a length of one byte; the length portion has a length of one, two, or four bytes; and the extended type portion has a length of one byte.
[0017] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0018] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0019] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0020] This invention also provides a technical solution for a data communication method for a relay protection device: a data communication method for a relay protection device, the method comprising: (1) Receive the byte stream to be parsed from the relay protection device; (2) Parse the byte stream into data according to the agreed encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte.
[0021] The beneficial effects of the above technical solution are as follows: This invention uses a novel encoding format for data communication. This encoding format, with its unique advantages, effectively solves the inherent limitations of traditional encoding in terms of flexibility, type expression, information self-description, and support for complex data structures. By flexibly setting the encoding of the traditional fixed-byte constant type part as a variable-length prefix part, it greatly saves data storage space. This invention solves the technical problem of resource waste caused by allocating a fixed-length space for all data in the prior art.
[0022] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; When the prefix part of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0023] Furthermore, when the length of the prefix portion of the string is three bits, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the string is one byte, the length of its corresponding length part is one, two, or four bytes.
[0024] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the array or mapping is one byte, the length of its corresponding length part is two or four bytes.
[0025] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0026] Furthermore, for extended data types that allow customization, the byte stream can be a fixed-length encoded byte stream or a variable-length encoded byte stream; The fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric portion through different values, an extended type portion for representing user-defined extended subtypes through different values, and a numeric portion for storing data; The variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length portion through different values, a length portion for representing the length of the numerical portion through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numerical portion for storing data; The prefix portion of the extended type has a length of one byte; the length portion has a length of one, two, or four bytes; and the extended type portion has a length of one byte.
[0027] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0028] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0029] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0030] The present invention also provides a technical solution for a relay protection device: a relay protection device, comprising a processor, the processor being used to execute a computer program to implement the following steps of a data communication method for a relay protection device: S1. Obtain the data to be transmitted from the relay protection device; S2. Serialize the data to be sent into a byte stream according to a preset encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. S3. Send the byte stream.
[0031] The beneficial effects of the above technical solution are as follows: This invention uses a novel encoding format for data communication. This encoding format, with its unique advantages, effectively solves the inherent limitations of traditional encoding in terms of flexibility, type expression, information self-description, and support for complex data structures. By flexibly setting the encoding of the traditional fixed-byte constant type part as a variable-length prefix part, it greatly saves data storage space. This invention solves the technical problem of resource waste caused by allocating a fixed-length space for all data in the prior art.
[0032] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; When the prefix part of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0033] Furthermore, when the length of the prefix portion of the string is three bits, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the string is one byte, the length of its corresponding length part is one, two, or four bytes.
[0034] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the array or mapping is one byte, the length of its corresponding length part is two or four bytes.
[0035] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0036] Furthermore, for extended data types that allow customization, the byte stream can be a fixed-length encoded byte stream or a variable-length encoded byte stream; The fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric portion through different values, an extended type portion for representing user-defined extended subtypes through different values, and a numeric portion for storing data; The variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length portion through different values, a length portion for representing the length of the numerical portion through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numerical portion for storing data; The prefix portion of the extended type has a length of one byte; the length portion has a length of one, two, or four bytes; and the extended type portion has a length of one byte.
[0037] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0038] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0039] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0040] The present invention also provides a technical solution for a computer-readable storage medium: a computer-readable storage medium having a computer program stored internally, the computer program being executed by a processor to implement the steps of the data communication method for a relay protection device as described below: S1. Obtain the data to be transmitted from the relay protection device; S2. Serialize the data to be sent into a byte stream according to a preset encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. S3. Send the byte stream.
[0041] The beneficial effects of the above technical solution are as follows: This invention uses a novel encoding format for data communication. This encoding format, with its unique advantages, effectively solves the inherent limitations of traditional encoding in terms of flexibility, type expression, information self-description, and support for complex data structures. By flexibly setting the encoding of the traditional fixed-byte constant type part as a variable-length prefix part, it greatly saves data storage space. This invention solves the technical problem of resource waste caused by allocating a fixed-length space for all data in the prior art.
[0042] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; When the prefix part of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0043] Furthermore, when the length of the prefix portion of the string is three bits, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the string is one byte, the length of its corresponding length part is one, two, or four bytes.
[0044] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining portion of the first byte of the corresponding byte stream is the length portion; When the length of the prefix part of the array or mapping is one byte, the length of its corresponding length part is two or four bytes.
[0045] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0046] Furthermore, for extended data types that allow customization, the byte stream can be a fixed-length encoded byte stream or a variable-length encoded byte stream; The fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric portion through different values, an extended type portion for representing user-defined extended subtypes through different values, and a numeric portion for storing data; The variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length portion through different values, a length portion for representing the length of the numerical portion through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numerical portion for storing data; The prefix portion of the extended type has a length of one byte; the length portion has a length of one, two, or four bytes; and the extended type portion has a length of one byte.
[0047] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0048] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0049] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes. Attached Figure Description
[0050] Figure 1 This is the single-byte encoding rule for the data communication method implementation of the present invention for relay protection devices; Figure 2 This is a fixed-length data encoding rule for an embodiment of the data communication method for relay protection devices according to the present invention; Figure 3 This is a variable-length data encoding rule for an embodiment of the data communication method for relay protection devices according to the present invention; Figure 4 This is an extended data encoding rule for an implementation of the data communication method for relay protection devices according to the present invention. Detailed Implementation
[0051] This invention employs a novel encoding format for data communication. This format, with its unique advantages, effectively overcomes the inherent limitations of traditional encoding in terms of flexibility, type representation, information self-description, and support for complex data structures. By flexibly setting the encoding of the traditional fixed-byte constant type portion as a variable-length prefix, it significantly saves data storage space. This invention solves the technical problem of resource waste caused by allocating a fixed-length space for all data in existing technologies.
[0052] Implementation methods for data communication methods used in relay protection devices: With the continuous improvement of the intelligence level of power systems, the communication and data interaction needs of relay protection devices are becoming increasingly complex. These needs are no longer limited to traditional telemetry and remote signaling data transmission, but have expanded to various scenarios such as configuration parameter distribution, operational status reporting, online diagnostics, remote debugging, and human-machine interaction. These new applications place higher demands on communication coding, requiring it to simultaneously possess efficient and compact transmission characteristics, good structural expression capabilities, type self-description capabilities, and scalability and compatibility. However, traditional coding methods generally suffer from problems such as strong structural rigidity, poor scalability, and weak semantic expression capabilities, making it difficult to meet the current practical needs of multi-service integration and multi-device collaborative operation.
[0053] In this context, adopting an encoding method that combines lightweight, high efficiency, and structured features has become a key requirement. This encoding method should support multiple basic and composite data types, possessing strong type recognition and structure identification capabilities to facilitate automatic system parsing and dynamic adaptation; simultaneously, it should maintain a compact binary representation to meet the stringent requirements of power systems for real-time communication and resource consumption. Furthermore, this encoding method should be cross-platform compatible, seamlessly integrating into heterogeneous systems such as embedded terminals, edge computing nodes, and backend servers, supporting end-to-end data transmission and processing from the device to the application layer.
[0054] In scenarios where the need for device configuration parameters, enumeration value display, and nested structure transmission is becoming increasingly frequent, the original fixed-length fields and fixed structures are no longer sufficient. Engineering practice has also revealed that when faced with data that needs to be transmitted with dynamic structures, variable fields, and uncertain types, traditional methods often require a large amount of manual parsing logic, leading to increased development and maintenance costs and reduced system flexibility.
[0055] The data communication method for relay protection devices includes the following steps: S1. Obtain the data to be sent from the relay protection device.
[0056] S2. Serialize the data to be sent into a byte stream according to a preset encoding format.
[0057] This implementation proposes an efficient binary serialization encoding format, aiming to provide a compact and fast data exchange method. By directly serializing data structures (such as arrays and mapping key-value pairs) and basic data types (such as integers, floating-point numbers, strings, booleans, and null data) into byte streams, flexible and efficient data transmission is achieved within relay protection devices and between power system equipment.
[0058] This encoding method represents data with as few bytes as possible while maintaining fast parsing. Through type embedding (i.e., the prefix portion), compact encoding, and support for common data types, it achieves efficient encoding while imbuing the data itself with a certain degree of self-descriptive information. Type embedding: This method directly encodes the data's type information into the prefix bytes (i.e., the prefix portion) of the data itself. After reading one or a few bytes, the parser can immediately determine the type and length of the following data. Unlike traditional fixed structures or protocols that rely entirely on external definitions, this gives the data a certain degree of self-descriptive capability.
[0059] Compact encoding: This method employs variable-length encoding for different data types and numerical ranges. For example, small integers can be represented using one byte, while larger integers require more bytes. This approach avoids the waste of allocating fixed-length space for all data, and is particularly effective when processing data containing a large number of small values.
[0060] Common data type support: Supports arrays and maps (i.e., collections of key-value pairs), enabling complex data structures to be represented directly and naturally without the need for complex conversions or reliance on fixed structure definitions, as is the case with some traditional binary formats.
[0061] For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical part through different values and a numerical part for storing the data; for strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type and length range of the numerical part through different values, a length portion for representing the length of the numerical part through different values, and a numerical part for storing the data; the length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte.
[0062] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; when the prefix portion of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0063] Furthermore, when the length of the prefix part of the string is three bits, the remaining part of the first byte of the corresponding byte stream is the length part; when the length of the prefix part of the string is one byte, the length of the corresponding length part is one, two, or four bytes.
[0064] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining part of the first byte of its corresponding byte stream is the length portion; when the length of the prefix portion of the array or mapping is one byte, the length of its corresponding length portion is two or four bytes.
[0065] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0066] Furthermore, for extended type data that allows customization, its byte stream is a fixed-length encoded byte stream or a variable-length encoded byte stream; the fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length part through different values, a length portion for representing the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the length of the extended type prefix portion is one byte; the length of the length portion is one, two, or four bytes; the length of the extended type portion is one byte.
[0067] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0068] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0069] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0070] Specifically, it defines data format specifications, detailing how each data type is encoded into a sequence of bytes.
[0071] The first byte defines the type: The first byte (or the first few bytes) of each data unit indicates the data type and the length or value of the data itself.
[0072] Recursive encoding: Supports complex structures such as arrays and maps, which are recursively encoded, and their elements or key-value pairs are also recursively encoded in the same format.
[0073] Single-byte data encoding: For some frequently used data that occupies little space, its type and value are directly encoded using a single byte, thus achieving extremely high efficiency. For example, small integers from -32 to 127, empty data, and Boolean values are all encoded using a single byte, significantly reducing the number of bytes of encoded data and improving transmission efficiency.
[0074] The encoding representation of single-byte data is: TAG(DATA), where TAG is the prefix and DATA represents the numerical part.
[0075] In this embodiment, single-byte data encoding is as follows: Figure 1 As shown, Figures 1-4 In the byte stream, D7~D0 represent the first 8 bits of the byte stream: like Figure 1 As shown, decimal integers between 0 and 127 can be encoded using a single byte of data. When D7=0 (i.e., the prefix part TAG), the positive integers 0 to 127 can be represented by the remaining 7 bits (i.e., the value part DATA). For example, 10000011 can be used to represent the integer 3.
[0076] like Figure 1 As shown, integers between -1 and -31 in decimal can also be encoded using single-byte data. When D7~D5=111 (i.e., the prefix part TAG), negative integers between -1 and -31 can be represented by the remaining 5 bits (i.e., the numerical part DATA). For example, 11111111 can be used to represent the integer -31.
[0077] like Figure 1 As shown, in addition to the above, single-byte data encoding also includes: using 11000000 to represent empty data (i.e., D7~D0=11000000), using 11000010 to represent the false Boolean value (i.e., false) (i.e., D7~D0=11000010), and using 11000011 to represent the true Boolean value (i.e., true) (i.e., D7~D0=11000011).
[0078] Fixed-length data encoding: Defines fixed-length formats to represent data of a specific size. A fixed number of bytes (or data bits) follow the prefix byte to represent the data value. Fixed-length data encoding includes: single / double-precision floating-point numbers, 1 / 2 / 4 / 8-byte signed / unsigned integers, etc. The data type and length can be obtained solely from the format byte (i.e., the prefix part). The encoded representation of fixed-length data is: TAG|DATA. Where TAG is the prefix part (…). Figure 2The blue part in the image), DATA represents the numerical part ( Figure 2 (The white part in the middle).
[0079] like Figure 2 As shown, the prefix byte of single / double precision floating-point numbers (32-bit / 64-bit floating-point numbers) Figure 2 The blue parts in the image are 11001010 and 11001011, respectively, and the corresponding numerical parts are ( Figure 2 The lengths of the white parts in the text are 4 bytes and 8 bytes respectively.
[0080] like Figure 2 As shown, the prefix bytes corresponding to unsigned integer data of different byte lengths ( Figure 2 The blue parts in the image are 11001100 to 11001111, where the first 6 bits (i.e., 110011) represent unsigned integer data, and the last two bits (00~11) represent the numerical part of the unsigned integer data. Figure 2 The byte length of the white part in the image is as follows: 00 corresponds to 1 byte, 01 corresponds to 2 bytes, 10 corresponds to 4 bytes, and 11 corresponds to 8 bytes.
[0081] like Figure 2 As shown, the prefix bytes corresponding to signed integer data of different byte lengths ( Figure 2 The blue parts in the image are 11010000 to 11010011, where the first 6 bits (i.e., 110100) represent signed integer data, and the last two bits (00~11) represent the numerical part of the signed integer data. Figure 2 The byte length of the white part in the image is as follows: 00 corresponds to 1 byte, 01 corresponds to 2 bytes, 10 corresponds to 4 bytes, and 11 corresponds to 8 bytes.
[0082] Variable-length data encoding: such as Figure 3 As shown, for data of uncertain or potentially very long length, variable-length encoding is used. This means that a prefix byte is followed by one or more bytes to represent the data length (i.e., the length portion), and then the actual data content. Variable-length data encoding includes: strings of 0-31 bytes, mappings and arrays with 0-15 elements, strings of 1 / 2 / 4 byte length, binary data of 1 / 2 / 4 byte length, mappings and arrays of 1 / 2 / 4 byte length, etc. With the prefix byte and the length portion (maximum 5 bytes), up to 4GB of corresponding data can be supported. The encoding representation of variable-length data is: TAG|Length|DATA. TAG is the prefix portion (…). Figure 3 The blue part in the image), Length represents the length part ( Figure 3 The yellow part in the image), DATA represents the numerical part ( Figure 3 (The white part in the middle).
[0083] like Figure 3 As shown, when D7~D4=1000 (i.e., the prefix part TAG), it can represent mapped data. The number of mapped data is represented by the value of D3~D0 (i.e., the length part Length). The 4-bit binary number of D3~D0 can represent the decimal number 0~15. Therefore, when using this format to represent mapped data, the number of mappings should be between 0 and 15.
[0084] like Figure 3 As shown, when D7~D4=1001 (i.e., the prefix part TAG), it can represent array data, and the value of D3~D0 (i.e., the length part Length) indicates the number of elements in the array data. The 4-bit binary number of D3~D0 can represent the decimal number 0~15. Therefore, when using this format to represent array data, the number of its elements should be between 0 and 15.
[0085] like Figure 3 As shown, when D7~D5=101 (i.e., the prefix part TAG), it can represent string data, and the length of the string is represented by the value of D4~D0 (i.e., the length part Length). The 5 binary numbers of D4~D0 can represent decimal numbers 0~31. Therefore, when using this format to represent string data, the length of the string should be between 0 and 31.
[0086] like Figure 3 As shown, the prefix bytes corresponding to string data of different byte length ranges ( Figure 3 The blue parts in the image represent the string data type 11011001 to 11011011. The first six bits (110110) indicate the string data type, and the last two bits (01-11) represent the length of the string data in bytes: 01 corresponds to 1 byte, 10 to 2 bytes, and 11 to 4 bytes. For example, a prefix byte of 11011001 can represent a string with a length between 16 and 255 bytes.
[0087] like Figure 3 As shown, the prefix bytes corresponding to array data with different ranges of element counts ( Figure 3 The blue parts in the image represent numbers from 11011100 to 11011101. The first six bits (110111) indicate an array or mapped data type, while the last two bits (00-01) represent the number of elements in the array (the length part) in bytes: 00 corresponds to 2 bytes, and 01 corresponds to 4 bytes. For example, a prefix byte of 11011100 indicates a number of elements between 16 and 2^6. 16 An array between [variables].
[0088] like Figure 3 As shown, the prefix bytes corresponding to the mapping data for different ranges of mapping numbers ( Figure 3 The blue parts in the image represent the range 11011110 to 11011111. The first six bits (110111) indicate an array or mapped data type, while the last two bits (10-11) represent the number of mapped data elements (the length part) in bytes: 10 corresponds to 2 bytes, and 11 corresponds to 4 bytes. For example, a prefix byte of 11011110 indicates a byte length between 16 and 2 bytes. 16 An array of more than 200 elements.
[0089] like Figure 3 As shown, the prefix bytes corresponding to binary data of different byte length ranges are respectively ( Figure 3 The blue part (11000100~11000110) represents binary data. The first 6 bits (110001) indicate the binary data type, and the last two bits (00~10) indicate the byte length of the binary data: 00 corresponds to 1 byte, 01 corresponds to 2 bytes, and 10 corresponds to 4 bytes. For example, a prefix byte of 11000100 can represent binary data with a byte length between 0 and 255.
[0090] Extended data encoding: such as Figure 4 As shown, extended types are provided, allowing users to define custom data types, thus supporting data formats not explicitly defined in the encoding specification, such as date and time, UUID (universally unique identifier), etc. According to the encoding rules, extended data also supports both fixed-length and variable-length encoding. The encoding representation of fixed-length extended data is: TAG|ExtTYPE|DATA; the encoding representation of variable-length extended data is: TAG|Length|ExtTYPE|DATA. TAG is the prefix part (…). Figure 4 The blue part in the image), Length represents the length part ( Figure 4 The yellow portion (indicated by the extTYPE symbol) represents the extended type code, which is user-defined, uses one byte, and can represent 256 extended types. DATA represents the numerical part.
[0091] like Figure 4 As shown, for extended type data, a fixed-length encoded byte stream is obtained through fixed-length encoding, and a variable-length encoded byte stream is obtained through variable-length encoding.
[0092] For fixed-length encoded byte streams, such as Figure 4As shown in the upper part, when the prefix TAG is 11010100~11011000, it indicates a fixed-length encoding of the extended type. Different values represent the extended data length of the numeric part DATA. For example, the prefix 11010100 indicates that the numeric part is extended type data of 1 byte length. The specific data type format (extended subtype) defined by the user is indicated by the extended type part ExtTYPE (i.e.,...). Figure 4 The extended type code in the table indicates that the extended type code is one byte long and can represent 256 extended subtypes. In other words, in addition to the data formats that have been explicitly defined above (such as integers, strings, etc.), users can also define 256 additional data types, such as date and time data types.
[0093] For variable-length encoded byte streams, such as Figure 4 The lower part, as shown, is largely the same as a fixed-length encoded byte stream. The main difference lies in the prefix TAG: when the prefix TAG is 11000111~11001001, it represents an extended type of variable-length encoding. Different values of TAG represent the encoded length of the length portion (Length), which in turn represents the extended data length of the numeric portion (DATA). In other words, different values of the prefix TAG represent the length range of the extended data in the numeric portion (DATA). The rest is the same as a fixed-length encoded byte stream.
[0094] Recursive Data Encoding: Array and mapping types support recursive encoding, meaning that the elements of an array or the key-value pairs of a mapping can be any of the data types mentioned above, and are encoded according to the above format. This implies that the elements of an array or the key-value pairs of a mapping can themselves be any valid encoded data type, including other arrays and mappings. Recursive capability is key to the encoding format of this implementation's ability to represent complex data structures, making it well-suited for objects, configuration parameters, or any hierarchical data in serialization programming languages.
[0095] S3, Send byte stream.
[0096] Implementation methods of relay protection devices: A relay protection device includes a processor for executing a computer program to implement the steps of the data communication method for the relay protection device as described above. The specific data communication method for the relay protection device has been described in sufficient detail in the above-described embodiments and will not be repeated here.
[0097] The data communication method for relay protection devices includes the following steps: S1. Obtain the data to be sent from the relay protection device.
[0098] S2. Serialize the data to be sent into a byte stream according to a preset encoding format.
[0099] For integer data and floating-point numbers, the byte stream includes a prefix portion describing the data type and length of the numerical part through different values, and a numerical part for storing the data; for strings, arrays, mappings, and binary data, the byte stream includes a prefix portion describing the data type and length range of the numerical part through different values, a length portion representing the length of the numerical part through different values, and a numerical part for storing the data; the length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; when the prefix portion of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0100] Furthermore, when the length of the prefix part of the string is three bits, the remaining part of the first byte of the corresponding byte stream is the length part; when the length of the prefix part of the string is one byte, the length of the corresponding length part is one, two, or four bytes.
[0101] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining part of the first byte of its corresponding byte stream is the length portion; when the length of the prefix portion of the array or mapping is one byte, the length of its corresponding length portion is two or four bytes.
[0102] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0103] Furthermore, for extended type data that allows customization, its byte stream is a fixed-length encoded byte stream or a variable-length encoded byte stream; the fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length part through different values, a length portion for representing the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the length of the extended type prefix portion is one byte; the length of the length portion is one, two, or four bytes; the length of the extended type portion is one byte.
[0104] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0105] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0106] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0107] S3, Send byte stream.
[0108] Specifically, a processor can be a CPU, or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. A processor can also be a processor that supports the Advanced Reduced Instruction Set Machine (ARM) architecture.
[0109] Implementation of computer-readable storage media: A computer-readable storage medium storing a computer program is provided, characterized in that the computer program is processored to perform the steps of the data communication method for a relay protection device as described above. The specific data communication method for a relay protection device has been described in sufficient detail in the above-described embodiments and will not be repeated here.
[0110] The data communication method for relay protection devices includes the following steps: S1. Obtain the data to be sent from the relay protection device.
[0111] S2. Serialize the data to be sent into a byte stream according to a preset encoding format.
[0112] For integer data and floating-point numbers, the byte stream includes a prefix portion describing the data type and length of the numerical part through different values, and a numerical part for storing the data; for strings, arrays, mappings, and binary data, the byte stream includes a prefix portion describing the data type and length range of the numerical part through different values, a length portion representing the length of the numerical part through different values, and a numerical part for storing the data; the length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; when the prefix portion of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0113] Furthermore, when the length of the prefix part of the string is three bits, the remaining part of the first byte of the corresponding byte stream is the length part; when the length of the prefix part of the string is one byte, the length of the corresponding length part is one, two, or four bytes.
[0114] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining part of the first byte of its corresponding byte stream is the length portion; when the length of the prefix portion of the array or mapping is one byte, the length of its corresponding length portion is two or four bytes.
[0115] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0116] Furthermore, for extended type data that allows customization, its byte stream is a fixed-length encoded byte stream or a variable-length encoded byte stream; the fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length part through different values, a length portion for representing the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the length of the extended type prefix portion is one byte; the length of the length portion is one, two, or four bytes; the length of the extended type portion is one byte.
[0117] Furthermore, for empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
[0118] Furthermore, the length of the prefix portion of the floating-point number is one byte.
[0119] Furthermore, the prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
[0120] S3, Send byte stream.
[0121] Specifically, the computer-readable storage medium can be volatile memory or non-volatile memory, or a combination of both. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which serves as an external cache. For example, Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate Synchronous DRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), SynchLink DRAM (SLDRAM), or Direct Rambus RAM (DRRAM).
[0122] Implementation method 2 for data communication method for relay protection devices: A data communication method for a relay protection device, the method comprising: (1) Receive the byte stream to be parsed from the relay protection device.
[0123] (2) Parse the byte stream into data according to the agreed encoding format.
[0124] For integer data and floating-point numbers, the byte stream includes a prefix portion describing the data type and length of the numerical part through different values, and a numerical part for storing the data; for strings, arrays, mappings, and binary data, the byte stream includes a prefix portion describing the data type and length range of the numerical part through different values, a length portion representing the length of the numerical part through different values, and a numerical part for storing the data; the length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte.
[0125] Furthermore, the length of the prefix portion of the integer data is one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; when the prefix portion of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
[0126] Furthermore, when the length of the prefix part of the string is three bits, the remaining part of the first byte of the corresponding byte stream is the length part; when the length of the prefix part of the string is one byte, the length of the corresponding length part is one, two, or four bytes.
[0127] Furthermore, when the length of the prefix portion of the array or mapping is half a byte, the remaining part of the first byte of its corresponding byte stream is the length portion; when the length of the prefix portion of the array or mapping is one byte, the length of its corresponding length portion is two or four bytes.
[0128] Furthermore, for arrays, the elements of the array are recursively encoded according to the data type of the element; for mappings, the key-value pairs of the mapping are recursively encoded according to the data type of the key-value pair.
[0129] Furthermore, for extended type data that allows customization, its byte stream is a fixed-length encoded byte stream or a variable-length encoded byte stream; the fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length part through different values, a length portion for representing the length of the numeric part through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numeric part for storing data; the length of the extended type prefix portion is one byte; the length of the length portion is one, two, or four bytes; the length of the extended type portion is one byte.
[0130] Furthermore, for empty data and boolean values, the length of the byte stream corresponding to the empty data and boolean value is one byte.
[0131] Furthermore, the prefix portion of a floating-point number is one byte in length.
[0132] Furthermore, the prefix portion of the binary data is one byte long; its corresponding length portion is one, two, or four bytes long.
[0133] This invention has the following characteristics: This invention employs a novel encoding format for data communication. This format, with its unique advantages, effectively addresses the inherent limitations of traditional encoding in terms of flexibility, type representation, information self-description, and support for complex data structures. By directly embedding type information into the data stream, it endows the data with self-descriptive capabilities, allowing the parser to dynamically identify data types without relying on external definitions, greatly improving structural flexibility and backward compatibility. This structured and explicit type system enables binary data to be easily converted into human-readable formats (such as JSON), significantly reducing the difficulty of debugging and maintenance. Furthermore, native support for composite data types (such as nested arrays and mappings) and standardized encoding definitions allow for flexible handling of complex data modeling, thereby comprehensively improving the communication performance of relay protection devices in the development of intelligence, networking, and platformization.
[0134] Finally, it should be noted that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still make modifications to the technical solutions described in the foregoing embodiments without creative effort, or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A data communication method for relay protection devices, characterized in that, The method includes: S1. Obtain the data to be transmitted from the relay protection device; S2. Serialize the data to be sent into a byte stream according to a preset encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte. S3. Send the byte stream.
2. The data communication method for relay protection devices according to claim 1, characterized in that, The prefix portion of the integer data has a length of one bit, three bits, or one byte; the data type described by the prefix portion of the integer data also includes signed integer data and unsigned integer data; When the prefix part of the integer data is one bit or three bits, the length of the byte stream is one byte, and the remaining part of the byte is the numerical part.
3. The data communication method for relay protection devices according to claim 1, characterized in that, When the length of the prefix part of the string is three bits, the remaining part of the first byte of the corresponding byte stream is the length part; When the length of the prefix part of the string is one byte, the length of its corresponding length part is one, two, or four bytes.
4. The data communication method for relay protection devices according to claim 1, characterized in that, When the length of the prefix part of the array or mapping is half a byte, the remaining part of the first byte of the corresponding byte stream is the length part; When the length of the prefix part of the array or mapping is one byte, the length of its corresponding length part is two or four bytes.
5. The data communication method for relay protection devices according to claim 1 or 4, characterized in that, For arrays, the elements of the array are recursively encoded according to the data type of the element; for maps, the key-value pairs of the map are recursively encoded according to the data type of the key-value pair.
6. The data communication method for relay protection devices according to claim 1, characterized in that, For extended data types that allow customization, the byte stream is either a fixed-length encoded byte stream or a variable-length encoded byte stream; The fixed-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the length of the numeric portion through different values, an extended type portion for representing user-defined extended subtypes through different values, and a numeric portion for storing data; The variable-length encoded byte stream includes a prefix portion for representing the data type as an extended type and the range of values for the length portion through different values, a length portion for representing the length of the numerical portion through different values, an extended type portion for representing the user-defined extended subtype through different values, and a numerical portion for storing data; The prefix portion of the extended type has a length of one byte; the length portion has a length of one, two, or four bytes; and the extended type portion has a length of one byte.
7. The data communication method for relay protection devices according to claim 1, characterized in that, For empty data and Boolean values, the length of the byte stream corresponding to the empty data and Boolean value is one byte.
8. The data communication method for relay protection devices according to claim 1, characterized in that, The prefix portion of the floating-point number is one byte in length.
9. The data communication method for relay protection devices according to claim 1, characterized in that, The prefix portion of the binary data has a length of one byte; the corresponding length portion has a length of one, two, or four bytes.
10. A data communication method for a relay protection device, characterized in that, The method includes: (1) Receive the byte stream to be parsed from the relay protection device; (2) Parse the byte stream into data according to the agreed encoding format; For integer data and floating-point numbers, the byte stream includes a prefix portion for describing the data type and length of the numerical portion through different values and a numerical portion for storing the data; For strings, arrays, mappings, and binary data, the byte stream includes a prefix portion for describing the data type of the numerical part by different values and a range of values for the length portion, a length portion for representing the length of the numerical part by different values, and a numerical portion for storing the data. The length of the prefix portion is at least one bit and at most one byte; the length of the length portion is at least half a byte.
11. A relay protection device, comprising a processor, characterized in that, The processor is used to execute a computer program to implement the steps of the data communication method for a relay protection device as described in any one of claims 1 to 9.
12. A computer-readable storage medium, wherein a computer program is stored internally, characterized in that, The computer program is used to be processed to perform the steps of the data communication method for a relay protection device as described in any one of claims 1 to 9.