Skip to content

Instantly share code, notes, and snippets.

@yume190
Last active August 29, 2015 14:04
Show Gist options
  • Save yume190/8368a9847d4455a2af8d to your computer and use it in GitHub Desktop.
Save yume190/8368a9847d4455a2af8d to your computer and use it in GitHub Desktop.
test1234
class packetFactory{
class func sender<T where T:Constructible, T:Packable>(command:devicePacketHeader.commandType,content:T) -> devicePacketSender<T>?{
var header:devicePacketHeader
switch (command,content){
case (.ASK_DEVICE,let TAsk) where TAsk is devicePacketNil:
header = devicePacketHeader(deviceID: .UNKNOWN, command: command, len:Int16(sizeof(T)))
// case (_,let TNil) where TNil is devicePacketNil:
// fallthrough
case (.ASK_VERSION,_),(.RADIO,_),(.READ_PARAMETERS,_),(.DEFAULT_PARAMETER,_) where content is devicePacketNil:
fallthrough
case (.SAVE_PARAMETERS, _) where content is devicePacketParameters:
fallthrough
case (.UPDATE_PARAMETER, _) where content is devicePacketParameters:
header = devicePacketHeader(deviceID: .APSM, command: command, len:Int16(sizeof(T)))
default:
return nil
}
return devicePacketSender(deviceHeader: header, deviceContent: content)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment