Skip to content

Conversation

@cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented May 8, 2023

This PR is mainly to determine if the binding style I'm using here will make sense, it's not a full implementation. In the spirit of not having massive PRs.

Missing are all the various sub-builders.

The main idea is that we'll have 4 opaque types,LD(Client|Server)Config(Builder). No naming collisions, so someone could use both SDKs in the same app.

But it does imply we'd need to dupe all the builder methods for both SDKs.

I feel like this makes sense, since we might have different config options for each. Otherwise, we would need to document specific methods / arrange the includes such that you can't accidentally call LDConfigSetSomeClientThing on a server config.

Ryan you might have better ideas.

Finally, I've added in an LDStatus type. On the C++ side we use tl::expected<T, Error>. In C, we can mirror this pattern with out params and return value:

T out;
LDStatus status = Foo_DoFallibleThing(foo, &out);

if (LDStatus_Ok(status)) {
  // it succeeded, go ahead and access 'out'
} else {
   print(LDStatus_Error(status))
}

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #201468: Create C bindings for Config type.


LD_EXPORT(LDClientConfigBuilder)
LDClientConfigBuilder_New(char const* sdk_key) {
return FROM_BUILDER(new ConfigBuilder(sdk_key ? sdk_key : ""));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe as of c++2023 it will be illegal to even pass nullptr to an std::string constructor.

@cwaldren-ld cwaldren-ld changed the title feat: c bindings for client configuration feat: incomplete C bindings for client configuration May 8, 2023

return LDStatus_Success();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this a helper so we can ensure builders are handled consistently across the C binding (like - always assigning nullptr to out result on failure, or whatever we choose.)

I do wonder this method should consume the builder, though. It's not consuming in C++, so you could theoretically inspect the error and allow for rebuilding until the problem is fixed - but I'm not sure that would be a common use-case.

@cwaldren-ld cwaldren-ld force-pushed the cw/sc-201468/client-config-bindings branch from 68b85d9 to 19d8e4e Compare May 8, 2023 21:41
@cwaldren-ld cwaldren-ld marked this pull request as ready for review May 8, 2023 21:42
@cwaldren-ld cwaldren-ld requested a review from kinyoklion May 8, 2023 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants