29 Commits

Author SHA1 Message Date
65ab46f714
connection: eliminate String method variants
After contemplating this for a little bit, there's no point in exposing
these separately from the plain variants. Even nats.c internally calls
its plain variants after calling `strlen` on the input. Zig benefits
from having nicer pointer types than C, so we get "string" handling
for free from the fact that the standard variants take slices anyway.
2023-08-23 22:27:33 -07:00
1256feb7ef
examples: always build in debug mode
There's no reason I can think of for these to be optimized.
2023-08-23 22:25:36 -07:00
18205a5533
examples: add statistics to request_reply
I should probably write some tests instead.
2023-08-23 22:18:45 -07:00
3816f32101
statistics: fix a remarkably bungled wrapper
keyboards are hard.
2023-08-23 22:18:03 -07:00
b101e0acd2
message: more iterators, less problems
This seems like a pretty nice way to do this, since it lets us produce
the sliced version of each value rather than the somewhat janky many
pointer.
2023-08-23 22:03:25 -07:00
ebd3e64111
examples: port header example to zig
This looks a lot nicer than its c counterpart, in my opinion.
2023-08-23 01:05:37 -07:00
3e5840bd84
message: fix header method types and add header iterator
As I ascertained from reading the code, nats.c does in fact let you set
message headers with null values. However, the library segfaults if
you try to actually send such a message over the wire. So we just
forbid it with stricter typing and assume it's not possible for
someone to send us a message containing headers with a null value as
well.
2023-08-23 01:03:29 -07:00
48962f27d9
add examples and integrate into build
I suppose the next step will be to translate the C examples into their
zig counterparts. This is also good dog food.
2023-08-21 23:51:58 -07:00
40d898a55e
tests: start building tests in separate directory
This approach seems nice, and as a bonus it makes it easier to run the
tests through the module interface rather than by importing the
sources directly, which I think is a good dog food approach.
2023-08-21 23:31:46 -07:00
ef185bc975
build: convert to being a module 2023-08-21 23:30:31 -07:00
9a4c80861c
connection: finish wrapping connection methods
I believe the standard API surface is now completely wrapped, ignoring
whatever cool copy-paste errors or other mistakes I introduced which
are currently undetectable due to lazy analysis and lack of test
coverage. Cool.
2023-08-19 19:00:15 -07:00
39edf12d34
connection.ConnectionOptions: finish hooking up callbacks
This was kind of tedious, but there were some interesting choices to be
made with regards to how the callback signatures should be adapted,
especially in the few cases that heavily use out-params in C. Ignoring
the lack of test coverage, this puts us pretty close to having the
entire basic API wrapped.
2023-08-19 17:15:29 -07:00
3ff894cc0d
keep thunkening
There are a lot of callbacks to wrap. This is a sloppy commit that
almost certainly needs fixes.
2023-08-18 23:01:33 -07:00
2e1a5579b9
connection: mostly wrap the connection options API
There are a several options that set up callbacks that I did not wrap
in this first pass because I need to decide on whether or not it makes
sense to move the various thunks into a common location. There's one
that could be shared between the subscriptions and here due to having
the same signature, but I'm not sure there are any others that would
really benefit from cross-file sharing.
2023-08-17 23:46:08 -07:00
4a7635fa7b
nats-c.build.zig: fix cross-compiling from Linux
There is a case-sensitivity issue here. The Windows documentation calls
the library Ws2_32, but the mingw cross-compilation on Linux fails
unless it is called `ws3_32`. For some reason, both work on macOS. I
have not tried on Windows, but I assume this will probably work there
due to everything being extremely insensitive (case-wise) on Windows.
2023-08-16 23:30:04 -07:00
3cf173c923
nats: wrap a couple of loose functions
These are probably not useful at all at the moment, but they were
trivial to do.
2023-08-16 21:33:02 -07:00
3ced6db69d
message: play around with unit testing
I think I am probably going to move unit tests to a separate
directory/file structure. This will allow me to add a bunch of utility
functions that don't get analyzed for the library compilation and also
avoid testing-only imports in the main modules.
2023-08-15 22:23:35 -07:00
970d274593
nats: fix typo'd C api call 2023-08-15 22:23:35 -07:00
55690ced02
subscription: wrap all basic API calls
Hopefully I am not missing anything here. Will need to comb through the
public API to make sure no calls are missing.
2023-08-15 22:23:35 -07:00
94a428139d
message: wrap all basic API calls
The streaming API is not wrapped because we do not build nats.c with
the necessary libraries. The jetstream API is not wrapped because I am
extremely lazy and it's outside of the minimum viable scope at the
moment. It can happen after the other basic APIs have been wrapped.
2023-08-15 22:23:35 -07:00
b55dfe0732
subscription: remove dangling old implementation
Missed this before the commit train left the station.
2023-08-15 20:11:57 -07:00
79a45fd2e3
git subrepo clone (merge) --branch=v3.6.1 https://github.com/nats-io/nats.c.git deps/nats.c
subrepo:
  subdir:   "deps/nats.c"
  merged:   "66cec7f"
upstream:
  origin:   "https://github.com/nats-io/nats.c.git"
  branch:   "v3.6.1"
  commit:   "66cec7f"
git-subrepo:
  version:  "0.4.6"
  commit:   "b8b46501e"
2023-08-15 00:21:33 -07:00
5bc936a09f
deps: remove nats.c submodule
I'm going to try out git-subrepo. The main reason for this is that
github's autogenerated tarballs do not include submodules. And
github's autogenerated tarballs are the easiest way to integrate into
the zig package manager. Since git-subrepo checks the files into the
tree directly, new tarballs should include this dependency code.
2023-08-15 00:16:05 -07:00
b78033f818
build: move cross-compilation shim into nats-c.build.zig
It makes more sense for it to be here. I'm really not sure why I put it
in the main build in the first place.
2023-08-15 00:04:44 -07:00
fbb45f1567
readme: add some notes about zig version support 2023-08-14 22:46:44 -07:00
aea64fb625
all: start wrapping API
This is pretty much just the API surface that is used in the demo code
for now, with a couple of minor things I tacked on while getting a
feel for how I was going to go about it. Unfortunately, the diff is
too messy to show the improvement provided by the wrapped API, but I'm
pretty pleased with how it is turning out so far. In general, there
have been no major hiccups.

Most of the time working on this was spent noodling about how to create
the subscription callback thunk to provide type safety and pointer
nullability guarantees for the subscription zig API. I'm satisfied
with the solution in place now: it seems to have good default
ergonomics and very few downsides except that the callback function
must be known at compile time. An earlier iteration of this code
supported runtime function pointers but had a showstopping problem
with memory management. In order to store the runtime callback
pointer, the thunk would need to be allocated, but there was no way of
attaching our allocated memory to the c-library subscription object.
No attachment meant that there were a number of error scenarios where
the allocated thunk couldn't be freed correctly.

Ultimately, if the user needs to use runtime callback pointers they can
write a comptime known callback that calls a runtime known callback.
This way all of the object lifetime and ownership is in the user's
hands, which is really where it needs to belong anyway for this.
2023-08-14 22:40:41 -07:00
c4fb6c6579
Add a readme
look ma, I'm a real project now
2023-08-14 01:38:21 -07:00
e935df3060
Add license info
It's easy to pick the apache license because that's what nats.c uses.
It's a permissive license, and there's no need to get fancy here.
2023-08-14 00:29:34 -07:00
d957a4605a
init
This builds a very basic version of the nats.c client (no TLS, no
streaming/jetstream/whatever, since those bring in complex
dependencies and I do not need them at the moment). Right now it
contains a simple test program that demonstrates the functionality
(cool!), but the plan is for the nats.zig to bind the API into a
nicer, zig-like shape and re-export it. Then this becomes a package.
The current function could become a test, though it's a bit complex
for a unit test (and requires connecting to an externally-running NATS
server in order to work).
2023-08-13 23:35:42 -07:00