" (C) 2010 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 . " Object subclass: BSSAPHelper [ BSSAPHelper class >> msgManagemnt [ ^ 0 ] BSSAPHelper class >> msgDtap [ ^ 1 ] BSSAPHelper class >> prependManagement: aMsg [ "Prepent the BSSAP Management header" | tmp | tmp := OrderedCollection new. tmp add: self msgManagemnt. tmp add: aMsg size. aMsg prependByteArray: tmp asByteArray. ] BSSAPHelper class >> prependDTAP: aMsg dlci: sapi [ "Prepend the DTAP header" | tmp | tmp := OrderedCollection new. tmp add: self msgDtap. tmp add: sapi. tmp add: aMsg size. aMsg prependByteArray: tmp asByteArray. ] ] Object subclass: BSSAPMessage [ BSSAPMessage class >> decode: bssap [ | type | type := bssap at: 1. BSSAPMessage allSubclassesDo: [:each | each msgType = type ifTrue: [ ^ each parseFrom: bssap. ] ]. ^ Error signal: 'No handler for: ', type asString. ] ] BSSAPMessage subclass: BSSAPManagement [ | data | BSSAPManagement class >> msgType [ ^ BSSAPHelper msgManagemnt ] BSSAPManagement class >> initWith: data [ ^ (self new) data: data; yourself. ] BSSAPMessage class >> parseFrom: aByteArray [ | size data | size := aByteArray at: 2. data := aByteArray copyFrom: 3 to: 2 + size. ^ BSSAPManagement initWith: data. ] data: aPayload [ data := aPayload. ] data [ ^ data ] writeOn: aMsg [ | dat | aMsg putByte: BSSAPHelper msgManagemnt. dat := data toMessageOrByteArray. aMsg putByte: dat size. aMsg putByteArray: dat. ] ] BSSAPMessage subclass: BSSAPDTAP [ | data li | BSSAPDTAP class >> msgType [ ^ BSSAPHelper msgDtap ] BSSAPDTAP class >> initWith: data linkIdentifier: li [ ^ self new data: data; linkIdentifier: li; yourself ] BSSAPDTAP class >> parseFrom: aByteArray [ | li size dat | li := aByteArray at: 2. size := aByteArray at: 3. dat := aByteArray copyFrom: 4 to: 4 + size - 1. ^ BSSAPDTAP initWith: dat linkIdentifier: li. ] writeOn: aMsg [ | dat | dat := data toMessageOrByteArray. aMsg putByte: self class msgType. aMsg putByte: li. aMsg putByte: dat size. aMsg putByteArray: dat. ] data [ ^ data ] data: aData [ data := aData. ] sapi [ ^ li bitAnd: 7 ] linkIdentifier [ ^ li ] linkIdentifier: aLi [ li := aLi. ] ]