Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ var package = Package(
targets: ["PureSwiftJSONParsing"]),
],
dependencies: [

// these are only used for testing
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "0.0.1")),
.package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.13.0"))
],
targets: [
.target(
name: "JSONTestSuiteCLI",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "NIO", package: "swift-nio"),
]
),
.target(
name: "PureSwiftJSONCoding",
dependencies: ["PureSwiftJSONParsing"]),
Expand Down
39 changes: 39 additions & 0 deletions Sources/JSONTestSuiteCLI/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ArgumentParser
import NIO

struct JSONTestSuiteCLI: ParsableCommand {

@Argument(help: "the json file to parse") var jsonFile: String

func run() throws {
// here lives the logic

let bytes = try self.read(file: jsonFile)


}

func read(file: String) throws -> [UInt8] {

let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
try! group.syncShutdownGracefully()
}
let loop = group.next()
let threadPool = NIOThreadPool(numberOfThreads: 1)
threadPool.start()
defer {
try! threadPool.syncShutdownGracefully()
}
let fileIO = NonBlockingFileIO(threadPool: threadPool)

let (handle, region) = try fileIO.openFile(path: file, eventLoop: loop).wait()
let allocator = ByteBufferAllocator()
var buffer = try fileIO.read(fileRegion: region, allocator: allocator, eventLoop: loop).wait()

return buffer.readBytes(length: buffer.readableBytes)!
}

}

JSONTestSuiteCLI.main()