Skip to content

Commit c90fffc

Browse files
committed
Add v0 files
1 parent c6d326b commit c90fffc

File tree

6 files changed

+715
-18
lines changed

6 files changed

+715
-18
lines changed

SwiftMQTT/SwiftMQTT.xcodeproj/project.pbxproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
5471A89A1BF228900079610F /* SwiftMQTT.h in Headers */ = {isa = PBXBuildFile; fileRef = 5471A8991BF228900079610F /* SwiftMQTT.h */; settings = {ATTRIBUTES = (Public, ); }; };
1111
5471A8A11BF228900079610F /* SwiftMQTT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5471A8961BF228900079610F /* SwiftMQTT.framework */; };
1212
5471A8A61BF228900079610F /* SwiftMQTTTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5471A8A51BF228900079610F /* SwiftMQTTTests.swift */; };
13+
5471A8E01BF22E9E0079610F /* MQTTSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5471A8DF1BF22E9E0079610F /* MQTTSession.swift */; };
14+
5471A8E21BF2317F0079610F /* MQTTPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5471A8E11BF2317F0079610F /* MQTTPacket.swift */; };
15+
5471A8E41BF231900079610F /* MQTTExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5471A8E31BF231900079610F /* MQTTExtensions.swift */; };
1316
/* End PBXBuildFile section */
1417

1518
/* Begin PBXContainerItemProxy section */
@@ -29,6 +32,9 @@
2932
5471A8A01BF228900079610F /* SwiftMQTTTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftMQTTTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3033
5471A8A51BF228900079610F /* SwiftMQTTTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftMQTTTests.swift; sourceTree = "<group>"; };
3134
5471A8A71BF228900079610F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
35+
5471A8DF1BF22E9E0079610F /* MQTTSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MQTTSession.swift; sourceTree = "<group>"; };
36+
5471A8E11BF2317F0079610F /* MQTTPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MQTTPacket.swift; sourceTree = "<group>"; };
37+
5471A8E31BF231900079610F /* MQTTExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MQTTExtensions.swift; sourceTree = "<group>"; };
3238
/* End PBXFileReference section */
3339

3440
/* Begin PBXFrameworksBuildPhase section */
@@ -73,6 +79,9 @@
7379
children = (
7480
5471A8991BF228900079610F /* SwiftMQTT.h */,
7581
5471A89B1BF228900079610F /* Info.plist */,
82+
5471A8DF1BF22E9E0079610F /* MQTTSession.swift */,
83+
5471A8E11BF2317F0079610F /* MQTTPacket.swift */,
84+
5471A8E31BF231900079610F /* MQTTExtensions.swift */,
7685
);
7786
path = SwiftMQTT;
7887
sourceTree = "<group>";
@@ -194,6 +203,9 @@
194203
isa = PBXSourcesBuildPhase;
195204
buildActionMask = 2147483647;
196205
files = (
206+
5471A8E01BF22E9E0079610F /* MQTTSession.swift in Sources */,
207+
5471A8E41BF231900079610F /* MQTTExtensions.swift in Sources */,
208+
5471A8E21BF2317F0079610F /* MQTTPacket.swift in Sources */,
197209
);
198210
runOnlyForDeploymentPostprocessing = 0;
199211
};
@@ -308,6 +320,7 @@
308320
5471A8AB1BF228900079610F /* Debug */ = {
309321
isa = XCBuildConfiguration;
310322
buildSettings = {
323+
CLANG_ENABLE_MODULES = YES;
311324
DEFINES_MODULE = YES;
312325
DYLIB_COMPATIBILITY_VERSION = 1;
313326
DYLIB_CURRENT_VERSION = 1;
@@ -319,12 +332,14 @@
319332
PRODUCT_BUNDLE_IDENTIFIER = im.ankit.SwiftMQTT;
320333
PRODUCT_NAME = "$(TARGET_NAME)";
321334
SKIP_INSTALL = YES;
335+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
322336
};
323337
name = Debug;
324338
};
325339
5471A8AC1BF228900079610F /* Release */ = {
326340
isa = XCBuildConfiguration;
327341
buildSettings = {
342+
CLANG_ENABLE_MODULES = YES;
328343
DEFINES_MODULE = YES;
329344
DYLIB_COMPATIBILITY_VERSION = 1;
330345
DYLIB_CURRENT_VERSION = 1;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// MQTTExtensions.swift
3+
// SwiftMQTT
4+
//
5+
// Created by Ankit Aggarwal on 10/11/15.
6+
// Copyright © 2015 Ankit. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
enum MQTTSessionError: ErrorType {
12+
case None
13+
case SocketError
14+
}
15+
16+
enum MQTTPacketType: UInt8 {
17+
case Connect = 0x01
18+
case Connack = 0x02
19+
case Publish = 0x03
20+
case PubAck = 0x04
21+
case PubRec = 0x05
22+
case PubRel = 0x06
23+
case PubComp = 0x07
24+
case Subscribe = 0x08
25+
case SubAck = 0x09
26+
case UnSubscribe = 0x0A
27+
case UnSubAck = 0x0B
28+
case PingReq = 0x0C
29+
case PingResp = 0x0D
30+
case Disconnect = 0x0E
31+
32+
}
33+
34+
public enum MQTTQoS: UInt8 {
35+
case AtMostOnce = 0x0
36+
case AtLeastOnce = 0x01
37+
case ExactlyOnce = 0x02
38+
}
39+
40+
enum MQTTConnackResponse: UInt8, ErrorType {
41+
case ConnectionAccepted = 0x00
42+
case BadProtocol = 0x01
43+
case ClientIDRejected = 0x02
44+
case ServerUnavailable = 0x03
45+
case BadUsernameOrPassword = 0x04
46+
case NotAuthorized = 0x05
47+
}
48+
49+
extension NSMutableData {
50+
51+
func encodeRemainingLength(length: Int) {
52+
var lengthOfRemainingData = length
53+
repeat {
54+
var digit = UInt8(lengthOfRemainingData % 128);
55+
lengthOfRemainingData /= 128;
56+
if (lengthOfRemainingData > 0) {
57+
digit |= 0x80;
58+
}
59+
self.appendBytes(&digit, length: 1)
60+
} while (lengthOfRemainingData > 0);
61+
}
62+
63+
func appendUInt8(data: UInt8) {
64+
var varData = data
65+
self.appendBytes(&varData, length: 1)
66+
}
67+
68+
///Appends two bytes
69+
///Big Endian
70+
func appendUInt16(data: UInt16) {
71+
let byteOne = UInt8(data / 256)
72+
let byteTwo = UInt8(data % 256)
73+
self.appendUInt8(byteOne)
74+
self.appendUInt8(byteTwo)
75+
}
76+
77+
func appendMQTTData(data: NSData) {
78+
self.appendUInt16(UInt16(data.length))
79+
self.appendData(data)
80+
}
81+
82+
func appendString(string: String) {
83+
self.appendUInt16(UInt16(string.characters.count))
84+
self.appendData(string.dataUsingEncoding(NSUTF8StringEncoding)!)
85+
}
86+
}

0 commit comments

Comments
 (0)