diff --git a/codec/SMPPBodyBase.st b/codec/SMPPBodyBase.st index 6021caf..ea68753 100644 --- a/codec/SMPPBodyBase.st +++ b/codec/SMPPBodyBase.st @@ -178,4 +178,22 @@ sub-classes will provide the specific bodies.'> ifTrue: [^self error: 'Optional attributes not implemented!']. ] ] + + writeOn: aMsg [ + + "Custom write to avoid having to box String code" + + "Write each element" + self class tlvDescription do: [:attr | + | val | + val := self instVarNamed: attr instVarName. + + "Now write it" + val isNil ifFalse: [ + attr needsTag + ifTrue: [aMsg putByte: attr tag]. + attr parseClass write: val on: aMsg with: attr. + ]. + ] + ] ] diff --git a/codec/attributes/SMPPInteger.st b/codec/attributes/SMPPInteger.st index 315326c..1000c97 100644 --- a/codec/attributes/SMPPInteger.st +++ b/codec/attributes/SMPPInteger.st @@ -33,4 +33,10 @@ Object subclass: SMPPInteger [ "This is not implemented yet" ^self error: 'The base class does not support other value sizes'. ] + + SMPPInteger class >> write: aValue on: aMsg with: anAttribute [ + anAttribute valueSize = 1 + ifTrue: [^aMsg putByte: aValue]. + ^self error: 'This value size is not supported yet.' + ] ] diff --git a/codec/attributes/SMPPOctetString.st b/codec/attributes/SMPPOctetString.st index cd76502..7ce11ec 100644 --- a/codec/attributes/SMPPOctetString.st +++ b/codec/attributes/SMPPOctetString.st @@ -38,4 +38,11 @@ Object subclass: SMPPOctetString [ "anAttribute... verify the max size" ^str contents ] + + SMPPOctetString class >> write: aValue on: aMsg with: anAttr [ + "Todo.. verify the size constraints..." + aMsg + putByteArray: aValue asByteArray; + putByte: 0 + ] ] diff --git a/test/SMPPMessageTest.st b/test/SMPPMessageTest.st index 37b93df..e1b1d0e 100644 --- a/test/SMPPMessageTest.st +++ b/test/SMPPMessageTest.st @@ -45,6 +45,13 @@ TestCase subclass: SMPPMessageTest [ self assert: msg body addressRange equals: ''. ] + testRoundTrip [ + | msg res | + msg := SMPPMessage readFrom: self examplePdu readStream. + res := msg toMessage asByteArray. + self assert: res equals: self examplePdu + ] + testWriteMessage [ | data | data := (SMPPMessage new