Ind.ie is now Small Technology Foundation.
Commit deed2158 authored by Dapperstout's avatar Dapperstout

Added "Hello" message.

parent df62bdae
......@@ -45,6 +45,9 @@
4D9D5A5B19F533F70058D1B8 /* Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D9D5A5A19F533F70058D1B8 /* Options.swift */; };
4D9D5A5D19F53AD50058D1B8 /* ClusterConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D9D5A5C19F53AD50058D1B8 /* ClusterConfigTests.swift */; };
4D9D5A5F19F53BAD0058D1B8 /* ClusterConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D9D5A5E19F53BAD0058D1B8 /* ClusterConfig.swift */; };
4DD16D4F1D3F828700A5EEB7 /* HelloTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD16D4D1D3F812100A5EEB7 /* HelloTests.swift */; };
4DD16D511D3F82C800A5EEB7 /* Hello.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD16D501D3F82C800A5EEB7 /* Hello.swift */; };
4DD16D541D3F833F00A5EEB7 /* HelloExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD16D521D3F830900A5EEB7 /* HelloExample.swift */; };
5C2E6F541B8E41D100929C50 /* SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C2E6F531B8E41D100929C50 /* SHA256.swift */; };
5CA368F61B9237F60081F0F6 /* LocalDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA368F11B9237F60081F0F6 /* LocalDevice.swift */; };
5CA368F71B9237F60081F0F6 /* DeviceId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA368F21B9237F60081F0F6 /* DeviceId.swift */; };
......@@ -179,6 +182,9 @@
4D9D5A5A19F533F70058D1B8 /* Options.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Options.swift; sourceTree = "<group>"; };
4D9D5A5C19F53AD50058D1B8 /* ClusterConfigTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClusterConfigTests.swift; sourceTree = "<group>"; };
4D9D5A5E19F53BAD0058D1B8 /* ClusterConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClusterConfig.swift; sourceTree = "<group>"; };
4DD16D4D1D3F812100A5EEB7 /* HelloTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelloTests.swift; sourceTree = "<group>"; };
4DD16D501D3F82C800A5EEB7 /* Hello.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hello.swift; sourceTree = "<group>"; };
4DD16D521D3F830900A5EEB7 /* HelloExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelloExample.swift; sourceTree = "<group>"; };
4DDBE78319A48FBB007EF37E /* Pulse.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pulse.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4DDBE78E19A48FBB007EF37E /* PulseTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PulseTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5C2E6F531B8E41D100929C50 /* SHA256.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SHA256.swift; sourceTree = "<group>"; };
......@@ -338,6 +344,7 @@
4D90356D19F91965009C9A34 /* IndexUpdate.swift */,
C0164BD55E62206876EB86DD /* Message.swift */,
C016482D1A9207829309C52A /* Counter.swift */,
4DD16D501D3F82C800A5EEB7 /* Hello.swift */,
);
path = v1;
sourceTree = "<group>";
......@@ -407,6 +414,8 @@
C01644471099F97008975495 /* OptionsExample.swift */,
C01645CC8D008656B5A17869 /* CounterTests.swift */,
C0164BF74A7990524C673A07 /* CounterExample.swift */,
4DD16D4D1D3F812100A5EEB7 /* HelloTests.swift */,
4DD16D521D3F830900A5EEB7 /* HelloExample.swift */,
);
path = v1;
sourceTree = "<group>";
......@@ -860,6 +869,7 @@
4D213DEA19F70334005DAE61 /* BlockInfo.swift in Sources */,
5CA368F71B9237F60081F0F6 /* DeviceId.swift in Sources */,
4D6A477219E860CF005D7C23 /* Request.swift in Sources */,
4DD16D511D3F82C800A5EEB7 /* Hello.swift in Sources */,
5C2E6F541B8E41D100929C50 /* SHA256.swift in Sources */,
4D6A47A019E868AD005D7C23 /* LZ4Compression.swift in Sources */,
C0164D76FAA209A4FE5BD2A9 /* Luhn.swift in Sources */,
......@@ -906,6 +916,7 @@
5CA369031B9238990081F0F6 /* KeychainTests.swift in Sources */,
5CA369041B9238990081F0F6 /* SynchronizationTests.swift in Sources */,
C0164CF02308A00FF83AAC97 /* SocketSpy.swift in Sources */,
4DD16D541D3F833F00A5EEB7 /* HelloExample.swift in Sources */,
F865F52F1B909E5100BB2480 /* SocketSpyBuilder.swift in Sources */,
C0164569BA58ED9B22C9D9EA /* SecIdentityExample.swift in Sources */,
C00B585E7B5D1388B9570C15 /* X509CertificateTests.swift in Sources */,
......@@ -922,6 +933,7 @@
C01643E0C470153B7CE27F57 /* IndexUpdateExample.swift in Sources */,
5CA369011B9238990081F0F6 /* LocalDeviceTests.swift in Sources */,
C0164501AD541B0F7CD25650 /* PongExample.swift in Sources */,
4DD16D4F1D3F828700A5EEB7 /* HelloTests.swift in Sources */,
C016438D1FF285C8290EACD0 /* RequestExample.swift in Sources */,
C0164DFFB5349C8F6722DAD7 /* ResponseExample.swift in Sources */,
CACF6E933D1819CAA7E34CEA /* AnnouncementTests.swift in Sources */,
......
public class Hello {
public let deviceName: String
public let clientName: String
public let clientVersion: String
public init(deviceName: String, clientName: String, clientVersion: String) {
self.deviceName = deviceName
self.clientName = clientName
self.clientVersion = clientVersion
}
public func serialize() -> [UInt8] {
let writer = XdrWriter()
writer.writeInt32(0x2EA7D90B)
let message = xdr(deviceName, clientName, clientVersion)!
writer.writeInt16(Int16(message.count))
writer.writeString(deviceName)
writer.writeString(clientName)
writer.writeString(clientVersion)
return writer.xdrBytes
}
}
import Pulse
extension Hello {
static var example: Hello {
return Hello(
deviceName: "Some Device Name",
clientName: "Some Client Name",
clientVersion: "v0.4.2"
)
}
}
import Quick
import Nimble
import Pulse
class HelloTests: QuickSpec {
override func spec() {
let hello = Hello.example
var reader: XdrReader!
beforeEach {
reader = XdrReader(xdrBytes: hello.serialize())
}
it("starts with the magic number 0x2EA7D90B") {
expect(reader.readInt32()) == 0x2EA7D90B
}
it("contains the size of the message") {
reader.readInt32()
let expectedBytes = xdr(
hello.deviceName,
hello.clientName,
hello.clientVersion
)!
expect(reader.readInt16()) == Int16(expectedBytes.count)
}
it("contains the device name") {
reader.readInt32()
reader.readInt16()
expect(reader.readString()) == hello.deviceName
}
it("contains the client name") {
reader.readInt32()
reader.readInt16()
reader.readString()
expect(reader.readString()) == hello.clientName
}
it("contains the client version") {
reader.readInt32()
reader.readInt16()
reader.readString()
reader.readString()
expect(reader.readString()) == hello.clientVersion
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment