From 8bdb0be6dc316b5bd24ae32b4ec2cb3d0bc3c1c8 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 25 Mar 2012 21:50:02 +0200 Subject: [PATCH] streams: Switch BSSAP to use streams. --- BSSAP.st | 22 +++++++++++----------- SCCPHandler.st | 6 +++--- Tests.st | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/BSSAP.st b/BSSAP.st index 981a3fc..71ad190 100644 --- a/BSSAP.st +++ b/BSSAP.st @@ -1,5 +1,5 @@ " - (C) 2010 by Holger Hans Peter Freyther + (C) 2010-2012 by Holger Hans Peter Freyther All Rights Reserved This program is free software: you can redistribute it and/or modify @@ -49,14 +49,14 @@ Object subclass: BSSAPHelper [ Object subclass: BSSAPMessage [ - BSSAPMessage class >> decode: bssap [ + BSSAPMessage class >> decode: aStream [ | type | - type := bssap at: 1. + type := aStream next. BSSAPMessage allSubclassesDo: [:each | each msgType = type ifTrue: [ - ^ each parseFrom: bssap. + ^ each parseFrom: aStream. ] ]. @@ -76,10 +76,10 @@ BSSAPMessage subclass: BSSAPManagement [ yourself. ] - BSSAPMessage class >> parseFrom: aByteArray [ + BSSAPMessage class >> parseFrom: aStream [ | size data | - size := aByteArray at: 2. - data := aByteArray copyFrom: 3 to: 2 + size. + size := aStream next. + data := aStream next: size. ^ BSSAPManagement initWith: data. ] @@ -115,11 +115,11 @@ BSSAPMessage subclass: BSSAPDTAP [ yourself ] - BSSAPDTAP class >> parseFrom: aByteArray [ + BSSAPDTAP class >> parseFrom: aStream [ | li size dat | - li := aByteArray at: 2. - size := aByteArray at: 3. - dat := aByteArray copyFrom: 4 to: 4 + size - 1. + li := aStream next. + size := aStream next. + dat := aStream next: size. ^ BSSAPDTAP initWith: dat linkIdentifier: li. ] diff --git a/SCCPHandler.st b/SCCPHandler.st index 06ec21d..14f0419 100644 --- a/SCCPHandler.st +++ b/SCCPHandler.st @@ -334,15 +334,15 @@ Object subclass: MSGParser [ sccp := Osmo.SCCPMessage decode: aByteArray. (sccp respondsTo: #data) ifTrue: [ - sccp data: (self decodeBSSAP: sccp data). + sccp data: (self decodeBSSAP: sccp data readStream). ]. ^ sccp ] - MSGParser class >> decodeBSSAP: aData [ + MSGParser class >> decodeBSSAP: aStream [ | bssap | - bssap := BSSAPMessage decode: aData. + bssap := BSSAPMessage decode: aStream. bssap class msgType = BSSAPDTAP msgType ifTrue: [ bssap data: (GSM48MSG decode: bssap data) diff --git a/Tests.st b/Tests.st index 86e2683..d6acd42 100644 --- a/Tests.st +++ b/Tests.st @@ -144,7 +144,7 @@ TestCase subclass: BSSAPTest [ testParseManagement [ | man | - man := BSSAPMessage decode: #(0 3 1 2 3) asByteArray. + man := BSSAPMessage decode: #(0 3 1 2 3) asByteArray readStream. self assert: (man isKindOf: BSSAPManagement). self assert: man data = #(1 2 3) asByteArray. ]