Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #27 +/- ##
==========================================
+ Coverage 35.44% 37.93% +2.48%
==========================================
Files 8 17 +9
Lines 1560 1558 -2
==========================================
+ Hits 553 591 +38
+ Misses 915 884 -31
+ Partials 92 83 -9
Continue to review full report at Codecov.
|
Move case body in separate methods: - (*Message).PDU() → (*Message).encodeXXX - (*Message).ReadFrom() → (*Message).decodeXXX Also extract User-Data decoding to reduce code duplication.
This method can help in input validation. Since Encode7Bit auto-substitutes unknown characters with '?', we cannot simply check whether decode(encode(input)) == input.
This fixes two small bugs related to parsing timestamp PDUs: In (Timestamp).PDU(), generating the time zone octet accidentally used integer arithmetic to calculate the GMT offset. This causes problems for time zones like +08:15, which resulted in an offset of 8 hours (and not 8.25 hours). In (*Timestamp).ReadFrom(), the wrong bit was used to identify negative time zones: Negative time zones are actually indicated by bit 3 (the fourth bit, 0x08, 0b0000_1000) set to one, this code previously looked at bit 2 (0x04, 0b0000_0100). This also surfaced an issue with the test fixture for TestSmsDeliverReadFromGsm7_2() where the correct time zone is GMT-03:00 (Moskow time, which matches the TP-UD payload contained in that message).
Contributor
Author
|
This is now ready for review. I've updated the cover letter. |
Owner
It's GMT+03 by the way, but I believe that the wrong bit could be used to detect that. I didn't have a chance to test with other zones with real data. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've refactored some bits:
Split code
I've split the
sms/sms.gofile in multiple units, as 1000-lines files start to get unwieldy.For the same reason, I've split the switch statements in
(*sms.Message).PDU()and(*sms.Message).ReadFrom()in separate methods.Add a resolver for TP-ST values
I've imported the names for TP-ST values from 3GPP TS 23.040 v16.0.0, section 9.2.3.15 (PDF). This allows to easier act on SMS-STATUS-REPORT PDUs:
I'm not sure about the Status field names: TS 23.040 reuses some names for different bytes (which either carry the information that the SC will or will not retry delivery, or whether the status is temporary or permanent). Hence the names of
sms.StatusCodesare prefixed with on of:CompletedReceived) for codes in categoryComplete,TemporaryBusyorTemporaryQualityOfServiceNotAvailable) for codes in categoryTemporaryError,PermanentQualityOfServiceNotAvailable) for codes in categoryPermanentError, andFinalBusyorFinalQualityOfServiceNotAvailable) for codes in categoryFinalError.Add type-of-address and numbering-plan-indentification for
PhoneNumberI've imported values for type-of-address and numbering-plan-identification bits from 3GPP TS 23.040, section 9.1.2.5.
The code does not make much use of it (as it only supports national/international E164 numbers for PDU-encoding and additionally alphanumeric numbers for parsing), but I guess this is the best place to put those constants.
Small fixes related to time zone
In
(Timestamp).PDU(), generating the time zone octet accidentally used integer arithmetic to calculate the GMT offset. This causes problems for time zones like +08:15, which resulted in an offset of 8 hours (and not 8.25 hours).In
(*Timestamp).ReadFrom(), the wrong bit was used to identify negative time zones: Negative time zones are actually indicated by bit 3 (the fourth bit, 0x08, 0b0000_1000) set to one, this code previously looked at bit 2 (0x04, 0b0000_0100). This also surfaced an issue with the test fixture for TestSmsDeliverReadFromGsm7_2() where the correct time zone is GMT-03:00 (Moscow time, which matches the TP-UD payload contained in that message).