-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new load method returning a tuple (an instance of current class and byte length) #176
base: master
Are you sure you want to change the base?
Conversation
Looks like I need to tweak the dependency resolver now that projects are starting to drop Python 2 support. Could you describe your use case, perhaps with some example code? I'm somewhat inclined to create a new method rather than having a param change the type of the return value. |
… byte length) In case there is a byte pool with many records they need to be extracted separately. Each record might have variable length depending on data in it.
Codecov Report
@@ Coverage Diff @@
## master #176 +/- ##
==========================================
- Coverage 87.16% 87.09% -0.07%
==========================================
Files 21 21
Lines 5243 5246 +3
==========================================
- Hits 4570 4569 -1
- Misses 673 677 +4
Continue to review full report at Codecov.
|
Here is an use case: cdr_file = open(filename, 'rb')
data = cdr_file.read()
offset = 0
bytes_left = len(data)
while bytes_left > 0:
asrecord, length = spec_class.load_p(data[offset:])
records.append(asrecord)
bytes_left = bytes_left - length
offset = offset + length Data on the input are ASN.1 encoded CDR records (several fields per record). Possibly you can suggest the method name if you like. |
What is "CDR"? |
Thanks I will have a look. CDR is a Call Detail Record. It is from telecommunication terminology. CDRs keeps the history of all dialogues that includes calling and called party and further important fields. |
Joern is right. I can use parser.parse method Here is the code I used: data = cdr_file.read()
offset = 0
bytes_left = len(data)
while bytes_left:
parsed_data = parser.parse(data[offset:])
record = parsed_data[3] + parsed_data[4] + parsed_data[5]
length = len(record)
asrecord = spec_class.load(record)
records.append(asrecord)
bytes_left = bytes_left - length
offset = offset + length
cdr_file.close() Otherwise my pull request can be closed as a solution exists. |
Python brings a bytearray object which has efficient append/remove operations on both ends: >>> from os import urandom
>>> buf = bytearray(urandom(1_000_000_000))
>>> del buf[:567] # finishes near instantly |
I don't think there's a solution yet. |
No description provided.