CN107562442B - Method and device for reading data - Google Patents

Method and device for reading data Download PDF

Info

Publication number
CN107562442B
CN107562442B CN201710868187.0A CN201710868187A CN107562442B CN 107562442 B CN107562442 B CN 107562442B CN 201710868187 A CN201710868187 A CN 201710868187A CN 107562442 B CN107562442 B CN 107562442B
Authority
CN
China
Prior art keywords
data
read
real
code stream
bits
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
CN201710868187.0A
Other languages
Chinese (zh)
Other versions
CN107562442A (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.)
Guangzhou Kugou Computer Technology Co Ltd
Original Assignee
Guangzhou Kugou Computer Technology 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 Guangzhou Kugou Computer Technology Co Ltd filed Critical Guangzhou Kugou Computer Technology Co Ltd
Priority to CN201710868187.0A priority Critical patent/CN107562442B/en
Publication of CN107562442A publication Critical patent/CN107562442A/en
Application granted granted Critical
Publication of CN107562442B publication Critical patent/CN107562442B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The embodiment of the invention discloses a method and a device for reading data, belonging to the technical field of electronics. The method comprises the following steps: determining the currently readable maximum digit total _ real _ n in the code stream; when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally; when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read; reading the data of the byte where the data to be read is located; shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v; and leftwards shifting real _ n bits of the previously read data r, and carrying out OR operation on the r leftwards shifted real _ n bits and the v to obtain the data which is read at present. By adopting the invention, the data reading speed can be improved.

Description

