From 488ecdb35461ba38de5bb9144ca2b37609c75caa Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 8 Aug 2023 14:13:49 +0200 Subject: [PATCH] chore(client): expose invoke raw method --- PolywrapClient.podspec | 2 +- Source/PolywrapClient.swift | 24 ++++++++++++++++++++++++ Tests/Wraps/Features/Invoke.swift | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/PolywrapClient.podspec b/PolywrapClient.podspec index e0c904e..0b45ff5 100644 --- a/PolywrapClient.podspec +++ b/PolywrapClient.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PolywrapClient' - s.version = '0.0.6' + s.version = '0.0.7' s.summary = 'Implementation of a client compatible with the WRAP Protocol in Swift' s.homepage = 'https://github.com/polywrap/swift-client' s.license = 'MIT' diff --git a/Source/PolywrapClient.swift b/Source/PolywrapClient.swift index 579d504..5d6457f 100644 --- a/Source/PolywrapClient.swift +++ b/Source/PolywrapClient.swift @@ -115,6 +115,30 @@ public class PolywrapClient { return try decode(value: result) } + /// Invokes a raw method without decoding or encoding arguments and environment variables. + /// + /// This method is a direct interface to the `FfiClient`'s raw invocation and is useful when + /// you want to interact with the underlying layer without the automatic encoding/decoding of parameters. + /// This is especially useful for cases where you need greater control over the data formats + /// or when dealing with raw bytes. + /// + /// - Parameters: + /// - uri: A `Uri` object representing the method's location. + /// - method: The name of the method to invoke. + /// - args: A msgpack buffer representing the arguments for the method. Optional. + /// - env: A msgpack buffer representing the environment variables for the method. Optional. + /// - Throws: If the invocation fails. + /// - Returns: A msgpack buffer representing the result of the invocation. + public func invokeRaw(uri: Uri, method: String, args: [UInt8]?, env: [UInt8]?) throws -> [UInt8] { + return try self.ffi.invokeRaw( + uri: uri.ffi, + method: method, + args: args, + env: env, + resolutionContext: nil + ) + } + /// Retrieves environment variables by Uri. /// /// - Parameters: diff --git a/Tests/Wraps/Features/Invoke.swift b/Tests/Wraps/Features/Invoke.swift index e5e398c..d48c5b9 100644 --- a/Tests/Wraps/Features/Invoke.swift +++ b/Tests/Wraps/Features/Invoke.swift @@ -80,4 +80,15 @@ final class InvokeTests: XCTestCase { let result: Int = try client.invoke(uri: invokeWrapUri, method: "addAndIncrement", args: AddArgs(a: 1, b: 1)) XCTAssertEqual(result, 3) } + + func testInvokeRaw() throws { + let wrap = try getTestWrap(path: "subinvoke/00-subinvoke/implementations/as") + let uri = try Uri("wrap://wrap/embedded") + let builder = BuilderConfig().addWrapper(uri, wrap) + let client = builder.build() + + let encodedArgs = try encode(value: AddArgs(a: 1, b: 1)) + let result = try client.invokeRaw(uri: uri, method: "add", args: encodedArgs, env: nil) + XCTAssertEqual(result, [2]) + } }