summaryrefslogtreecommitdiffstats
path: root/codec
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-05-13 04:25:25 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-05-13 04:25:25 +0200
commit6cec6976563b6f50b39b3577972cbd460b1342c5 (patch)
tree1ed99cea0c934b7ba35257fd8a0e196d7653c870 /codec
parent1e181e67e6e1483c2df29cde322e60a6dc1aaac2 (diff)
write: Implement write for the attributes and the body
This will decode and re-create the message. It is the first round-trip test.
Diffstat (limited to 'codec')
-rw-r--r--codec/SMPPBodyBase.st18
-rw-r--r--codec/attributes/SMPPInteger.st6
-rw-r--r--codec/attributes/SMPPOctetString.st7
3 files changed, 31 insertions, 0 deletions
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 [
+ <category: 'serialize'>
+ "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
+ ]
]