Method and device for reading data
Technical Field
The present invention relates to the field of electronic technologies, and in particular, to a method and an apparatus for reading data.
Background
With the development of electronic technology, devices such as mobile phones and computers are widely applied, and corresponding devices have more and more abundant functions. During the use of the device, it is often necessary to transmit data with other devices (such as a server).
The data transmitted between the devices is generally a code stream composed of multi-bit binary numbers, and after the devices receive the code stream, the devices can read data of a certain number of bits in the received code stream as required. At present, a device usually reads some bits of data in a code stream by using a mask generation method.
In the process of implementing the invention, the inventor finds that the prior art has at least the following problems:
based on the above processing method, the time required for generating the mask is often long, and thus, the speed of reading data is slow.
Disclosure of Invention
In order to solve the problem of slow data reading speed in the related art, embodiments of the present invention provide a method and an apparatus for reading data. The technical scheme is as follows:
in a first aspect, a method for reading data is provided, the method comprising:
determining the currently readable maximum digit total _ real _ n in the code stream;
when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally;
when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read;
reading the data of the byte where the data to be read is located;
shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v;
and leftwards shifting real _ n bits of the previously read data r, and carrying out OR operation on the r leftwards shifted real _ n bits and the v to obtain the data which is read at present.
Optionally, the determining a currently readable maximum number of bits total _ real _ n in the code stream includes:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of the data read at present and the position p of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
Optionally, when the total _ real _ n is greater than 0, determining a number of bits consume _ n before the data to be read in the byte where the data to be read is located includes:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
Optionally, the method further includes:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
Optionally, the determining the number of bits real _ n of the data to be read includes:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
In a second aspect, there is provided an apparatus for reading data, the apparatus comprising:
the first determining module is used for determining the currently readable maximum digit total _ real _ n in the code stream;
the termination module is used for terminating reading when the total _ real _ n is equal to 0 to obtain the data in the code stream to be read finally;
the second determining module is used for determining the number of bits constume _ n before the data to be read in the byte where the data to be read is located when the total _ real _ n is larger than 0, and determining the number of bits real _ n of the data to be read;
the reading module is used for reading the data of the byte where the data to be read is located;
the shift module is used for shifting the read data by the control _ n bit to the left, and shifting the data after the control _ n bit to the left by the difference bit between the bit number contained in the byte and the real _ n to obtain the read data v;
and the merging module is used for leftwards shifting the previous read data r by real _ n bits, and carrying out OR operation on the r leftwards shifted by the real _ n bits and the v to obtain the data which is read at present.
Optionally, the first determining module is configured to:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of the data read at present and the position p of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
Optionally, the second determining module is configured to:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
Optionally, the first determining module is further configured to:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
Optionally, the second determining module is configured to:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
in the embodiment of the invention, the currently readable maximum digit total _ real _ n in the code stream is determined; when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally; when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read; reading the data of the byte where the data to be read is located; shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v; and carrying out left shift on the r bits of the read data by real _ n bits, and carrying out OR operation on the r bits and the v bits of the left shift by real _ n bits to obtain the data which is read at present. Therefore, the device can read the data in the code stream to be read finally through left shift, right shift and/or operation without generating a mask, and the time required by the left shift, the right shift and/or operation is usually less, so that the data reading speed can be improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flow chart of a method for reading data according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a read data according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of an apparatus for reading data according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
The embodiment of the invention provides a method for reading data, and an execution main body of the method is equipment. The device may be a terminal (such as a mobile phone, a computer, etc.) or a server, among others. The device may include a processor, memory, etc. The processor may be a CPU (Central Processing Unit) or the like, and may be used for related Processing of reading data. The Memory may be a RAM (Random Access Memory), a Flash (Flash Memory), or the like, and may be configured to store received data, data required by a processing procedure, data generated during the processing procedure, or the like. The device may also include a transceiver. The transceiver may be used for data transmission with other devices and may include an antenna, matching circuitry, a modem, and the like.
The process flow shown in fig. 1 will be described in detail below with reference to specific embodiments, and the contents may be as follows:
step 101, determining the currently readable maximum digit total _ real _ n in the code stream.
In implementation, in the use process of the device, data transmission is often performed with other devices, that is, code streams sent by other devices can be received. After the device receives the code stream, it may read some bits of data in the code stream as needed (where n may represent the number of bits of data in the code stream that the device finally needs to read). Before starting to read data, the device may first determine the current readable maximum number of bits in the received codestream (where the current readable maximum number of bits may be total _ real _ n).
Optionally, total _ real _ n may be determined by the total number of bits of the code stream, n, the number of bits of the data that is currently read, and the position of the data to be read in the code stream, and accordingly, the processing procedure in step 101 may be as follows: acquiring the total digit t of a code stream, the digit n of data in the code stream to be read finally, the digit x of the data read at present and the position p of the data to be read in the code stream; and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
The position p of the data to be read in the code stream may be the bit number of the previous bit of the data to be read in the code stream. The number of bits n of the data in the code stream to be finally read may be the total number of bits of all data to be read from the received code stream by the device.
In implementation, when reading data, the device reads the data according to bytes, that is, the minimum unit read by the device each time is a byte (where one byte contains 8 bits). For such a situation, when the data in the code stream to be finally read by the device spans multiple bytes, the device can read the data for multiple times until the data in the code stream to be finally read is obtained. And the device can update the total _ real _ n and the position p of the data to be read in the code stream once every time the data is read.
Specifically, after receiving the code stream, the device may determine a total bit number of the code stream (where the total bit number may be represented by t), a bit number n of data in the code stream to be finally read, and a bit number of previous bit data of the data in the code stream to be finally read (which may be represented by p, where p is a position of the data to be read this time (for the first time) in the code stream). After t, n and p are determined, the currently readable maximum digit total _ real _ n in the code stream during the first reading can be determined. Specifically, the difference between t and p and the minimum value of n may be determined as total _ real _ n, that is, when the number of bits after p in the code stream is less than n, total _ real _ n is the number of bits after p in the code stream (i.e., the difference between t and p), and when the number of bits after p in the code stream is greater than n, total _ real _ n is n. For example, assuming that the position of the first digit of the code stream is called the first digit, the received code stream is 0101101110, and 3 bits of data after the fourth digit are to be read (i.e., the data in the code stream to be finally read is 101), the device may determine that t is 10, p is 4, n is 3, and the difference between t and p is 6, and further, the device may determine that the difference between t and p and the minimum value of n is 3, as total _ real _ n.
After the data is read for the first time, when the data needs to be read for the second time, the device may re-determine the currently readable maximum digit number total _ real _ n in the code stream (i.e., when the data is read for the second time), that is, may update the total _ real _ n, so as to obtain the currently readable maximum digit number total _ real _ n in the code stream (i.e., when the data is read for the second time). At this time, total _ real _ n may be a difference value obtained by subtracting the number of bits of the data read for the first time from the maximum number of bits currently readable in the code stream when the data is read for the first time. That is to say, each time data is read, the device may obtain the total bit t of the code stream, the bit n of the data in the code stream to be read finally, the bit x of the data read until the current time, and the position p of the data to be read in the code stream, and further, may determine the minimum value of the difference between t minus p and the difference between n minus x as the maximum bit total _ real _ n readable currently in the code stream.
Optionally, each time data is read, the device may further update p, and accordingly, the device may further perform the following processing: acquiring a target position of data in a code stream to be read finally in the code stream; and determining the sum of the target position and x as the position p of the data to be read in the code stream.
In implementation, after reading data each time, when reading data next time (that is, this time), the device may update the position of the data read last time in the code stream, to obtain the position of the data to be read this time in the code stream, where the position of the data to be read each time in the code stream may be represented by p. Specifically, the device may obtain a target position of data in the code stream to be finally read in the code stream, that is, may obtain a bit number (i.e., a position) of a previous bit of data in the code stream to be finally read, and may obtain a bit number x of data that is intercepted to the current read, and further, may determine a sum of the target position and x as a position p of the data to be read in the code stream this time. Or, the device may obtain the position of the data read last time in the code stream and the bit number of the data read last time, and further, may determine the sum of the position of the data read last time in the code stream and the bit number of the data read last time as the position p of the data to be read this time in the code stream. That is to say, after the code stream is received, the target position of the data in the code stream to be read finally in the code stream can be determined, and then, before the data is read each time, the position of the data to be read in the code stream at this time can be obtained according to the number of bits of the data read last time and the position of the data read last time in the code stream.
And 102, when the total _ real _ n is equal to 0, terminating reading to obtain the data in the code stream to be read finally.
In implementation, after the currently readable maximum number of bits total _ real _ n in the code stream is determined, whether total _ real _ n is equal to 0 or not can be judged, and when total _ real _ n is equal to 0, the device can terminate reading to obtain the data in the code stream to be finally read.
Step 103, when the total _ real _ n is greater than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read.
In implementation, when total _ real _ n is greater than 0, it is stated that the device has not completely read the data in the code stream to be read finally, and the data reading can be continued. Specifically, the device may determine a byte where the data to be read is located, and further, may determine a number of bits consume _ n in the byte before the data to be read. After determining the control _ n, the device may further determine the bit number real _ n of the data to be read this time.
Optionally, the device may determine a control _ n from the position p of the data to be read in the code stream, and accordingly, the processing procedure in step 103 may be as follows: when total _ real _ n is greater than 0, dividing p by the remainder of the number of bits contained in the byte, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
In an implementation, when total _ real _ n is greater than 0, the device may obtain the determined p, divide p by the number of bits (e.g., 8) included in the byte to obtain a remainder, and further determine the obtained remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located. For example, if p is 5 (in this case, it is stated that the data read this time is the data after the bit number of the byte where p is 5), and the bit number included in the byte is 8, the device may divide 5 by 8 to determine the bit number consume _ n before the data to be read this time in the byte where the data to be read this time is located.
Optionally, the device may determine real _ n from control _ n and total _ real _ n, and accordingly, the processing procedure may be as follows: and determining the bit number of the data to be read at this time, namely the minimum value of the total _ real _ n and the difference value of the number of the bits contained in the byte minus the control _ n.
In implementation, since the minimum unit of data read by the device each time is a byte, the number of bits (which may be represented by real _ n) of the data to be read this time may be determined by the number of bits contained in the byte and the control _ n. Specifically, after the device determines the control _ n, a difference value obtained by subtracting the control _ n from the number of bits included in the byte (where the difference value may be the number of bits after p included in the byte where p is located) may be calculated, and then, the minimum value between the obtained difference value and the total _ real _ n may be determined as the number of bits real _ n of the data to be read this time. For example, if p is 5 and total _ real _ n is 10, real _ n can be calculated to be 3. For another example, if p is 5 and total _ real _ n is 1, real _ n can be calculated to be 1.
And step 104, reading the data of the byte where the data to be read is located.
In implementation, since the minimum unit of data read by the device each time is a byte, the device can read the data of the byte where the data to be read this time is located. Specifically, the device may determine the byte where the data to be read is located through p, that is, the device may start from an integer part of a quotient obtained by dividing p by 8 (that is, the number of bits included in one byte), and read 8-bit data in the code stream in sequence.
For example, if the codestream is 101011001011101010, p is 10, and total _ real _ n is 1, the device may calculate that the integer part of the quotient obtained by dividing p by 8 is 1, and the remainder is 2, that is, the constant _ n is 2, and real _ n is 1, at this time, the device may determine that the data of the byte where the data to be read is located is the data of the second byte in the codestream, that is, 10111010.
And 105, shifting the read data by the control _ n bit to the left, and shifting the data after the control _ n bit to the left by the difference bit between the bit number contained in the byte and real _ n to obtain the read data v.
In the implementation, after the data of the byte where the data to be read is located is read, the data may be left-shifted by the control _ n bit, and then, the data left-shifted by the control _ n bit may be right-shifted by a difference bit between a bit number included in the byte and real _ n to obtain the data v read this time. For example, the codestream is 101011001011101010, p is 10, total _ real _ n is 1, the data of the byte where the data to be read this time is read is 10111010, constant _ n is 2, real _ n is 1, 10111010 is shifted left by 2 bits to obtain 11101000, and then 11101000 is shifted right by 7 bits to obtain the data v read this time is 00000001.
And 106, carrying out left shift of real _ n bits on the previously read data r, and carrying out OR operation on r and v of the left shift of real _ n bits to obtain the data which is read at present.
In implementation, after obtaining the data v read this time, the device may obtain the data r read before this time, shift r left by real _ n bits, and further perform an or operation on r and v shifted left by real _ n bits to obtain the data read from the beginning of the first time reading data to the end of the current time. That is to say, for the case that the data in the code stream to be finally read is obtained by reading for multiple times, after the device reads the data each time, the data read this time and the data read before can be merged. For example, the code stream is 101011011011101010, the data in the code stream to be finally read is 101101 (i.e., the last three bits of the first byte and the first three bits of the second byte), the data of the first byte read for the first time is 10101101, 10101101 is shifted left by 5 bits to obtain 10100000, the data is shifted right by 5 bits (8-3) to obtain 00000101 (i.e., the data read for the first time), the data of the second byte read for the second time is 10111010, the device can shift 10111010 left by 0 bits to obtain 10111010, and then shift right by 5 bits to obtain 00000101 (i.e., the data read for the second time), at this time, the data r read before is the data read for the first time, the device can shift left by 3 bits to obtain 00101000, and then perform an or operation on 00101000 and the data read for the second time to obtain 01101, at this time, the data 101101 in the code stream to be finally read is obtained, as shown in fig. 2.
In this scheme, if data needs to be read for multiple times to obtain data in a code stream to be finally read, the device may perform processing of the above steps in a cycle, that is, each time data is read, the data may be processed according to the above steps, a condition of reading end may be that total _ real _ n is 0, and after each time data is read, total _ real _ n and p may be updated.
In the embodiment of the invention, the currently readable maximum digit total _ real _ n in the code stream is determined; when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally; when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read; reading the data of the byte where the data to be read is located; shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v; and carrying out left shift on the r bits of the read data by real _ n bits, and carrying out OR operation on the r bits and the v bits of the left shift by real _ n bits to obtain the data which is read at present. Therefore, the device can read the data in the code stream to be read finally through left shift, right shift and/or operation without generating a mask, and the time required by the left shift, the right shift and/or operation is usually less, so that the data reading speed can be improved.
Based on the same technical concept, an embodiment of the present invention further provides an apparatus for reading data, as shown in fig. 3, the apparatus includes:
a first determining module 310, configured to determine a currently readable maximum number of bits total _ real _ n in the code stream;
a termination module 320, configured to terminate reading when the total _ real _ n is equal to 0, so as to obtain data in the code stream to be finally read;
a second determining module 330, configured to determine, when the total _ real _ n is greater than 0, a bit count constant _ n before the data to be read this time in a byte where the data to be read this time is located, and determine a bit count real _ n of the data to be read this time;
a reading module 340, configured to read data of a byte where the data to be read is located;
a shift module 350, configured to shift the read data by the control _ n bit to the left, and shift the data after the control _ n bit is shifted to the left by the difference bit between the number of bits included in the right-shifted byte and real _ n to obtain the data v read this time;
and the merging module 360 is configured to shift left the real _ n bit of the previously read data r, and perform an or operation on the r shifted left by the real _ n bit and the v to obtain the data read until the current time.
Optionally, the first determining module 310 is configured to:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of the data read at present and the position p of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
Optionally, the second determining module 330 is configured to:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
Optionally, the first determining module 310 is further configured to:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
Optionally, the second determining module 330 is configured to:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
In the embodiment of the invention, the currently readable maximum digit total _ real _ n in the code stream is determined; when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally; when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read; reading the data of the byte where the data to be read is located; shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v; and carrying out left shift on the r bits of the read data by real _ n bits, and carrying out OR operation on the r bits and the v bits of the left shift by real _ n bits to obtain the data which is read at present. Therefore, the device can read the data in the code stream to be read finally through left shift, right shift and/or operation without generating a mask, and the time required by the left shift, the right shift and/or operation is usually less, so that the data reading speed can be improved.
It should be noted that: in the apparatus for reading data provided in the foregoing embodiment, when reading data, only the division of the functional modules is illustrated, and in practical applications, the functions may be distributed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus for reading data and the method for reading data provided by the above embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and are not described herein again.
Fig. 4 is a block diagram illustrating an apparatus 1900 for reading data according to an example embodiment. For example, the apparatus 1900 may be provided as a server or terminal. Referring to fig. 4, the device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by the processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method of reading data.
The device 1900 may also include a power component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input/output (I/O) interface 1958. The device 1900 may operate based on an operating system stored in memory 1932, such as Windows Server, MacOS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
Device 1900 may include memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors include instructions for:
determining the currently readable maximum digit total _ real _ n in the code stream;
when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally;
when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read;
reading the data of the byte where the data to be read is located;
shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v;
and leftwards shifting real _ n bits of the previously read data r, and carrying out OR operation on the r leftwards shifted real _ n bits and the v to obtain the data which is read at present.
Optionally, the determining a currently readable maximum number of bits total _ real _ n in the code stream includes:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of the data read at present and the position p of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
Optionally, when the total _ real _ n is greater than 0, determining a number of bits consume _ n before the data to be read in the byte where the data to be read is located includes:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
Optionally, the method further includes:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
Optionally, the determining the number of bits real _ n of the data to be read includes:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
In the embodiment of the invention, the currently readable maximum digit total _ real _ n in the code stream is determined; when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally; when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read; reading the data of the byte where the data to be read is located; shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v; and carrying out left shift on the r bits of the read data by real _ n bits, and carrying out OR operation on the r bits and the v bits of the left shift by real _ n bits to obtain the data which is read at present. Therefore, the device can read the data in the code stream to be read finally through left shift, right shift and/or operation without generating a mask, and the time required by the left shift, the right shift and/or operation is usually less, so that the data reading speed can be improved.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.

Claims (10)

1. A method of reading data, the method comprising:
determining the currently readable maximum digit total _ real _ n in the code stream;
when the total _ real _ n is equal to 0, stopping reading to obtain the data in the code stream to be read finally;
when the total _ real _ n is larger than 0, determining the digit consume _ n before the data to be read in the byte where the data to be read is located, and determining the digit real _ n of the data to be read;
reading the data of the byte where the data to be read is located;
shifting the left position of the read data by the consume _ n position, and shifting the right position of the data after shifting the left position of the consume _ n position by the bit number contained in the byte and the difference bit of real _ n to obtain the read data v;
and carrying out left shift on the r bits of the read data by real _ n bits, carrying out OR operation on the r bits of the left shift by real _ n bits and the v to obtain the data which is read until the current time, wherein the r refers to the data which is read from the beginning of reading the data for the first time until the v is obtained.
2. The method of claim 1, wherein determining the maximum number of bits currently readable in the codestream, total _ real _ n, comprises:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of data read until the current time and the position p of the data to be read in the code stream, wherein the p is the digit of the previous digit of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
3. The method of claim 2, wherein the determining the number of bits consume _ n before the data to be read in the byte where the data to be read exists when the total _ real _ n is greater than 0 comprises:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
4. The method of claim 2, further comprising:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
5. The method according to any of claims 1-4, wherein the determining the number of bits real _ n of the data to be read comprises:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
6. An apparatus for reading data, the apparatus comprising:
the first determining module is used for determining the currently readable maximum digit total _ real _ n in the code stream;
the termination module is used for terminating reading when the total _ real _ n is equal to 0 to obtain the data in the code stream to be read finally;
the second determining module is used for determining the number of bits constume _ n before the data to be read in the byte where the data to be read is located when the total _ real _ n is larger than 0, and determining the number of bits real _ n of the data to be read;
the reading module is used for reading the data of the byte where the data to be read is located;
the shift module is used for shifting the read data by the control _ n bit to the left, and shifting the data after the control _ n bit to the left by the difference bit between the bit number contained in the byte and the real _ n to obtain the read data v;
and the merging module is used for performing left shift on the r bits of the previously read data by real _ n bits, and performing OR operation on the r bits of the left shift by real _ n bits and the v to obtain the data which is read until the current time, wherein the r is the data which is read from the beginning of reading the data for the first time until the v is obtained.
7. The apparatus of claim 6, wherein the first determining module is configured to:
acquiring the total digit t of the code stream, the digit n of data in the code stream to be read finally, the digit x of data read until the current time and the position p of the data to be read in the code stream, wherein the p is the digit of the previous digit of the data to be read in the code stream;
and determining the minimum value of the difference value of subtracting p from t and the difference value of subtracting x from n as the currently readable maximum digit total _ real _ n in the code stream.
8. The apparatus of claim 7, wherein the second determining module is configured to:
when the total _ real _ n is larger than 0, dividing the remainder of the number of bits contained in the byte by the p, and determining the remainder as the number of bits consume _ n before the data to be read in the byte where the data to be read is located.
9. The apparatus of claim 7, wherein the first determining module is further configured to:
acquiring a target position of data in the code stream to be read finally in the code stream;
and determining the sum of the target position and the x as the position p of the data to be read at the time in the code stream.
10. The apparatus of any one of claims 6-9, wherein the second determining module is configured to:
and determining the difference value of the number of bits contained in a byte minus the control _ n and the minimum value of the total _ real _ n as the number of bits real _ n of the data to be read at this time.
CN201710868187.0A 2017-09-22 2017-09-22 Method and device for reading data Active CN107562442B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710868187.0A CN107562442B (en) 2017-09-22 2017-09-22 Method and device for reading data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710868187.0A CN107562442B (en) 2017-09-22 2017-09-22 Method and device for reading data

