smalltalk
/
osmo-st-smpp
Archived
1
0
Fork 0

msg: Introduce a message class that contains header and body

This commit is contained in:
Holger Hans Peter Freyther 2014-04-24 21:58:10 +02:00
parent fea5159aa7
commit a2a6bbc690
3 changed files with 109 additions and 0 deletions

54
codec/SMPPMessage.st Normal file
View File

@ -0,0 +1,54 @@
"
(C) 2014 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"
Object subclass: SMPPMessage [
| header body |
SMPPMessage class >> readFrom: aStream [
| len data stream |
len := ((aStream next: 4) uintAt: 1) swap32.
data := aStream next: len - 4.
stream := data readStream.
^SMPPMessage new
header: (SMPPPDUHeader readFrom: stream);
yourself.
]
header: aHeader [
header := aHeader
]
header [
^header
]
body: aBody [
body := aBody
]
writeOn: aMsg [
| hdrData bodyData |
hdrData := header toMessageOrByteArray.
bodyData := body toMessageOrByteArray.
aMsg
putLen32: (hdrData size + bodyData size + 4);
putByteArray: hdrData;
putByteArray: bodyData.
]
]

View File

@ -4,9 +4,12 @@
<prereq>OsmoNetwork</prereq>
<filein>codec/SMPPPDUHeader.st</filein>
<filein>codec/SMPPMessage.st</filein>
<test>
<sunit>Osmo.SMPPPDUHeaderTest</sunit>
<sunit>Osmo.SMPPMessageTest</sunit>
<filein>test/SMPPPDUHeaderTest.st</filein>
<filein>test/SMPPMessageTest.st</filein>
</test>
</package>

52
test/SMPPMessageTest.st Normal file
View File

@ -0,0 +1,52 @@
"
(C) 2014 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"
TestCase subclass: SMPPMessageTest [
<category: 'OsmoSMPP-Test'>
<comment: 'I test reading and writing most of the SMPP header and body'>
examplePdu [
^#[16r00 16r00 16r00 16r2F 16r00 16r00 16r00 16r02
16r00 16r00 16r00 16r00 16r00 16r00 16r00 16r01
16r53 16r4D 16r50 16r50 16r33 16r54 16r45 16r53
16r54 16r00 16r73 16r65 16r63 16r72 16r65 16r74
16r30 16r38 16r00 16r53 16r55 16r42 16r4D 16r49
16r54 16r31 16r00 16r00 16r01 16r01 16r00]
]
testReadMessage [
| msg |
msg := SMPPMessage readFrom: self examplePdu readStream.
self assert: msg header commandId equals: 2.
self assert: msg header commandStatus equals: 0.
self assert: msg header sequenceNumber equals: 1.
]
testWriteMessage [
| data |
data := (SMPPMessage new
header: (SMPPPDUHeader new
commandId: 2;
commandStatus: 0;
sequenceNumber: 1;
yourself);
body: (self examplePdu copyFrom: 17);
toMessage) asByteArray.
self assert: data equals: self examplePdu.
]
]