Using the same keys and values across different languages

When using the same keys and values across different languages such as Go, JavaScript, and Rust, which data type is the best, bytes or literals such as string or int?

// bytes
// string

And are directory paths also compatible with different languages?

directory.CreateOrOpen(db, []string{"test"}, []byte{})
1 Like

Both the directory layer and the tuple layer are intended to be interoperable across different bindings implementations. There has been occasional weirdness (Tuples: Malformed UTF-16 treated differently in Java and Python · Issue #1186 · apple/foundationdb · GitHub is the only thing that comes to mind).

I think python and java support more features in the tuple layer than other bindings, so to maximize compatibility there avoid using things like arbitrary precision integers. See foundationdb/ at master · apple/foundationdb · GitHub for more details.

1 Like

Thanks! I’ll directly use strings.

Yeah my recommendation is to use tuples if you want your keys to contain anything more complex than strings. Eg if you wanted posts/1, posts/2, etc then those manually encoded strings would work fine - but range requests would return weird results when you get to posts/10. But if you encode that using tuples, it’ll cleverly order everything in a way that means 10 comes after 9.

And yeah, compatibility is excellent with the tuple encoder and directory layer between languages. It’s all tested extensively as part of the binding tester suite.

There’s also this weird inconsistency with 8 byte max int in Python, but outside of that I also can’t think of any other incompatibilities.

I believe that more bindings now support large integers than just Python and Java, but it may still be correct that some bindings have more types available than others. It’s definitely worth checking with the languages you intend to use before using a type in your tuple. It’s also possible, of course, to add support for new types in each language after the fact, if you decide to adopt a binding later and discover it’s missing one.

1 Like

Yes. As with the first example code, I meant using strings as tuple elements.

Big integers are fully supported in the javascript tuple layer too, if that matters to you. As far as I know my unofficial JS implementation has full feature parity with the implementations in Java and python.