Publications (2)

Publication Number Publication Date
CN107562442A CN107562442A (en) 2018-01-09
CN107562442B true CN107562442B (en) 2020-03-17

Family

ID=60981865

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710868187.0A Active CN107562442B (en) 2017-09-22 2017-09-22 Method and device for reading data

Country Status (1)

Country Link
CN (1) CN107562442B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1124180A2 (en) * 2000-02-08 2001-08-16 Kabushiki Kaisha Toshiba Information processing system with instruction code conversion unit, and instruction code generation method
CN101051845A (en) * 2007-05-09 2007-10-10 上海广电(集团)有限公司中央研究院 Huffman decoding method for quick extracting bit stream
CN102469307A (en) * 2010-11-12 2012-05-23 珠海全志科技股份有限公司 Decoder and code stream analyzing device
CN104011660A (en) * 2011-12-22 2014-08-27 英特尔公司 Processor-based apparatus and method for processing bit streams

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1124180A2 (en) * 2000-02-08 2001-08-16 Kabushiki Kaisha Toshiba Information processing system with instruction code conversion unit, and instruction code generation method
CN101051845A (en) * 2007-05-09 2007-10-10 上海广电(集团)有限公司中央研究院 Huffman decoding method for quick extracting bit stream
CN102469307A (en) * 2010-11-12 2012-05-23 珠海全志科技股份有限公司 Decoder and code stream analyzing device
CN104011660A (en) * 2011-12-22 2014-08-27 英特尔公司 Processor-based apparatus and method for processing bit streams

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Error resilient decoding of randomly impaired MPEG2 bit stream;Jong Won Kim等;《Trans.Inform.Theory》;19970612;第1-20页 *
基于网络的嵌入式MPEG_2远程视频监控系统的实现;王海波;《通信世界》;20030408;第48-50页 *

