Skip to content

Commit

Permalink
Debugging!
Browse files Browse the repository at this point in the history
  • Loading branch information
fumoboy007 committed Jun 6, 2024
1 parent ee5ae8d commit 60a81d7
Show file tree
Hide file tree
Showing 8 changed files with 1,791 additions and 1,764 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ import Foundation

extension EncodableMessagePackValue {
func encode(to messageWriter: inout MessageWriter) throws {

switch self {
case .future(let future):
let value = try future.encodableMessagePackValue
try value.encode(to: &messageWriter)

case .nil:

encodeNil(to: &messageWriter)

case .boolean(let value):

encode(value, to: &messageWriter)

case .signedInteger(let value):

encode(value, to: &messageWriter)

case .unsignedInteger(let value):

encode(value, to: &messageWriter)

case .float32(let value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ extension SingleValueMessagePackEncodingContainer: SingleValueEncodingContainer
}

func encodeNil() throws {

encoder.store(.nil)
}

func encode(_ value: Bool) throws {

encoder.store(.boolean(value))
}

Expand All @@ -54,49 +56,62 @@ extension SingleValueMessagePackEncodingContainer: SingleValueEncodingContainer
}

func encode(_ value: Int) throws {

encoder.store(.init(value))
}

func encode(_ value: Int8) throws {

encoder.store(.init(value))
}

func encode(_ value: Int16) throws {

encoder.store(.init(value))
}

func encode(_ value: Int32) throws {

encoder.store(.init(value))
}

func encode(_ value: Int64) throws {

encoder.store(.init(value))
}

func encode(_ value: UInt) throws {

encoder.store(.init(value))
}

func encode(_ value: UInt8) throws {

encoder.store(.init(value))
}

func encode(_ value: UInt16) throws {

encoder.store(.init(value))
}

func encode(_ value: UInt32) throws {

encoder.store(.init(value))
}

func encode(_ value: UInt64) throws {

encoder.store(.init(value))
}

func encode<T: Encodable>(_ value: T) throws {

if let messagePackValue = EncodableMessagePackValue(standardCompoundValue: value) {

encoder.store(messagePackValue)
} else {

let nestedEncoder = encoder.nestedEncoder()
try value.encode(to: nestedEncoder)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/MessagePack/MessagePackEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public struct MessagePackEncoder {
try singleValueContainer.encode(value)

let messagePackValue = try swiftToMessagePackValueEncoder.encodableMessagePackValue
print(messagePackValue)

var messageWriter = MessageWriter()
try messagePackValue.encode(to: &messageWriter)
Expand Down
5 changes: 5 additions & 0 deletions Sources/MessagePack/MessageWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public struct MessageWriter: ~Copyable {

public mutating func write(byte: UInt8) {
withUnsafePointer(to: byte) {
print($0.pointee)
// print(UnsafeBufferPointer(start: $0, count: 1)[0])
// print(UnsafeRawBufferPointer(UnsafeBufferPointer(start: $0, count: 1))[0])
// print(Array(Data(bytes: $0, count: 1)))
message.append($0, count: 1)
}
print(Array(message))
}

public mutating func write(_ bytes: UnsafeRawBufferPointer) {
Expand Down
56 changes: 28 additions & 28 deletions Tests/Benchmarks/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ final class Benchmarks: XCTestCase {
static let iterationCount = 10_000

func testAlpacaTradeEvent() async throws {
let alpacaTradeEvent = AlpacaTradeEvent.fake
let alpacaTradeEventForSwiftMsgpack = AlpacaTradeEventForSwiftMsgpack(alpacaTradeEvent)
let alpacaTradeEventForMessagePacker = AlpacaTradeEventForMessagePacker(alpacaTradeEvent)

try runBenchmark(blockUsingCurrentLibrary: {
try Self.encodeAndDecodeUsingCurrentLibrary(alpacaTradeEvent)
}, otherLibraryNameToBlockMap: [
"nnabeyang/swift-msgpack": {
try Self.encodeAndDecodeUsingSwiftMsgpackLibrary(alpacaTradeEventForSwiftMsgpack)
},
"hirotakan/MessagePacker": {
try Self.encodeAndDecodeUsingMessagePackerLibrary(alpacaTradeEventForMessagePacker)
}
])
// let alpacaTradeEvent = AlpacaTradeEvent.fake
// let alpacaTradeEventForSwiftMsgpack = AlpacaTradeEventForSwiftMsgpack(alpacaTradeEvent)
// let alpacaTradeEventForMessagePacker = AlpacaTradeEventForMessagePacker(alpacaTradeEvent)
//
// try runBenchmark(blockUsingCurrentLibrary: {
// try Self.encodeAndDecodeUsingCurrentLibrary(alpacaTradeEvent)
// }, otherLibraryNameToBlockMap: [
// "nnabeyang/swift-msgpack": {
// try Self.encodeAndDecodeUsingSwiftMsgpackLibrary(alpacaTradeEventForSwiftMsgpack)
// },
// "hirotakan/MessagePacker": {
// try Self.encodeAndDecodeUsingMessagePackerLibrary(alpacaTradeEventForMessagePacker)
// }
// ])
}

func testAlpacaQuoteEvent() async throws {
let alpacaQuoteEvent = AlpacaQuoteEvent.fake
let alpacaQuoteEventForSwiftMsgpack = AlpacaQuoteEventForSwiftMsgpack(alpacaQuoteEvent)
let alpacaQuoteEventForMessagePacker = AlpacaQuoteEventForMessagePacker(alpacaQuoteEvent)

try runBenchmark(blockUsingCurrentLibrary: {
try Self.encodeAndDecodeUsingCurrentLibrary(alpacaQuoteEvent)
}, otherLibraryNameToBlockMap: [
"nnabeyang/swift-msgpack": {
try Self.encodeAndDecodeUsingSwiftMsgpackLibrary(alpacaQuoteEventForSwiftMsgpack)
},
"hirotakan/MessagePacker": {
try Self.encodeAndDecodeUsingMessagePackerLibrary(alpacaQuoteEventForMessagePacker)
}
])
// let alpacaQuoteEvent = AlpacaQuoteEvent.fake
// let alpacaQuoteEventForSwiftMsgpack = AlpacaQuoteEventForSwiftMsgpack(alpacaQuoteEvent)
// let alpacaQuoteEventForMessagePacker = AlpacaQuoteEventForMessagePacker(alpacaQuoteEvent)
//
// try runBenchmark(blockUsingCurrentLibrary: {
// try Self.encodeAndDecodeUsingCurrentLibrary(alpacaQuoteEvent)
// }, otherLibraryNameToBlockMap: [
// "nnabeyang/swift-msgpack": {
// try Self.encodeAndDecodeUsingSwiftMsgpackLibrary(alpacaQuoteEventForSwiftMsgpack)
// },
// "hirotakan/MessagePacker": {
// try Self.encodeAndDecodeUsingMessagePackerLibrary(alpacaQuoteEventForMessagePacker)
// }
// ])
}

private static func encodeAndDecodeUsingCurrentLibrary<T: Codable>(_ value: T) throws {
Expand Down
Loading

0 comments on commit 60a81d7

Please sign in to comment.