codec: Implement parsing trx bind resp and fix optional parsing
This commit is contained in:
parent
2008f19ac1
commit
de471382a4
|
@ -0,0 +1,41 @@
|
|||
"
|
||||
(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/>.
|
||||
"
|
||||
|
||||
SMPPBodyBase subclass: SMPPBindTransceiverResponse [
|
||||
| system_id sc_interface_version |
|
||||
|
||||
<category: 'SMPP-Codec'>
|
||||
<comment: 'I represent a response and there should be a intermediate
|
||||
class just like with the SMPPBindTransmitter'>
|
||||
|
||||
SMPPBindTransceiverResponse class >> messageType [
|
||||
^self bindTransceiverResp
|
||||
]
|
||||
|
||||
SMPPBindTransceiverResponse class >> tlvDescription [
|
||||
^OrderedCollection new
|
||||
add: SMPPSystemId tlvDescription;
|
||||
add: (SMPPValueHolder for: #sc_interface_version tag: 16r0210);
|
||||
yourself
|
||||
]
|
||||
|
||||
systemId [
|
||||
^system_id
|
||||
]
|
||||
]
|
||||
|
|
@ -168,17 +168,20 @@ sub-classes will provide the specific bodies.'>
|
|||
]
|
||||
|
||||
readFrom: aStream [
|
||||
| description |
|
||||
| description tag |
|
||||
description := self class tlvDescription.
|
||||
description do: [:attribute |
|
||||
attribute isMandatory
|
||||
ifTrue: [self doParse: attribute stream: aStream].
|
||||
attribute isOptional
|
||||
ifTrue: [
|
||||
| tag |
|
||||
tag := aStream peek.
|
||||
"Read the tag if we have not done so far. We can not
|
||||
peek for more than one character."
|
||||
(tag isNil and: [aStream atEnd not]) ifTrue:
|
||||
[tag := ((aStream next: 2) shortAt: 1) swap16].
|
||||
|
||||
tag = attribute tag ifTrue: [
|
||||
aStream next.
|
||||
tag := nil.
|
||||
self doParse: attribute stream: aStream]].
|
||||
].
|
||||
|
||||
|
@ -197,7 +200,7 @@ sub-classes will provide the specific bodies.'>
|
|||
"Now write it"
|
||||
val isNil ifFalse: [
|
||||
attr needsTag
|
||||
ifTrue: [aMsg putByte: attr tag].
|
||||
ifTrue: [aMsg putLen16: attr tag].
|
||||
attr parseClass write: val on: aMsg with: attr.
|
||||
].
|
||||
]
|
||||
|
|
|
@ -23,6 +23,7 @@ Object subclass: SMPPValueHolder [
|
|||
SMPPValueHolder class >> for: aString tag: aTag [
|
||||
^Osmo.TLVDescription new
|
||||
instVarName: aString;
|
||||
parseClass: self;
|
||||
tag: aTag;
|
||||
beOptional;
|
||||
beTLV;
|
||||
|
@ -31,13 +32,13 @@ Object subclass: SMPPValueHolder [
|
|||
|
||||
SMPPValueHolder class >> readFrom: aStream with: anAttribute [
|
||||
| len |
|
||||
len := aStream next.
|
||||
len := ((aStream next: 2) shortAt: 1) swap16.
|
||||
^(aStream next: len)
|
||||
]
|
||||
|
||||
SMPPValueHolder class >> write: aValue on: aMsg with: anAttribute [
|
||||
aMsg
|
||||
putByte: aValue size;
|
||||
putLen16: aValue size;
|
||||
putByteArray: aValue asByteArray.
|
||||
]
|
||||
]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<filein>codec/SMPPBodyBase.st</filein>
|
||||
<filein>codec/SMPPBindTransmitterBody.st</filein>
|
||||
<filein>codec/SMPPBindTransceiver.st</filein>
|
||||
<filein>codec/SMPPBindTransceiverResponse.st</filein>
|
||||
<filein>codec/SMPPEnquireLink.st</filein>
|
||||
<filein>codec/SMPPGenericNack.st</filein>
|
||||
<filein>codec/SMPPUnbind.st</filein>
|
||||
|
|
|
@ -68,6 +68,13 @@ TestCase subclass: SMPPMessageTest [
|
|||
16r32]
|
||||
]
|
||||
|
||||
exampleBindResponse [
|
||||
^#[16r00 16r00 16r00 16r1D 16r80 16r00 16r00 16r09
|
||||
16r00 16r00 16r00 16r00 16r00 16r00 16r00 16r00
|
||||
16r53 16r4D 16r50 16r50 16r4D 16r41 16r50 16r00
|
||||
16r02 16r10 16r00 16r01 16r34]
|
||||
]
|
||||
|
||||
testReadMessage [
|
||||
| msg |
|
||||
msg := SMPPMessage readFrom: self examplePdu readStream.
|
||||
|
@ -141,4 +148,15 @@ TestCase subclass: SMPPMessageTest [
|
|||
res := msg toMessage asByteArray.
|
||||
self assert: res equals: self exampleSubmitSM.
|
||||
]
|
||||
|
||||
testBindResponse [
|
||||
| msg res |
|
||||
msg := SMPPMessage readFrom: self exampleBindResponse readStream.
|
||||
self assert: msg body class equals: SMPPBindTransceiverResponse.
|
||||
self assert: msg body systemId equals: 'SMPPMAP'.
|
||||
|
||||
"Do round trip test"
|
||||
res := msg toMessage asByteArray.
|
||||
self assert: res equals: self exampleBindResponse.
|
||||
]
|
||||
]
|
||||
|
|
Reference in New Issue