Skip to content

Commit

Permalink
chore(client): expose invoke raw method
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrzn committed Aug 8, 2023
1 parent cad3fec commit 488ecdb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PolywrapClient.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
24 changes: 24 additions & 0 deletions Source/PolywrapClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions Tests/Wraps/Features/Invoke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 488ecdb

Please sign in to comment.