Also Published As

Publication number Publication date
CN107562442A (en) 2018-01-09

Similar Documents

Publication Publication Date Title
CN110413812B (en) Neural network model training method and device, electronic equipment and storage medium
CN110391938B (en) Method and apparatus for deploying services
CN109829164B (en) Method and device for generating text
US11775269B2 (en) Generating a synchronous digital circuit from a source code construct defining a function call
US11086668B2 (en) Method, electronic device and computer program product for processing task
CN110960855A (en) Communication protocol code updating method and device, electronic equipment and storage medium
CN109918381B (en) Method and apparatus for storing data
CN116166583B (en) Data precision conversion method and device, DMA controller and medium
US20230325149A1 (en) Data processing method and apparatus, computer device, and computer-readable storage medium
CN107562442B (en) Method and device for reading data
CN112818387A (en) Method, apparatus, storage medium, and program product for model parameter adjustment
CN107301017B (en) Data storage method and device
CN113377295B (en) Data storage and reading method, device and equipment for multi-producer single-consumer
CN111756833B (en) Node processing method, node processing device, electronic equipment and computer readable medium
CN114579054A (en) Data processing method and device, electronic equipment and computer readable medium
CN110209851B (en) Model training method and device, electronic equipment and storage medium
CN112230964A (en) Application program development method, application program running method, device, equipment and medium
CN111309323A (en) Parameter initialization method and device and electronic equipment
CN111562913B (en) Method, device and equipment for pre-creating view component and computer readable medium
CN111209042B (en) Method, device, medium and electronic equipment for establishing function stack
CN109918209B (en) Method and equipment for communication between threads
US11431349B2 (en) Method, electronic device and computer program product for processing data
CN117370025A (en) Hash calculation method, device, acceleration card and medium
CN113031914B (en) Floating point rounding mode control method, device, equipment and storage medium
CN113779079A (en) Method and device for caching data

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 510660 Guangzhou City, Guangzhou, Guangdong, Whampoa Avenue, No. 315, self - made 1-17

Applicant after: Guangzhou KuGou Networks Co., Ltd.

Address before: 510000 B1, building, No. 16, rhyme Road, Guangzhou, Guangdong, China 13F

Applicant before: Guangzhou KuGou Networks Co., Ltd.

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant