From f9dc4ed6b32c83aca02f7eebe860746303144bfc Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Sun, 7 Sep 2025 18:20:55 +0700 Subject: [PATCH] refactor: Gen ffi library --- .github/workflows/ci.yml | 2 +- .gitignore | 6 +- analysis_options.yaml | 2 + doc/contribute.md | 67 + lib/gen/library.dart | 10795 +++++++++++++++++++++++++++++ lib/pact_dart.dart | 1 - lib/src/bindings/bindings.dart | 183 +- lib/src/bindings/signatures.dart | 169 - lib/src/bindings/types.dart | 43 - lib/src/ffi/extensions.dart | 7 - lib/src/interaction.dart | 58 +- lib/src/pact_mock_service.dart | 30 +- pubspec.lock | 36 +- pubspec.yaml | 7 + 14 files changed, 10960 insertions(+), 446 deletions(-) create mode 100644 doc/contribute.md create mode 100644 lib/gen/library.dart delete mode 100644 lib/src/bindings/signatures.dart delete mode 100644 lib/src/bindings/types.dart delete mode 100644 lib/src/ffi/extensions.dart diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ac82a7..aa001b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: run: dart pub get - name: Run analyzers and linters run: | - dart format --set-exit-if-changed . + dart format lib/src lib/pact_dart.dart test bin example --set-exit-if-changed . dart analyze tests: diff --git a/.gitignore b/.gitignore index 39d9a01..c651806 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,8 @@ contracts/ # Coverage *.lcov -coverage/ \ No newline at end of file +coverage/ + +# Downloaded files +pact.h +libpact_ffi.so diff --git a/analysis_options.yaml b/analysis_options.yaml index 2ff7341..f317ed7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,3 +7,5 @@ analyzer: camel_case_types: ignore constant_identifier_names: ignore non_constant_identifier_names: ignore + exclude: + - lib/src/bindings/library.dart diff --git a/doc/contribute.md b/doc/contribute.md new file mode 100644 index 0000000..5898eab --- /dev/null +++ b/doc/contribute.md @@ -0,0 +1,67 @@ +# Contributing to pact_dart + +Thanks for contributing! Here’s how to get started: + +--- + +## Run Tests + +1. Clone and create a new branch: + +```bash +git clone https://github.com/pact-foundation/pact-dart.git +cd pact-dart +git checkout -b my-change +``` + +2. Install dependencies: + +```bash +dart pub get +dart run pact_dart:install +# Or use custom lib download path +PACT_DART_LIB_DOWNLOAD_PATH=. dart run pact_dart:install +``` + +3. Run tests: + +```bash +dart test +# Or use custom lib download path +PACT_DART_LIB_DOWNLOAD_PATH=. dart test -j 1 +``` + +## Generate Bindings with ffigen + +1. Download Pact FFI headers + +```bash +# Ubuntu +VERSION=0.4.27 +wget "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$VERSION/pact.h" +# MacOS +VERSION=0.4.27 +curl -O "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$VERSION/pact.h" +# Windows +$VERSION = "0.4.27" +Invoke-WebRequest -Uri "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$VERSION/pact.h" -OutFile "pact.h" +``` + +2. Install LLVM + +```bash +# Ubuntu +sudo apt-get install libclang-dev +# Windows +winget install -e --id LLVM.LLVM +# MacOS +xcode-select --install +``` + +3. Regenerate bindings: + +```bash +dart run ffigen +``` + +This will update the generated Dart bindings under `lib/gen/library.dart`. diff --git a/lib/gen/library.dart b/lib/gen/library.dart new file mode 100644 index 0000000..37d7d4b --- /dev/null +++ b/lib/gen/library.dart @@ -0,0 +1,10795 @@ +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint +import 'dart:ffi' as ffi; + +class NativeLibrary { + /// Holds the symbol lookup function. + final ffi.Pointer Function(String symbolName) + _lookup; + + /// The symbols are looked up in [dynamicLibrary]. + NativeLibrary(ffi.DynamicLibrary dynamicLibrary) + : _lookup = dynamicLibrary.lookup; + + /// The symbols are looked up with [lookup]. + NativeLibrary.fromLookup( + ffi.Pointer Function(String symbolName) + lookup) + : _lookup = lookup; + + int __ctype_get_mb_cur_max() { + return ___ctype_get_mb_cur_max(); + } + + late final ___ctype_get_mb_cur_maxPtr = + _lookup>( + '__ctype_get_mb_cur_max'); + late final ___ctype_get_mb_cur_max = + ___ctype_get_mb_cur_maxPtr.asFunction(); + + double atof( + ffi.Pointer __nptr, + ) { + return _atof( + __nptr, + ); + } + + late final _atofPtr = + _lookup)>>( + 'atof'); + late final _atof = + _atofPtr.asFunction)>(); + + int atoi( + ffi.Pointer __nptr, + ) { + return _atoi( + __nptr, + ); + } + + late final _atoiPtr = + _lookup)>>( + 'atoi'); + late final _atoi = _atoiPtr.asFunction)>(); + + int atol( + ffi.Pointer __nptr, + ) { + return _atol( + __nptr, + ); + } + + late final _atolPtr = + _lookup)>>( + 'atol'); + late final _atol = _atolPtr.asFunction)>(); + + int atoll( + ffi.Pointer __nptr, + ) { + return _atoll( + __nptr, + ); + } + + late final _atollPtr = + _lookup)>>( + 'atoll'); + late final _atoll = + _atollPtr.asFunction)>(); + + double strtod( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + ) { + return _strtod( + __nptr, + __endptr, + ); + } + + late final _strtodPtr = _lookup< + ffi.NativeFunction< + ffi.Double Function(ffi.Pointer, + ffi.Pointer>)>>('strtod'); + late final _strtod = _strtodPtr.asFunction< + double Function( + ffi.Pointer, ffi.Pointer>)>(); + + double strtof( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + ) { + return _strtof( + __nptr, + __endptr, + ); + } + + late final _strtofPtr = _lookup< + ffi.NativeFunction< + ffi.Float Function(ffi.Pointer, + ffi.Pointer>)>>('strtof'); + late final _strtof = _strtofPtr.asFunction< + double Function( + ffi.Pointer, ffi.Pointer>)>(); + + int strtol( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtol( + __nptr, + __endptr, + __base, + ); + } + + late final _strtolPtr = _lookup< + ffi.NativeFunction< + ffi.Long Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtol'); + late final _strtol = _strtolPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + int strtoul( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtoul( + __nptr, + __endptr, + __base, + ); + } + + late final _strtoulPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedLong Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtoul'); + late final _strtoul = _strtoulPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + int strtoq( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtoq( + __nptr, + __endptr, + __base, + ); + } + + late final _strtoqPtr = _lookup< + ffi.NativeFunction< + ffi.LongLong Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtoq'); + late final _strtoq = _strtoqPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + int strtouq( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtouq( + __nptr, + __endptr, + __base, + ); + } + + late final _strtouqPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedLongLong Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtouq'); + late final _strtouq = _strtouqPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + int strtoll( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtoll( + __nptr, + __endptr, + __base, + ); + } + + late final _strtollPtr = _lookup< + ffi.NativeFunction< + ffi.LongLong Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtoll'); + late final _strtoll = _strtollPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + int strtoull( + ffi.Pointer __nptr, + ffi.Pointer> __endptr, + int __base, + ) { + return _strtoull( + __nptr, + __endptr, + __base, + ); + } + + late final _strtoullPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedLongLong Function(ffi.Pointer, + ffi.Pointer>, ffi.Int)>>('strtoull'); + late final _strtoull = _strtoullPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>, int)>(); + + ffi.Pointer l64a( + int __n, + ) { + return _l64a( + __n, + ); + } + + late final _l64aPtr = + _lookup Function(ffi.Long)>>( + 'l64a'); + late final _l64a = _l64aPtr.asFunction Function(int)>(); + + int a64l( + ffi.Pointer __s, + ) { + return _a64l( + __s, + ); + } + + late final _a64lPtr = + _lookup)>>( + 'a64l'); + late final _a64l = _a64lPtr.asFunction)>(); + + int select( + int __nfds, + ffi.Pointer __readfds, + ffi.Pointer __writefds, + ffi.Pointer __exceptfds, + ffi.Pointer __timeout, + ) { + return _select( + __nfds, + __readfds, + __writefds, + __exceptfds, + __timeout, + ); + } + + late final _selectPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Int, ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>('select'); + late final _select = _selectPtr.asFunction< + int Function(int, ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer)>(); + + int pselect( + int __nfds, + ffi.Pointer __readfds, + ffi.Pointer __writefds, + ffi.Pointer __exceptfds, + ffi.Pointer __timeout, + ffi.Pointer<__sigset_t> __sigmask, + ) { + return _pselect( + __nfds, + __readfds, + __writefds, + __exceptfds, + __timeout, + __sigmask, + ); + } + + late final _pselectPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer<__sigset_t>)>>('pselect'); + late final _pselect = _pselectPtr.asFunction< + int Function( + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer<__sigset_t>)>(); + + int random() { + return _random(); + } + + late final _randomPtr = + _lookup>('random'); + late final _random = _randomPtr.asFunction(); + + void srandom( + int __seed, + ) { + return _srandom( + __seed, + ); + } + + late final _srandomPtr = + _lookup>( + 'srandom'); + late final _srandom = _srandomPtr.asFunction(); + + ffi.Pointer initstate( + int __seed, + ffi.Pointer __statebuf, + int __statelen, + ) { + return _initstate( + __seed, + __statebuf, + __statelen, + ); + } + + late final _initstatePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.UnsignedInt, ffi.Pointer, ffi.Size)>>('initstate'); + late final _initstate = _initstatePtr.asFunction< + ffi.Pointer Function(int, ffi.Pointer, int)>(); + + ffi.Pointer setstate( + ffi.Pointer __statebuf, + ) { + return _setstate( + __statebuf, + ); + } + + late final _setstatePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('setstate'); + late final _setstate = _setstatePtr + .asFunction Function(ffi.Pointer)>(); + + int random_r( + ffi.Pointer __buf, + ffi.Pointer __result, + ) { + return _random_r( + __buf, + __result, + ); + } + + late final _random_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('random_r'); + late final _random_r = _random_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + int srandom_r( + int __seed, + ffi.Pointer __buf, + ) { + return _srandom_r( + __seed, + __buf, + ); + } + + late final _srandom_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.UnsignedInt, ffi.Pointer)>>('srandom_r'); + late final _srandom_r = + _srandom_rPtr.asFunction)>(); + + int initstate_r( + int __seed, + ffi.Pointer __statebuf, + int __statelen, + ffi.Pointer __buf, + ) { + return _initstate_r( + __seed, + __statebuf, + __statelen, + __buf, + ); + } + + late final _initstate_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.UnsignedInt, ffi.Pointer, ffi.Size, + ffi.Pointer)>>('initstate_r'); + late final _initstate_r = _initstate_rPtr.asFunction< + int Function( + int, ffi.Pointer, int, ffi.Pointer)>(); + + int setstate_r( + ffi.Pointer __statebuf, + ffi.Pointer __buf, + ) { + return _setstate_r( + __statebuf, + __buf, + ); + } + + late final _setstate_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('setstate_r'); + late final _setstate_r = _setstate_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + int rand() { + return _rand(); + } + + late final _randPtr = _lookup>('rand'); + late final _rand = _randPtr.asFunction(); + + void srand( + int __seed, + ) { + return _srand( + __seed, + ); + } + + late final _srandPtr = + _lookup>('srand'); + late final _srand = _srandPtr.asFunction(); + + int rand_r( + ffi.Pointer __seed, + ) { + return _rand_r( + __seed, + ); + } + + late final _rand_rPtr = _lookup< + ffi.NativeFunction)>>( + 'rand_r'); + late final _rand_r = + _rand_rPtr.asFunction)>(); + + double drand48() { + return _drand48(); + } + + late final _drand48Ptr = + _lookup>('drand48'); + late final _drand48 = _drand48Ptr.asFunction(); + + double erand48( + ffi.Pointer __xsubi, + ) { + return _erand48( + __xsubi, + ); + } + + late final _erand48Ptr = _lookup< + ffi.NativeFunction< + ffi.Double Function(ffi.Pointer)>>('erand48'); + late final _erand48 = + _erand48Ptr.asFunction)>(); + + int lrand48() { + return _lrand48(); + } + + late final _lrand48Ptr = + _lookup>('lrand48'); + late final _lrand48 = _lrand48Ptr.asFunction(); + + int nrand48( + ffi.Pointer __xsubi, + ) { + return _nrand48( + __xsubi, + ); + } + + late final _nrand48Ptr = _lookup< + ffi.NativeFunction< + ffi.Long Function(ffi.Pointer)>>('nrand48'); + late final _nrand48 = + _nrand48Ptr.asFunction)>(); + + int mrand48() { + return _mrand48(); + } + + late final _mrand48Ptr = + _lookup>('mrand48'); + late final _mrand48 = _mrand48Ptr.asFunction(); + + int jrand48( + ffi.Pointer __xsubi, + ) { + return _jrand48( + __xsubi, + ); + } + + late final _jrand48Ptr = _lookup< + ffi.NativeFunction< + ffi.Long Function(ffi.Pointer)>>('jrand48'); + late final _jrand48 = + _jrand48Ptr.asFunction)>(); + + void srand48( + int __seedval, + ) { + return _srand48( + __seedval, + ); + } + + late final _srand48Ptr = + _lookup>('srand48'); + late final _srand48 = _srand48Ptr.asFunction(); + + ffi.Pointer seed48( + ffi.Pointer __seed16v, + ) { + return _seed48( + __seed16v, + ); + } + + late final _seed48Ptr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('seed48'); + late final _seed48 = _seed48Ptr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + void lcong48( + ffi.Pointer __param, + ) { + return _lcong48( + __param, + ); + } + + late final _lcong48Ptr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>('lcong48'); + late final _lcong48 = + _lcong48Ptr.asFunction)>(); + + int drand48_r( + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _drand48_r( + __buffer, + __result, + ); + } + + late final _drand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('drand48_r'); + late final _drand48_r = _drand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + int erand48_r( + ffi.Pointer __xsubi, + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _erand48_r( + __xsubi, + __buffer, + __result, + ); + } + + late final _erand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('erand48_r'); + late final _erand48_r = _erand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + int lrand48_r( + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _lrand48_r( + __buffer, + __result, + ); + } + + late final _lrand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('lrand48_r'); + late final _lrand48_r = _lrand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + int nrand48_r( + ffi.Pointer __xsubi, + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _nrand48_r( + __xsubi, + __buffer, + __result, + ); + } + + late final _nrand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>('nrand48_r'); + late final _nrand48_r = _nrand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + int mrand48_r( + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _mrand48_r( + __buffer, + __result, + ); + } + + late final _mrand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('mrand48_r'); + late final _mrand48_r = _mrand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + int jrand48_r( + ffi.Pointer __xsubi, + ffi.Pointer __buffer, + ffi.Pointer __result, + ) { + return _jrand48_r( + __xsubi, + __buffer, + __result, + ); + } + + late final _jrand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>('jrand48_r'); + late final _jrand48_r = _jrand48_rPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + int srand48_r( + int __seedval, + ffi.Pointer __buffer, + ) { + return _srand48_r( + __seedval, + __buffer, + ); + } + + late final _srand48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Long, ffi.Pointer)>>('srand48_r'); + late final _srand48_r = + _srand48_rPtr.asFunction)>(); + + int seed48_r( + ffi.Pointer __seed16v, + ffi.Pointer __buffer, + ) { + return _seed48_r( + __seed16v, + __buffer, + ); + } + + late final _seed48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('seed48_r'); + late final _seed48_r = _seed48_rPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer)>(); + + int lcong48_r( + ffi.Pointer __param, + ffi.Pointer __buffer, + ) { + return _lcong48_r( + __param, + __buffer, + ); + } + + late final _lcong48_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('lcong48_r'); + late final _lcong48_r = _lcong48_rPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer)>(); + + int arc4random() { + return _arc4random(); + } + + late final _arc4randomPtr = + _lookup>('arc4random'); + late final _arc4random = _arc4randomPtr.asFunction(); + + void arc4random_buf( + ffi.Pointer __buf, + int __size, + ) { + return _arc4random_buf( + __buf, + __size, + ); + } + + late final _arc4random_bufPtr = _lookup< + ffi + .NativeFunction, ffi.Size)>>( + 'arc4random_buf'); + late final _arc4random_buf = _arc4random_bufPtr + .asFunction, int)>(); + + int arc4random_uniform( + int __upper_bound, + ) { + return _arc4random_uniform( + __upper_bound, + ); + } + + late final _arc4random_uniformPtr = + _lookup>( + 'arc4random_uniform'); + late final _arc4random_uniform = + _arc4random_uniformPtr.asFunction(); + + ffi.Pointer malloc( + int __size, + ) { + return _malloc( + __size, + ); + } + + late final _mallocPtr = + _lookup Function(ffi.Size)>>( + 'malloc'); + late final _malloc = + _mallocPtr.asFunction Function(int)>(); + + ffi.Pointer calloc( + int __nmemb, + int __size, + ) { + return _calloc( + __nmemb, + __size, + ); + } + + late final _callocPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Size, ffi.Size)>>('calloc'); + late final _calloc = + _callocPtr.asFunction Function(int, int)>(); + + ffi.Pointer realloc( + ffi.Pointer __ptr, + int __size, + ) { + return _realloc( + __ptr, + __size, + ); + } + + late final _reallocPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Size)>>('realloc'); + late final _realloc = _reallocPtr + .asFunction Function(ffi.Pointer, int)>(); + + void free( + ffi.Pointer __ptr, + ) { + return _free( + __ptr, + ); + } + + late final _freePtr = + _lookup)>>( + 'free'); + late final _free = + _freePtr.asFunction)>(); + + ffi.Pointer reallocarray( + ffi.Pointer __ptr, + int __nmemb, + int __size, + ) { + return _reallocarray( + __ptr, + __nmemb, + __size, + ); + } + + late final _reallocarrayPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Size, ffi.Size)>>('reallocarray'); + late final _reallocarray = _reallocarrayPtr.asFunction< + ffi.Pointer Function(ffi.Pointer, int, int)>(); + + ffi.Pointer alloca( + int __size, + ) { + return _alloca( + __size, + ); + } + + late final _allocaPtr = + _lookup Function(ffi.Size)>>( + 'alloca'); + late final _alloca = + _allocaPtr.asFunction Function(int)>(); + + ffi.Pointer valloc( + int __size, + ) { + return _valloc( + __size, + ); + } + + late final _vallocPtr = + _lookup Function(ffi.Size)>>( + 'valloc'); + late final _valloc = + _vallocPtr.asFunction Function(int)>(); + + int posix_memalign( + ffi.Pointer> __memptr, + int __alignment, + int __size, + ) { + return _posix_memalign( + __memptr, + __alignment, + __size, + ); + } + + late final _posix_memalignPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer>, ffi.Size, + ffi.Size)>>('posix_memalign'); + late final _posix_memalign = _posix_memalignPtr + .asFunction>, int, int)>(); + + ffi.Pointer aligned_alloc( + int __alignment, + int __size, + ) { + return _aligned_alloc( + __alignment, + __size, + ); + } + + late final _aligned_allocPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Size, ffi.Size)>>('aligned_alloc'); + late final _aligned_alloc = + _aligned_allocPtr.asFunction Function(int, int)>(); + + void abort() { + return _abort(); + } + + late final _abortPtr = + _lookup>('abort'); + late final _abort = _abortPtr.asFunction(); + + int atexit( + ffi.Pointer> __func, + ) { + return _atexit( + __func, + ); + } + + late final _atexitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer>)>>('atexit'); + late final _atexit = _atexitPtr.asFunction< + int Function(ffi.Pointer>)>(); + + int at_quick_exit( + ffi.Pointer> __func, + ) { + return _at_quick_exit( + __func, + ); + } + + late final _at_quick_exitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer>)>>( + 'at_quick_exit'); + late final _at_quick_exit = _at_quick_exitPtr.asFunction< + int Function(ffi.Pointer>)>(); + + int on_exit( + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int __status, ffi.Pointer __arg)>> + __func, + ffi.Pointer __arg, + ) { + return _on_exit( + __func, + __arg, + ); + } + + late final _on_exitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int __status, ffi.Pointer __arg)>>, + ffi.Pointer)>>('on_exit'); + late final _on_exit = _on_exitPtr.asFunction< + int Function( + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int __status, ffi.Pointer __arg)>>, + ffi.Pointer)>(); + + void exit( + int __status, + ) { + return _exit( + __status, + ); + } + + late final _exitPtr = + _lookup>('exit'); + late final _exit = _exitPtr.asFunction(); + + void quick_exit( + int __status, + ) { + return _quick_exit( + __status, + ); + } + + late final _quick_exitPtr = + _lookup>('quick_exit'); + late final _quick_exit = _quick_exitPtr.asFunction(); + + void _Exit( + int __status, + ) { + return __Exit( + __status, + ); + } + + late final __ExitPtr = + _lookup>('_Exit'); + late final __Exit = __ExitPtr.asFunction(); + + ffi.Pointer getenv( + ffi.Pointer __name, + ) { + return _getenv( + __name, + ); + } + + late final _getenvPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('getenv'); + late final _getenv = _getenvPtr + .asFunction Function(ffi.Pointer)>(); + + int putenv( + ffi.Pointer __string, + ) { + return _putenv( + __string, + ); + } + + late final _putenvPtr = + _lookup)>>( + 'putenv'); + late final _putenv = + _putenvPtr.asFunction)>(); + + int setenv( + ffi.Pointer __name, + ffi.Pointer __value, + int __replace, + ) { + return _setenv( + __name, + __value, + __replace, + ); + } + + late final _setenvPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Int)>>('setenv'); + late final _setenv = _setenvPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); + + int unsetenv( + ffi.Pointer __name, + ) { + return _unsetenv( + __name, + ); + } + + late final _unsetenvPtr = + _lookup)>>( + 'unsetenv'); + late final _unsetenv = + _unsetenvPtr.asFunction)>(); + + int clearenv() { + return _clearenv(); + } + + late final _clearenvPtr = + _lookup>('clearenv'); + late final _clearenv = _clearenvPtr.asFunction(); + + ffi.Pointer mktemp( + ffi.Pointer __template, + ) { + return _mktemp( + __template, + ); + } + + late final _mktempPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('mktemp'); + late final _mktemp = _mktempPtr + .asFunction Function(ffi.Pointer)>(); + + int mkstemp( + ffi.Pointer __template, + ) { + return _mkstemp( + __template, + ); + } + + late final _mkstempPtr = + _lookup)>>( + 'mkstemp'); + late final _mkstemp = + _mkstempPtr.asFunction)>(); + + int mkstemps( + ffi.Pointer __template, + int __suffixlen, + ) { + return _mkstemps( + __template, + __suffixlen, + ); + } + + late final _mkstempsPtr = _lookup< + ffi.NativeFunction, ffi.Int)>>( + 'mkstemps'); + late final _mkstemps = + _mkstempsPtr.asFunction, int)>(); + + ffi.Pointer mkdtemp( + ffi.Pointer __template, + ) { + return _mkdtemp( + __template, + ); + } + + late final _mkdtempPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('mkdtemp'); + late final _mkdtemp = _mkdtempPtr + .asFunction Function(ffi.Pointer)>(); + + int system( + ffi.Pointer __command, + ) { + return _system( + __command, + ); + } + + late final _systemPtr = + _lookup)>>( + 'system'); + late final _system = + _systemPtr.asFunction)>(); + + ffi.Pointer realpath( + ffi.Pointer __name, + ffi.Pointer __resolved, + ) { + return _realpath( + __name, + __resolved, + ); + } + + late final _realpathPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>>('realpath'); + late final _realpath = _realpathPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer bsearch( + ffi.Pointer __key, + ffi.Pointer __base, + int __nmemb, + int __size, + __compar_fn_t __compar, + ) { + return _bsearch( + __key, + __base, + __nmemb, + __size, + __compar, + ); + } + + late final _bsearchPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Size, + __compar_fn_t)>>('bsearch'); + late final _bsearch = _bsearchPtr.asFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, int, int, __compar_fn_t)>(); + + void qsort( + ffi.Pointer __base, + int __nmemb, + int __size, + __compar_fn_t __compar, + ) { + return _qsort( + __base, + __nmemb, + __size, + __compar, + ); + } + + late final _qsortPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Size, ffi.Size, + __compar_fn_t)>>('qsort'); + late final _qsort = _qsortPtr.asFunction< + void Function(ffi.Pointer, int, int, __compar_fn_t)>(); + + int abs( + int __x, + ) { + return _abs( + __x, + ); + } + + late final _absPtr = + _lookup>('abs'); + late final _abs = _absPtr.asFunction(); + + int labs( + int __x, + ) { + return _labs( + __x, + ); + } + + late final _labsPtr = + _lookup>('labs'); + late final _labs = _labsPtr.asFunction(); + + int llabs( + int __x, + ) { + return _llabs( + __x, + ); + } + + late final _llabsPtr = + _lookup>('llabs'); + late final _llabs = _llabsPtr.asFunction(); + + div_t div( + int __numer, + int __denom, + ) { + return _div( + __numer, + __denom, + ); + } + + late final _divPtr = + _lookup>('div'); + late final _div = _divPtr.asFunction(); + + ldiv_t ldiv( + int __numer, + int __denom, + ) { + return _ldiv( + __numer, + __denom, + ); + } + + late final _ldivPtr = + _lookup>('ldiv'); + late final _ldiv = _ldivPtr.asFunction(); + + lldiv_t lldiv( + int __numer, + int __denom, + ) { + return _lldiv( + __numer, + __denom, + ); + } + + late final _lldivPtr = + _lookup>( + 'lldiv'); + late final _lldiv = _lldivPtr.asFunction(); + + ffi.Pointer ecvt( + double __value, + int __ndigit, + ffi.Pointer __decpt, + ffi.Pointer __sign, + ) { + return _ecvt( + __value, + __ndigit, + __decpt, + __sign, + ); + } + + late final _ecvtPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Double, ffi.Int, + ffi.Pointer, ffi.Pointer)>>('ecvt'); + late final _ecvt = _ecvtPtr.asFunction< + ffi.Pointer Function( + double, int, ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer fcvt( + double __value, + int __ndigit, + ffi.Pointer __decpt, + ffi.Pointer __sign, + ) { + return _fcvt( + __value, + __ndigit, + __decpt, + __sign, + ); + } + + late final _fcvtPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Double, ffi.Int, + ffi.Pointer, ffi.Pointer)>>('fcvt'); + late final _fcvt = _fcvtPtr.asFunction< + ffi.Pointer Function( + double, int, ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer gcvt( + double __value, + int __ndigit, + ffi.Pointer __buf, + ) { + return _gcvt( + __value, + __ndigit, + __buf, + ); + } + + late final _gcvtPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Double, ffi.Int, ffi.Pointer)>>('gcvt'); + late final _gcvt = _gcvtPtr.asFunction< + ffi.Pointer Function(double, int, ffi.Pointer)>(); + + int ecvt_r( + double __value, + int __ndigit, + ffi.Pointer __decpt, + ffi.Pointer __sign, + ffi.Pointer __buf, + int __len, + ) { + return _ecvt_r( + __value, + __ndigit, + __decpt, + __sign, + __buf, + __len, + ); + } + + late final _ecvt_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Double, + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size)>>('ecvt_r'); + late final _ecvt_r = _ecvt_rPtr.asFunction< + int Function(double, int, ffi.Pointer, ffi.Pointer, + ffi.Pointer, int)>(); + + int fcvt_r( + double __value, + int __ndigit, + ffi.Pointer __decpt, + ffi.Pointer __sign, + ffi.Pointer __buf, + int __len, + ) { + return _fcvt_r( + __value, + __ndigit, + __decpt, + __sign, + __buf, + __len, + ); + } + + late final _fcvt_rPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Double, + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size)>>('fcvt_r'); + late final _fcvt_r = _fcvt_rPtr.asFunction< + int Function(double, int, ffi.Pointer, ffi.Pointer, + ffi.Pointer, int)>(); + + int mblen( + ffi.Pointer __s, + int __n, + ) { + return _mblen( + __s, + __n, + ); + } + + late final _mblenPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Size)>>('mblen'); + late final _mblen = + _mblenPtr.asFunction, int)>(); + + int mbtowc( + ffi.Pointer __pwc, + ffi.Pointer __s, + int __n, + ) { + return _mbtowc( + __pwc, + __s, + __n, + ); + } + + late final _mbtowcPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('mbtowc'); + late final _mbtowc = _mbtowcPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); + + int wctomb( + ffi.Pointer __s, + int __wchar, + ) { + return _wctomb( + __s, + __wchar, + ); + } + + late final _wctombPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.WChar)>>('wctomb'); + late final _wctomb = + _wctombPtr.asFunction, int)>(); + + int mbstowcs( + ffi.Pointer __pwcs, + ffi.Pointer __s, + int __n, + ) { + return _mbstowcs( + __pwcs, + __s, + __n, + ); + } + + late final _mbstowcsPtr = _lookup< + ffi.NativeFunction< + ffi.Size Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('mbstowcs'); + late final _mbstowcs = _mbstowcsPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); + + int wcstombs( + ffi.Pointer __s, + ffi.Pointer __pwcs, + int __n, + ) { + return _wcstombs( + __s, + __pwcs, + __n, + ); + } + + late final _wcstombsPtr = _lookup< + ffi.NativeFunction< + ffi.Size Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('wcstombs'); + late final _wcstombs = _wcstombsPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); + + int rpmatch( + ffi.Pointer __response, + ) { + return _rpmatch( + __response, + ); + } + + late final _rpmatchPtr = + _lookup)>>( + 'rpmatch'); + late final _rpmatch = + _rpmatchPtr.asFunction)>(); + + int getsubopt( + ffi.Pointer> __optionp, + ffi.Pointer> __tokens, + ffi.Pointer> __valuep, + ) { + return _getsubopt( + __optionp, + __tokens, + __valuep, + ); + } + + late final _getsuboptPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>>('getsubopt'); + late final _getsubopt = _getsuboptPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>(); + + int getloadavg( + ffi.Pointer __loadavg, + int __nelem, + ) { + return _getloadavg( + __loadavg, + __nelem, + ); + } + + late final _getloadavgPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>>('getloadavg'); + late final _getloadavg = + _getloadavgPtr.asFunction, int)>(); + + /// Returns the current library version + ffi.Pointer pactffi_version() { + return _pactffi_version(); + } + + late final _pactffi_versionPtr = + _lookup Function()>>( + 'pactffi_version'); + late final _pactffi_version = + _pactffi_versionPtr.asFunction Function()>(); + + /// Initialise the mock server library, can provide an environment variable name to use to + /// set the log levels. This function should only be called once, as it tries to install a global + /// tracing subscriber. + /// + /// # Safety + /// + /// log_env_var must be a valid NULL terminated UTF-8 string. + void pactffi_init( + ffi.Pointer log_env_var, + ) { + return _pactffi_init( + log_env_var, + ); + } + + late final _pactffi_initPtr = + _lookup)>>( + 'pactffi_init'); + late final _pactffi_init = + _pactffi_initPtr.asFunction)>(); + + /// Initialises logging, and sets the log level explicitly. This function should only be called + /// once, as it tries to install a global tracing subscriber. + /// + /// * `log_level` - String. One of TRACE, DEBUG, INFO, WARN, ERROR, NONE/OFF. Case-insensitive. Defaults to INFO. + /// + /// # Safety + /// + /// Exported functions are inherently unsafe. + void pactffi_init_with_log_level( + ffi.Pointer level, + ) { + return _pactffi_init_with_log_level( + level, + ); + } + + late final _pactffi_init_with_log_levelPtr = + _lookup)>>( + 'pactffi_init_with_log_level'); + late final _pactffi_init_with_log_level = _pactffi_init_with_log_levelPtr + .asFunction)>(); + + /// Enable ANSI coloured output on Windows. On non-Windows platforms, this function is a no-op. + /// + /// # Safety + /// + /// This function is safe. + void pactffi_enable_ansi_support() { + return _pactffi_enable_ansi_support(); + } + + late final _pactffi_enable_ansi_supportPtr = + _lookup>( + 'pactffi_enable_ansi_support'); + late final _pactffi_enable_ansi_support = + _pactffi_enable_ansi_supportPtr.asFunction(); + + /// Log using the shared core logging facility. + /// + /// This is useful for callers to have a single set of logs. + /// + /// * `source` - String. The source of the log, such as the class or caller framework to + /// disambiguate log lines from the rust logging (e.g. pact_go) + /// * `log_level` - String. One of TRACE, DEBUG, INFO, WARN, ERROR. Case-insensitive. Defaults to INFO. + /// * `message` - Message to log + /// + /// # Safety + /// This function will fail if any of the pointers passed to it are invalid. + void pactffi_log_message( + ffi.Pointer source, + ffi.Pointer log_level, + ffi.Pointer message, + ) { + return _pactffi_log_message( + source, + log_level, + message, + ); + } + + late final _pactffi_log_messagePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('pactffi_log_message'); + late final _pactffi_log_message = _pactffi_log_messagePtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Match a pair of messages, producing a collection of mismatches, + /// which is empty if the two messages matched. + ffi.Pointer pactffi_match_message( + ffi.Pointer msg_1, + ffi.Pointer msg_2, + ) { + return _pactffi_match_message( + msg_1, + msg_2, + ); + } + + late final _pactffi_match_messagePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_match_message'); + late final _pactffi_match_message = _pactffi_match_messagePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Get an iterator over mismatches. + ffi.Pointer pactffi_mismatches_get_iter( + ffi.Pointer mismatches, + ) { + return _pactffi_mismatches_get_iter( + mismatches, + ); + } + + late final _pactffi_mismatches_get_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatches_get_iter'); + late final _pactffi_mismatches_get_iter = + _pactffi_mismatches_get_iterPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Delete mismatches + void pactffi_mismatches_delete( + ffi.Pointer mismatches, + ) { + return _pactffi_mismatches_delete( + mismatches, + ); + } + + late final _pactffi_mismatches_deletePtr = + _lookup)>>( + 'pactffi_mismatches_delete'); + late final _pactffi_mismatches_delete = _pactffi_mismatches_deletePtr + .asFunction)>(); + + /// Get the next mismatch from a mismatches iterator. + /// + /// Returns a null pointer if no mismatches remain. + ffi.Pointer pactffi_mismatches_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_mismatches_iter_next( + iter, + ); + } + + late final _pactffi_mismatches_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_mismatches_iter_next'); + late final _pactffi_mismatches_iter_next = + _pactffi_mismatches_iter_nextPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Delete a mismatches iterator when you're done with it. + void pactffi_mismatches_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_mismatches_iter_delete( + iter, + ); + } + + late final _pactffi_mismatches_iter_deletePtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_mismatches_iter_delete'); + late final _pactffi_mismatches_iter_delete = + _pactffi_mismatches_iter_deletePtr + .asFunction)>(); + + /// Get a JSON representation of the mismatch. + ffi.Pointer pactffi_mismatch_to_json( + ffi.Pointer mismatch, + ) { + return _pactffi_mismatch_to_json( + mismatch, + ); + } + + late final _pactffi_mismatch_to_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatch_to_json'); + late final _pactffi_mismatch_to_json = _pactffi_mismatch_to_jsonPtr + .asFunction Function(ffi.Pointer)>(); + + /// Get the type of a mismatch. + ffi.Pointer pactffi_mismatch_type( + ffi.Pointer mismatch, + ) { + return _pactffi_mismatch_type( + mismatch, + ); + } + + late final _pactffi_mismatch_typePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatch_type'); + late final _pactffi_mismatch_type = _pactffi_mismatch_typePtr + .asFunction Function(ffi.Pointer)>(); + + /// Get a summary of a mismatch. + ffi.Pointer pactffi_mismatch_summary( + ffi.Pointer mismatch, + ) { + return _pactffi_mismatch_summary( + mismatch, + ); + } + + late final _pactffi_mismatch_summaryPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatch_summary'); + late final _pactffi_mismatch_summary = _pactffi_mismatch_summaryPtr + .asFunction Function(ffi.Pointer)>(); + + /// Get a description of a mismatch. + ffi.Pointer pactffi_mismatch_description( + ffi.Pointer mismatch, + ) { + return _pactffi_mismatch_description( + mismatch, + ); + } + + late final _pactffi_mismatch_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatch_description'); + late final _pactffi_mismatch_description = _pactffi_mismatch_descriptionPtr + .asFunction Function(ffi.Pointer)>(); + + /// Get an ANSI-compatible description of a mismatch. + ffi.Pointer pactffi_mismatch_ansi_description( + ffi.Pointer mismatch, + ) { + return _pactffi_mismatch_ansi_description( + mismatch, + ); + } + + late final _pactffi_mismatch_ansi_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_mismatch_ansi_description'); + late final _pactffi_mismatch_ansi_description = + _pactffi_mismatch_ansi_descriptionPtr + .asFunction Function(ffi.Pointer)>(); + + /// Provide the error message from `LAST_ERROR` to the calling C code. + /// + /// This function should be called after any other function in the pact_matching FFI + /// indicates a failure with its own error message, if the caller wants to get more context + /// on why the error happened. + /// + /// Do note that this error-reporting mechanism only reports the top-level error message, + /// not any source information embedded in the original Rust error type. If you want more + /// detailed information for debugging purposes, use the logging interface. + /// + /// # Params + /// + /// * `buffer`: a pointer to an array of `char` of sufficient length to hold the error message. + /// * `length`: an int providing the length of the `buffer`. + /// + /// # Return Codes + /// + /// * The number of bytes written to the provided buffer, which may be zero if there is no last error. + /// * `-1` if the provided buffer is a null pointer. + /// * `-2` if the provided buffer length is too small for the error message. + /// * `-3` if the write failed for some other reason. + /// * `-4` if the error message had an interior NULL + /// + /// # Notes + /// + /// Note that this function zeroes out any excess in the provided buffer. + /// + /// # Error Handling + /// + /// The return code must be checked for one of the negative number error codes before the buffer + /// is used. If an error code is present, the buffer may not be in a usable state. + /// + /// If the buffer is longer than needed for the error message, the excess space will be zeroed + /// as a safety mechanism. This is slightly less efficient than leaving the contents of the buffer + /// alone, but the difference is expected to be negligible in practice. + int pactffi_get_error_message( + ffi.Pointer buffer, + int length, + ) { + return _pactffi_get_error_message( + buffer, + length, + ); + } + + late final _pactffi_get_error_messagePtr = _lookup< + ffi.NativeFunction, ffi.Int)>>( + 'pactffi_get_error_message'); + late final _pactffi_get_error_message = _pactffi_get_error_messagePtr + .asFunction, int)>(); + + /// Convenience function to direct all logging to stdout. + int pactffi_log_to_stdout( + int level_filter, + ) { + return _pactffi_log_to_stdout( + level_filter, + ); + } + + late final _pactffi_log_to_stdoutPtr = + _lookup>( + 'pactffi_log_to_stdout'); + late final _pactffi_log_to_stdout = + _pactffi_log_to_stdoutPtr.asFunction(); + + /// Convenience function to direct all logging to stderr. + int pactffi_log_to_stderr( + int level_filter, + ) { + return _pactffi_log_to_stderr( + level_filter, + ); + } + + late final _pactffi_log_to_stderrPtr = + _lookup>( + 'pactffi_log_to_stderr'); + late final _pactffi_log_to_stderr = + _pactffi_log_to_stderrPtr.asFunction(); + + /// Convenience function to direct all logging to a file. + /// + /// # Safety + /// This function will fail if the file_name pointer is invalid or does not point to a NULL + /// terminated string. + int pactffi_log_to_file( + ffi.Pointer file_name, + int level_filter, + ) { + return _pactffi_log_to_file( + file_name, + level_filter, + ); + } + + late final _pactffi_log_to_filePtr = _lookup< + ffi + .NativeFunction, ffi.Int32)>>( + 'pactffi_log_to_file'); + late final _pactffi_log_to_file = _pactffi_log_to_filePtr + .asFunction, int)>(); + + /// Convenience function to direct all logging to a task local memory buffer. + int pactffi_log_to_buffer( + int level_filter, + ) { + return _pactffi_log_to_buffer( + level_filter, + ); + } + + late final _pactffi_log_to_bufferPtr = + _lookup>( + 'pactffi_log_to_buffer'); + late final _pactffi_log_to_buffer = + _pactffi_log_to_bufferPtr.asFunction(); + + /// Initialize the FFI logger with no sinks. + /// + /// This initialized logger does nothing until `pactffi_logger_apply` has been called. + /// + /// # Usage + /// + /// ```c + /// pactffi_logger_init(); + /// ``` + /// + /// # Safety + /// + /// This function is always safe to call. + void pactffi_logger_init() { + return _pactffi_logger_init(); + } + + late final _pactffi_logger_initPtr = + _lookup>('pactffi_logger_init'); + late final _pactffi_logger_init = + _pactffi_logger_initPtr.asFunction(); + + /// Attach an additional sink to the thread-local logger. + /// + /// This logger does nothing until `pactffi_logger_apply` has been called. + /// + /// Types of sinks can be specified: + /// + /// - stdout (`pactffi_logger_attach_sink("stdout", LevelFilter_Info)`) + /// - stderr (`pactffi_logger_attach_sink("stderr", LevelFilter_Debug)`) + /// - file w/ file path (`pactffi_logger_attach_sink("file /some/file/path", LevelFilter_Trace)`) + /// - buffer (`pactffi_logger_attach_sink("buffer", LevelFilter_Debug)`) + /// + /// # Usage + /// + /// ```c + /// int result = pactffi_logger_attach_sink("file /some/file/path", LogLevel_Filter); + /// ``` + /// + /// # Error Handling + /// + /// The return error codes are as follows: + /// + /// - `-1`: Can't set logger (applying the logger failed, perhaps because one is applied already). + /// - `-2`: No logger has been initialized (call `pactffi_logger_init` before any other log function). + /// - `-3`: The sink specifier was not UTF-8 encoded. + /// - `-4`: The sink type specified is not a known type (known types: "stdout", "stderr", "buffer", or "file /some/path"). + /// - `-5`: No file path was specified in a file-type sink specification. + /// - `-6`: Opening a sink to the specified file path failed (check permissions). + /// + /// # Safety + /// + /// This function checks the validity of the passed-in sink specifier, and errors + /// out if the specifier isn't valid UTF-8. Passing in an invalid or NULL pointer will result in + /// undefined behaviour. + int pactffi_logger_attach_sink( + ffi.Pointer sink_specifier, + int level_filter, + ) { + return _pactffi_logger_attach_sink( + sink_specifier, + level_filter, + ); + } + + late final _pactffi_logger_attach_sinkPtr = _lookup< + ffi + .NativeFunction, ffi.Int32)>>( + 'pactffi_logger_attach_sink'); + late final _pactffi_logger_attach_sink = _pactffi_logger_attach_sinkPtr + .asFunction, int)>(); + + /// Apply the previously configured sinks and levels to the program. If no sinks have been setup, + /// will set the log level to info and the target to standard out. + /// + /// This function will install a global tracing subscriber. Any attempts to modify the logger + /// after the call to `logger_apply` will fail. + /// + /// # Error Handling + /// + /// The return error codes are as follows: + /// + /// - `-1`: Can't set logger (applying the logger failed, perhaps because one is applied already). + int pactffi_logger_apply() { + return _pactffi_logger_apply(); + } + + late final _pactffi_logger_applyPtr = + _lookup>('pactffi_logger_apply'); + late final _pactffi_logger_apply = + _pactffi_logger_applyPtr.asFunction(); + + /// Fetch the in-memory logger buffer contents. This will only have any contents if the `buffer` + /// sink has been configured to log to. The contents will be allocated on the heap and will need + /// to be freed with `pactffi_string_delete`. + /// + /// Fetches the logs associated with the provided identifier, or uses the "global" one if the + /// identifier is not specified (i.e. NULL). + /// + /// Returns a NULL pointer if the buffer can't be fetched. This can occur is there is not + /// sufficient memory to make a copy of the contents or the buffer contains non-UTF-8 characters. + /// + /// # Safety + /// + /// This function will fail if the log_id pointer is invalid or does not point to a NULL + /// terminated string. + ffi.Pointer pactffi_fetch_log_buffer( + ffi.Pointer log_id, + ) { + return _pactffi_fetch_log_buffer( + log_id, + ); + } + + late final _pactffi_fetch_log_bufferPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_fetch_log_buffer'); + late final _pactffi_fetch_log_buffer = _pactffi_fetch_log_bufferPtr + .asFunction Function(ffi.Pointer)>(); + + /// Parses the provided JSON into a Pact model. The returned Pact model must be freed with the + /// `pactffi_pact_model_delete` function when no longer needed. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_parse_pact_json( + ffi.Pointer json, + ) { + return _pactffi_parse_pact_json( + json, + ); + } + + late final _pactffi_parse_pact_jsonPtr = _lookup< + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'pactffi_parse_pact_json'); + late final _pactffi_parse_pact_json = _pactffi_parse_pact_jsonPtr + .asFunction Function(ffi.Pointer)>(); + + /// Frees the memory used by the Pact model + void pactffi_pact_model_delete( + ffi.Pointer pact, + ) { + return _pactffi_pact_model_delete( + pact, + ); + } + + late final _pactffi_pact_model_deletePtr = + _lookup)>>( + 'pactffi_pact_model_delete'); + late final _pactffi_pact_model_delete = _pactffi_pact_model_deletePtr + .asFunction)>(); + + /// Returns an iterator over all the interactions in the Pact. The iterator will have to be + /// deleted using the `pactffi_pact_interaction_iter_delete` function. The iterator will + /// contain a copy of the interactions, so it will not be affected but mutations to the Pact + /// model and will still function if the Pact model is deleted. + /// + /// # Safety + /// This function is safe as long as the Pact pointer is a valid pointer. + /// + /// # Errors + /// On any error, this function will return a NULL pointer. + ffi.Pointer pactffi_pact_model_interaction_iterator( + ffi.Pointer pact, + ) { + return _pactffi_pact_model_interaction_iterator( + pact, + ); + } + + late final _pactffi_pact_model_interaction_iteratorPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_pact_model_interaction_iterator'); + late final _pactffi_pact_model_interaction_iterator = + _pactffi_pact_model_interaction_iteratorPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Returns the Pact specification enum that the Pact is for. + int pactffi_pact_spec_version( + ffi.Pointer pact, + ) { + return _pactffi_pact_spec_version( + pact, + ); + } + + late final _pactffi_pact_spec_versionPtr = + _lookup)>>( + 'pactffi_pact_spec_version'); + late final _pactffi_pact_spec_version = _pactffi_pact_spec_versionPtr + .asFunction)>(); + + /// Frees the memory used by the Pact interaction model + void pactffi_pact_interaction_delete( + ffi.Pointer interaction, + ) { + return _pactffi_pact_interaction_delete( + interaction, + ); + } + + late final _pactffi_pact_interaction_deletePtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_pact_interaction_delete'); + late final _pactffi_pact_interaction_delete = + _pactffi_pact_interaction_deletePtr + .asFunction)>(); + + /// Get a mutable pointer to a newly-created default message on the heap. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_async_message_new() { + return _pactffi_async_message_new(); + } + + late final _pactffi_async_message_newPtr = + _lookup Function()>>( + 'pactffi_async_message_new'); + late final _pactffi_async_message_new = _pactffi_async_message_newPtr + .asFunction Function()>(); + + /// Destroy the `AsynchronousMessage` being pointed to. + void pactffi_async_message_delete( + ffi.Pointer message, + ) { + return _pactffi_async_message_delete( + message, + ); + } + + late final _pactffi_async_message_deletePtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_async_message_delete'); + late final _pactffi_async_message_delete = _pactffi_async_message_deletePtr + .asFunction)>(); + + /// Get the message contents of an `AsynchronousMessage` as a `MessageContents` pointer. + /// + /// # Safety + /// + /// The data pointed to by the pointer this function returns will be deleted when the message + /// is deleted. Trying to use if after the message is deleted will result in undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. + ffi.Pointer pactffi_async_message_get_contents( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_contents( + message, + ); + } + + late final _pactffi_async_message_get_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_get_contents'); + late final _pactffi_async_message_get_contents = + _pactffi_async_message_get_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Generate the message contents of an `AsynchronousMessage` as a + /// `MessageContents` pointer. + /// + /// This function differs from [`pactffi_async_message_get_contents`] in + /// that it will process the message contents for any generators or matchers + /// that are present in the message in order to generate the actual message + /// contents as would be received by the consumer. + /// + /// # Safety + /// + /// The data pointed to by the pointer must be deleted with + /// [`pactffi_message_contents_delete`][crate::models::contents::pactffi_message_contents_delete] + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. + ffi.Pointer pactffi_async_message_generate_contents( + ffi.Pointer message, + ) { + return _pactffi_async_message_generate_contents( + message, + ); + } + + late final _pactffi_async_message_generate_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_generate_contents'); + late final _pactffi_async_message_generate_contents = + _pactffi_async_message_generate_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the message contents of an `AsynchronousMessage` in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the message. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. This means there's + /// no mechanism to differentiate with this function call alone between + /// a NULL message and a missing message body. + ffi.Pointer pactffi_async_message_get_contents_str( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_contents_str( + message, + ); + } + + late final _pactffi_async_message_get_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_get_contents_str'); + late final _pactffi_async_message_get_contents_str = + _pactffi_async_message_get_contents_strPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the contents of the message as a string. + /// + /// * `message` - the message to set the contents for + /// * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The message contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_async_message_set_contents_str( + ffi.Pointer message, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_async_message_set_contents_str( + message, + contents, + content_type, + ); + } + + late final _pactffi_async_message_set_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_async_message_set_contents_str'); + late final _pactffi_async_message_set_contents_str = + _pactffi_async_message_set_contents_strPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the contents of a `AsynchronousMessage`. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the message is NULL, returns 0. If the body of the request + /// is missing, then this function also returns 0. + int pactffi_async_message_get_contents_length( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_contents_length( + message, + ); + } + + late final _pactffi_async_message_get_contents_lengthPtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_async_message_get_contents_length'); + late final _pactffi_async_message_get_contents_length = + _pactffi_async_message_get_contents_lengthPtr + .asFunction)>(); + + /// Get the contents of an `AsynchronousMessage` as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_async_message_get_contents_length`. + /// It is safe to use the pointer while the message is not deleted or changed. Using the pointer + /// after the message is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_async_message_get_contents_bin( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_contents_bin( + message, + ); + } + + late final _pactffi_async_message_get_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_get_contents_bin'); + late final _pactffi_async_message_get_contents_bin = + _pactffi_async_message_get_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Sets the contents of the message as an array of bytes. + /// + /// * `message` - the message to set the contents for + /// * `contents` - pointer to contents to copy from + /// * `len` - number of bytes to copy from the contents pointer + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_async_message_set_contents_bin( + ffi.Pointer message, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_async_message_set_contents_bin( + message, + contents, + len, + content_type, + ); + } + + late final _pactffi_async_message_set_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_async_message_set_contents_bin'); + late final _pactffi_async_message_set_contents_bin = + _pactffi_async_message_set_contents_binPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get a copy of the description. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// Since it is a copy, the returned string may safely outlive the `AsynchronousMessage`. + /// + /// # Errors + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the Rust string contains embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_async_message_get_description( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_description( + message, + ); + } + + late final _pactffi_async_message_get_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_get_description'); + late final _pactffi_async_message_get_description = + _pactffi_async_message_get_descriptionPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Write the `description` field on the `AsynchronousMessage`. + /// + /// # Safety + /// + /// `description` must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + /// + /// This function will only reallocate if the new string + /// does not fit in the existing buffer. + /// + /// # Error Handling + /// + /// Errors will be reported with a non-zero return value. + int pactffi_async_message_set_description( + ffi.Pointer message, + ffi.Pointer description, + ) { + return _pactffi_async_message_set_description( + message, + description, + ); + } + + late final _pactffi_async_message_set_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_async_message_set_description'); + late final _pactffi_async_message_set_description = + _pactffi_async_message_set_descriptionPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Get a copy of the provider state at the given index from this message. + /// + /// # Safety + /// + /// The returned structure must be deleted with `provider_state_delete`. + /// + /// Since it is a copy, the returned structure may safely outlive the `AsynchronousMessage`. + /// + /// # Error Handling + /// + /// On failure, this function will return a variant other than Success. + /// + /// This function may fail if the index requested is out of bounds, + /// or if any of the Rust strings contain embedded null ('\0') bytes. + ffi.Pointer pactffi_async_message_get_provider_state( + ffi.Pointer message, + int index, + ) { + return _pactffi_async_message_get_provider_state( + message, + index, + ); + } + + late final _pactffi_async_message_get_provider_statePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.UnsignedInt)>>('pactffi_async_message_get_provider_state'); + late final _pactffi_async_message_get_provider_state = + _pactffi_async_message_get_provider_statePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over provider states. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// + /// # Error Handling + /// + /// Returns NULL if an error occurs. + ffi.Pointer + pactffi_async_message_get_provider_state_iter( + ffi.Pointer message, + ) { + return _pactffi_async_message_get_provider_state_iter( + message, + ); + } + + late final _pactffi_async_message_get_provider_state_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_async_message_get_provider_state_iter'); + late final _pactffi_async_message_get_provider_state_iter = + _pactffi_async_message_get_provider_state_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get a copy of this consumer's name. + /// + /// The copy must be deleted with `pactffi_string_delete`. + /// + /// # Usage + /// + /// ```c + /// // Assuming `file_name` and `json_str` are already defined. + /// + /// MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str); + /// if (message_pact == NULLPTR) { + /// // handle error. + /// } + /// + /// Consumer *consumer = pactffi_message_pact_get_consumer(message_pact); + /// if (consumer == NULLPTR) { + /// // handle error. + /// } + /// + /// char *name = pactffi_consumer_get_name(consumer); + /// if (name == NULL) { + /// // handle error. + /// } + /// + /// printf("%s\n", name); + /// + /// pactffi_string_delete(name); + /// ``` + /// + /// # Errors + /// + /// This function will fail if it is passed a NULL pointer, + /// or the Rust string contains an embedded NULL byte. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_consumer_get_name( + ffi.Pointer consumer, + ) { + return _pactffi_consumer_get_name( + consumer, + ); + } + + late final _pactffi_consumer_get_namePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_consumer_get_name'); + late final _pactffi_consumer_get_name = _pactffi_consumer_get_namePtr + .asFunction Function(ffi.Pointer)>(); + + /// Get the consumer from a Pact. This returns a copy of the consumer model, and needs to + /// be cleaned up with `pactffi_pact_consumer_delete` when no longer required. + /// + /// # Errors + /// + /// This function will fail if it is passed a NULL pointer. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_pact_get_consumer( + ffi.Pointer pact, + ) { + return _pactffi_pact_get_consumer( + pact, + ); + } + + late final _pactffi_pact_get_consumerPtr = _lookup< + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'pactffi_pact_get_consumer'); + late final _pactffi_pact_get_consumer = _pactffi_pact_get_consumerPtr + .asFunction Function(ffi.Pointer)>(); + + /// Frees the memory used by the Pact consumer + void pactffi_pact_consumer_delete( + ffi.Pointer consumer, + ) { + return _pactffi_pact_consumer_delete( + consumer, + ); + } + + late final _pactffi_pact_consumer_deletePtr = + _lookup)>>( + 'pactffi_pact_consumer_delete'); + late final _pactffi_pact_consumer_delete = _pactffi_pact_consumer_deletePtr + .asFunction)>(); + + /// Delete the message contents instance. + /// + /// # Safety + /// + /// This should only be called on a message contents that require deletion. + /// The function creating the message contents should document whether it + /// requires deletion. + /// + /// Deleting a message content which is associated with an interaction + /// will result in undefined behaviour. + void pactffi_message_contents_delete( + ffi.Pointer contents, + ) { + return _pactffi_message_contents_delete( + contents, + ); + } + + late final _pactffi_message_contents_deletePtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_message_contents_delete'); + late final _pactffi_message_contents_delete = + _pactffi_message_contents_deletePtr + .asFunction)>(); + + /// Get the message contents in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the message. + /// + /// # Error Handling + /// + /// If the message contents is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. This means there's + /// no mechanism to differentiate with this function call alone between + /// a NULL message and a missing message body. + ffi.Pointer pactffi_message_contents_get_contents_str( + ffi.Pointer contents, + ) { + return _pactffi_message_contents_get_contents_str( + contents, + ); + } + + late final _pactffi_message_contents_get_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_message_contents_get_contents_str'); + late final _pactffi_message_contents_get_contents_str = + _pactffi_message_contents_get_contents_strPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the contents of the message as a string. + /// + /// * `contents` - the message contents to set the contents for + /// * `contents_str` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The message contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents string is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_message_contents_set_contents_str( + ffi.Pointer contents, + ffi.Pointer contents_str, + ffi.Pointer content_type, + ) { + return _pactffi_message_contents_set_contents_str( + contents, + contents_str, + content_type, + ); + } + + late final _pactffi_message_contents_set_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_message_contents_set_contents_str'); + late final _pactffi_message_contents_set_contents_str = + _pactffi_message_contents_set_contents_strPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the message contents. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the message is NULL, returns 0. If the body of the message + /// is missing, then this function also returns 0. + int pactffi_message_contents_get_contents_length( + ffi.Pointer contents, + ) { + return _pactffi_message_contents_get_contents_length( + contents, + ); + } + + late final _pactffi_message_contents_get_contents_lengthPtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_message_contents_get_contents_length'); + late final _pactffi_message_contents_get_contents_length = + _pactffi_message_contents_get_contents_lengthPtr + .asFunction)>(); + + /// Get the contents of a message as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_message_contents_get_contents_length`. + /// It is safe to use the pointer while the message is not deleted or changed. Using the pointer + /// after the message is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_message_contents_get_contents_bin( + ffi.Pointer contents, + ) { + return _pactffi_message_contents_get_contents_bin( + contents, + ); + } + + late final _pactffi_message_contents_get_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_contents_get_contents_bin'); + late final _pactffi_message_contents_get_contents_bin = + _pactffi_message_contents_get_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Sets the contents of the message as an array of bytes. + /// + /// * `message` - the message contents to set the contents for + /// * `contents_bin` - pointer to contents to copy from + /// * `len` - number of bytes to copy from the contents pointer + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_message_contents_set_contents_bin( + ffi.Pointer contents, + ffi.Pointer contents_bin, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_message_contents_set_contents_bin( + contents, + contents_bin, + len, + content_type, + ); + } + + late final _pactffi_message_contents_set_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_message_contents_set_contents_bin'); + late final _pactffi_message_contents_set_contents_bin = + _pactffi_message_contents_set_contents_binPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get an iterator over the metadata of a message. + /// + /// The returned pointer must be deleted with `pactffi_message_metadata_iter_delete` when done + /// with it. + /// + /// # Safety + /// + /// This iterator carries a pointer to the message contents, and must + /// not outlive the message. + /// + /// The message metadata also must not be modified during iteration. If it is, + /// the old iterator must be deleted and a new iterator created. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain + /// embedded null ('\0') bytes. + ffi.Pointer + pactffi_message_contents_get_metadata_iter( + ffi.Pointer contents, + ) { + return _pactffi_message_contents_get_metadata_iter( + contents, + ); + } + + late final _pactffi_message_contents_get_metadata_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_contents_get_metadata_iter'); + late final _pactffi_message_contents_get_metadata_iter = + _pactffi_message_contents_get_metadata_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get an iterator over the matching rules for a category of a message. + /// + /// The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done + /// with it. + /// + /// Note that there could be multiple matching rules for the same key, so this iterator will + /// sequentially return each rule with the same key. + /// + /// For sample, given the following rules: + /// "$.a" => Type, + /// "$.b" => Regex("\\d+"), Number + /// + /// This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number) + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the message or message + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_message_contents_get_matching_rule_iter( + ffi.Pointer contents, + int category, + ) { + return _pactffi_message_contents_get_matching_rule_iter( + contents, + category, + ); + } + + late final _pactffi_message_contents_get_matching_rule_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_message_contents_get_matching_rule_iter'); + late final _pactffi_message_contents_get_matching_rule_iter = + _pactffi_message_contents_get_matching_rule_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over the matching rules for a category of an HTTP request. + /// + /// The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done + /// with it. + /// + /// For sample, given the following rules: + /// "$.a" => Type, + /// "$.b" => Regex("\\d+"), Number + /// + /// This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number) + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the interaction or request + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_request_contents_get_matching_rule_iter( + ffi.Pointer request, + int category, + ) { + return _pactffi_request_contents_get_matching_rule_iter( + request, + category, + ); + } + + late final _pactffi_request_contents_get_matching_rule_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_request_contents_get_matching_rule_iter'); + late final _pactffi_request_contents_get_matching_rule_iter = + _pactffi_request_contents_get_matching_rule_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over the matching rules for a category of an HTTP response. + /// + /// The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done + /// with it. + /// + /// For sample, given the following rules: + /// "$.a" => Type, + /// "$.b" => Regex("\\d+"), Number + /// + /// This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number) + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the interaction or response + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_response_contents_get_matching_rule_iter( + ffi.Pointer response, + int category, + ) { + return _pactffi_response_contents_get_matching_rule_iter( + response, + category, + ); + } + + late final _pactffi_response_contents_get_matching_rule_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_response_contents_get_matching_rule_iter'); + late final _pactffi_response_contents_get_matching_rule_iter = + _pactffi_response_contents_get_matching_rule_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over the generators for a category of a message. + /// + /// The returned pointer must be deleted with `pactffi_generators_iter_delete` when done + /// with it. + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the message or message + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_message_contents_get_generators_iter( + ffi.Pointer contents, + int category, + ) { + return _pactffi_message_contents_get_generators_iter( + contents, + category, + ); + } + + late final _pactffi_message_contents_get_generators_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_message_contents_get_generators_iter'); + late final _pactffi_message_contents_get_generators_iter = + _pactffi_message_contents_get_generators_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over the generators for a category of an HTTP request. + /// + /// The returned pointer must be deleted with `pactffi_generators_iter_delete` when done + /// with it. + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the interaction or request + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_request_contents_get_generators_iter( + ffi.Pointer request, + int category, + ) { + return _pactffi_request_contents_get_generators_iter( + request, + category, + ); + } + + late final _pactffi_request_contents_get_generators_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_request_contents_get_generators_iter'); + late final _pactffi_request_contents_get_generators_iter = + _pactffi_request_contents_get_generators_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over the generators for a category of an HTTP response. + /// + /// The returned pointer must be deleted with `pactffi_generators_iter_delete` when done + /// with it. + /// + /// # Safety + /// + /// The iterator contains a copy of the data, so is safe to use when the interaction or response + /// contents has been deleted. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + ffi.Pointer + pactffi_response_contents_get_generators_iter( + ffi.Pointer response, + int category, + ) { + return _pactffi_response_contents_get_generators_iter( + response, + category, + ); + } + + late final _pactffi_response_contents_get_generators_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Int32)>>('pactffi_response_contents_get_generators_iter'); + late final _pactffi_response_contents_get_generators_iter = + _pactffi_response_contents_get_generators_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Parse a matcher definition string into a MatchingRuleDefinition containing the example value, + /// and matching rules and any generator. + /// + /// The following are examples of matching rule definitions: + /// * `matching(type,'Name')` - type matcher with string value 'Name' + /// * `matching(number,100)` - number matcher + /// * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string + /// + /// See [Matching Rule definition expressions](https://docs.rs/pact_models/latest/pact_models/matchingrules/expressions/index.html). + /// + /// The returned value needs to be freed up with the `pactffi_matcher_definition_delete` function. + /// + /// # Errors + /// If the expression is invalid, the MatchingRuleDefinition error will be set. You can check for + /// this value with the `pactffi_matcher_definition_error` function. + /// + /// # Safety + /// + /// This function is safe if the expression is a valid NULL terminated string pointer. + ffi.Pointer pactffi_parse_matcher_definition( + ffi.Pointer expression, + ) { + return _pactffi_parse_matcher_definition( + expression, + ); + } + + late final _pactffi_parse_matcher_definitionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_parse_matcher_definition'); + late final _pactffi_parse_matcher_definition = + _pactffi_parse_matcher_definitionPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Returns any error message from parsing a matching definition expression. If there is no error, + /// it will return a NULL pointer, otherwise returns the error message as a NULL-terminated string. + /// The returned string must be freed using the `pactffi_string_delete` function once done with it. + ffi.Pointer pactffi_matcher_definition_error( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_error( + definition, + ); + } + + late final _pactffi_matcher_definition_errorPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matcher_definition_error'); + late final _pactffi_matcher_definition_error = + _pactffi_matcher_definition_errorPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Returns the value from parsing a matching definition expression. If there was an error, + /// it will return a NULL pointer, otherwise returns the value as a NULL-terminated string. + /// The returned string must be freed using the `pactffi_string_delete` function once done with it. + /// + /// Note that different expressions values can have types other than a string. Use + /// `pactffi_matcher_definition_value_type` to get the actual type of the value. This function + /// will always return the string representation of the value. + ffi.Pointer pactffi_matcher_definition_value( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_value( + definition, + ); + } + + late final _pactffi_matcher_definition_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matcher_definition_value'); + late final _pactffi_matcher_definition_value = + _pactffi_matcher_definition_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Frees the memory used by the result of parsing the matching definition expression + void pactffi_matcher_definition_delete( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_delete( + definition, + ); + } + + late final _pactffi_matcher_definition_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_matcher_definition_delete'); + late final _pactffi_matcher_definition_delete = + _pactffi_matcher_definition_deletePtr.asFunction< + void Function(ffi.Pointer)>(); + + /// Returns the generator from parsing a matching definition expression. If there was an error or + /// there is no associated generator, it will return a NULL pointer, otherwise returns the generator + /// as a pointer. + /// + /// The generator pointer will be a valid pointer as long as `pactffi_matcher_definition_delete` + /// has not been called on the definition. Using the generator pointer after the definition + /// has been deleted will result in undefined behaviour. + ffi.Pointer pactffi_matcher_definition_generator( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_generator( + definition, + ); + } + + late final _pactffi_matcher_definition_generatorPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matcher_definition_generator'); + late final _pactffi_matcher_definition_generator = + _pactffi_matcher_definition_generatorPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Returns the type of the value from parsing a matching definition expression. If there was an + /// error parsing the expression, it will return Unknown. + int pactffi_matcher_definition_value_type( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_value_type( + definition, + ); + } + + late final _pactffi_matcher_definition_value_typePtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(ffi.Pointer)>>( + 'pactffi_matcher_definition_value_type'); + late final _pactffi_matcher_definition_value_type = + _pactffi_matcher_definition_value_typePtr.asFunction< + int Function(ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_matching_rule_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_matching_rule_iter_delete( + iter, + ); + } + + late final _pactffi_matching_rule_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_matching_rule_iter_delete'); + late final _pactffi_matching_rule_iter_delete = + _pactffi_matching_rule_iter_deletePtr + .asFunction)>(); + + /// Returns an iterator over the matching rules from the parsed definition. The iterator needs to + /// be deleted with the `pactffi_matching_rule_iter_delete` function once done with it. + /// + /// If there was an error parsing the expression, this function will return a NULL pointer. + ffi.Pointer pactffi_matcher_definition_iter( + ffi.Pointer definition, + ) { + return _pactffi_matcher_definition_iter( + definition, + ); + } + + late final _pactffi_matcher_definition_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matcher_definition_iter'); + late final _pactffi_matcher_definition_iter = + _pactffi_matcher_definition_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the next matching rule or reference from the iterator. As the values returned are owned + /// by the iterator, they do not need to be deleted but will be cleaned up when the iterator is + /// deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_matching_rule_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_matching_rule_iter_next( + iter, + ); + } + + late final _pactffi_matching_rule_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matching_rule_iter_next'); + late final _pactffi_matching_rule_iter_next = + _pactffi_matching_rule_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Return the ID of the matching rule. + /// + /// The ID corresponds to the following rules: + /// | Rule | ID | + /// | ---- | -- | + /// | Equality | 1 | + /// | Regex | 2 | + /// | Type | 3 | + /// | MinType | 4 | + /// | MaxType | 5 | + /// | MinMaxType | 6 | + /// | Timestamp | 7 | + /// | Time | 8 | + /// | Date | 9 | + /// | Include | 10 | + /// | Number | 11 | + /// | Integer | 12 | + /// | Decimal | 13 | + /// | Null | 14 | + /// | ContentType | 15 | + /// | ArrayContains | 16 | + /// | Values | 17 | + /// | Boolean | 18 | + /// | StatusCode | 19 | + /// | NotEmpty | 20 | + /// | Semver | 21 | + /// | EachKey | 22 | + /// | EachValue | 23 | + /// + /// # Safety + /// + /// This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the + /// iterator has not been deleted. + int pactffi_matching_rule_id( + ffi.Pointer rule_result, + ) { + return _pactffi_matching_rule_id( + rule_result, + ); + } + + late final _pactffi_matching_rule_idPtr = _lookup< + ffi.NativeFunction< + ffi.Uint16 Function( + ffi.Pointer)>>('pactffi_matching_rule_id'); + late final _pactffi_matching_rule_id = _pactffi_matching_rule_idPtr + .asFunction)>(); + + /// Returns the associated value for the matching rule. If the matching rule does not have an + /// associated value, will return a NULL pointer. + /// + /// The associated values for the rules are: + /// | Rule | ID | VALUE | + /// | ---- | -- | ----- | + /// | Equality | 1 | NULL | + /// | Regex | 2 | Regex value | + /// | Type | 3 | NULL | + /// | MinType | 4 | Minimum value | + /// | MaxType | 5 | Maximum value | + /// | MinMaxType | 6 | "min:max" | + /// | Timestamp | 7 | Format string | + /// | Time | 8 | Format string | + /// | Date | 9 | Format string | + /// | Include | 10 | String value | + /// | Number | 11 | NULL | + /// | Integer | 12 | NULL | + /// | Decimal | 13 | NULL | + /// | Null | 14 | NULL | + /// | ContentType | 15 | Content type | + /// | ArrayContains | 16 | NULL | + /// | Values | 17 | NULL | + /// | Boolean | 18 | NULL | + /// | StatusCode | 19 | NULL | + /// | NotEmpty | 20 | NULL | + /// | Semver | 21 | NULL | + /// | EachKey | 22 | NULL | + /// | EachValue | 23 | NULL | + /// + /// Will return a NULL pointer if the matching rule was a reference or does not have an + /// associated value. + /// + /// # Safety + /// + /// This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the + /// iterator it came from has not been deleted. + ffi.Pointer pactffi_matching_rule_value( + ffi.Pointer rule_result, + ) { + return _pactffi_matching_rule_value( + rule_result, + ); + } + + late final _pactffi_matching_rule_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_matching_rule_value'); + late final _pactffi_matching_rule_value = + _pactffi_matching_rule_valuePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Returns the matching rule pointer for the matching rule. Will return a NULL pointer if the + /// matching rule result was a reference. + /// + /// # Safety + /// + /// This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the + /// iterator it came from has not been deleted. + ffi.Pointer pactffi_matching_rule_pointer( + ffi.Pointer rule_result, + ) { + return _pactffi_matching_rule_pointer( + rule_result, + ); + } + + late final _pactffi_matching_rule_pointerPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matching_rule_pointer'); + late final _pactffi_matching_rule_pointer = + _pactffi_matching_rule_pointerPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Return any matching rule reference to a attribute by name. This is when the matcher should + /// be configured to match the type of a structure. I.e., + /// + /// ```json + /// { + /// "pact:match": "eachValue(matching($'person'))", + /// "person": { + /// "name": "Fred", + /// "age": 100 + /// } + /// } + /// ``` + /// + /// Will return a NULL pointer if the matching rule was not a reference. + /// + /// # Safety + /// + /// This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the + /// iterator has not been deleted. + ffi.Pointer pactffi_matching_rule_reference_name( + ffi.Pointer rule_result, + ) { + return _pactffi_matching_rule_reference_name( + rule_result, + ); + } + + late final _pactffi_matching_rule_reference_namePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_matching_rule_reference_name'); + late final _pactffi_matching_rule_reference_name = + _pactffi_matching_rule_reference_namePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Validates the date/time value against the date/time format string. If the value is valid, + /// this function will return a zero status code (EXIT_SUCCESS). + /// If the value is not valid, will return a value of 1 (EXIT_FAILURE) and set the + /// error message which can be retrieved with `pactffi_get_error_message`. + /// + /// # Errors + /// If the function receives a panic, it will return 2 and the message associated with the + /// panic can be retrieved with `pactffi_get_error_message`. + /// + /// # Safety + /// + /// This function is safe as long as the value and format parameters point to valid + /// NULL-terminated strings. + int pactffi_validate_datetime( + ffi.Pointer value, + ffi.Pointer format, + ) { + return _pactffi_validate_datetime( + value, + format, + ); + } + + late final _pactffi_validate_datetimePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_validate_datetime'); + late final _pactffi_validate_datetime = _pactffi_validate_datetimePtr + .asFunction, ffi.Pointer)>(); + + /// Get the JSON form of the generator. + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// # Safety + /// + /// This function will fail if it is passed a NULL pointer, or the owner of the generator has + /// been deleted. + ffi.Pointer pactffi_generator_to_json( + ffi.Pointer generator, + ) { + return _pactffi_generator_to_json( + generator, + ); + } + + late final _pactffi_generator_to_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_generator_to_json'); + late final _pactffi_generator_to_json = _pactffi_generator_to_jsonPtr + .asFunction Function(ffi.Pointer)>(); + + /// Generate a string value using the provided generator and an optional JSON payload containing + /// any generator context. The context value is used for generators like `MockServerURL` (which + /// should contain details about the running mock server) and `ProviderStateGenerator` (which + /// should be the values returned from the Provider State callback function). + /// + /// If anything goes wrong, it will return a NULL pointer. + ffi.Pointer pactffi_generator_generate_string( + ffi.Pointer generator, + ffi.Pointer context_json, + ) { + return _pactffi_generator_generate_string( + generator, + context_json, + ); + } + + late final _pactffi_generator_generate_stringPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_generator_generate_string'); + late final _pactffi_generator_generate_string = + _pactffi_generator_generate_stringPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Generate an integer value using the provided generator and an optional JSON payload containing + /// any generator context. The context value is used for generators like `ProviderStateGenerator` + /// (which should be the values returned from the Provider State callback function). + /// + /// If anything goes wrong or the generator is not a type that can generate an integer value, it + /// will return a zero value. + int pactffi_generator_generate_integer( + ffi.Pointer generator, + ffi.Pointer context_json, + ) { + return _pactffi_generator_generate_integer( + generator, + context_json, + ); + } + + late final _pactffi_generator_generate_integerPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedShort Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_generator_generate_integer'); + late final _pactffi_generator_generate_integer = + _pactffi_generator_generate_integerPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_generators_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_generators_iter_delete( + iter, + ); + } + + late final _pactffi_generators_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_generators_iter_delete'); + late final _pactffi_generators_iter_delete = + _pactffi_generators_iter_deletePtr + .asFunction)>(); + + /// Get the next path and generator out of the iterator, if possible. + /// + /// The returned pointer must be deleted with `pactffi_generator_iter_pair_delete`. + /// + /// # Safety + /// + /// The underlying data is owned by the `GeneratorKeyValuePair`, so is always safe to use. + /// + /// # Error Handling + /// + /// If no further data is present, returns NULL. + ffi.Pointer pactffi_generators_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_generators_iter_next( + iter, + ); + } + + late final _pactffi_generators_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_generators_iter_next'); + late final _pactffi_generators_iter_next = + _pactffi_generators_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free a pair of key and value returned from `pactffi_generators_iter_next`. + void pactffi_generators_iter_pair_delete( + ffi.Pointer pair, + ) { + return _pactffi_generators_iter_pair_delete( + pair, + ); + } + + late final _pactffi_generators_iter_pair_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_generators_iter_pair_delete'); + late final _pactffi_generators_iter_pair_delete = + _pactffi_generators_iter_pair_deletePtr + .asFunction)>(); + + /// Get a mutable pointer to a newly-created default interaction on the heap. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_sync_http_new() { + return _pactffi_sync_http_new(); + } + + late final _pactffi_sync_http_newPtr = + _lookup Function()>>( + 'pactffi_sync_http_new'); + late final _pactffi_sync_http_new = _pactffi_sync_http_newPtr + .asFunction Function()>(); + + /// Destroy the `SynchronousHttp` interaction being pointed to. + void pactffi_sync_http_delete( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_delete( + interaction, + ); + } + + late final _pactffi_sync_http_deletePtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_sync_http_delete'); + late final _pactffi_sync_http_delete = _pactffi_sync_http_deletePtr + .asFunction)>(); + + /// Get the request of a `SynchronousHttp` interaction. + /// + /// # Safety + /// + /// The data pointed to by the pointer this function returns will be deleted when the interaction + /// is deleted. Trying to use if after the interaction is deleted will result in undefined behaviour. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. + ffi.Pointer pactffi_sync_http_get_request( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_request( + interaction, + ); + } + + late final _pactffi_sync_http_get_requestPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_sync_http_get_request'); + late final _pactffi_sync_http_get_request = + _pactffi_sync_http_get_requestPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get the request contents of a `SynchronousHttp` interaction in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the interaction. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. If the body of the request + /// is missing, then this function also returns NULL. This means there's + /// no mechanism to differentiate with this function call alone between + /// a NULL body and a missing body. + ffi.Pointer pactffi_sync_http_get_request_contents( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_request_contents( + interaction, + ); + } + + late final _pactffi_sync_http_get_request_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_sync_http_get_request_contents'); + late final _pactffi_sync_http_get_request_contents = + _pactffi_sync_http_get_request_contentsPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the request contents of the interaction. + /// + /// * `interaction` - the interaction to set the request contents for + /// * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The request contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the request contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_http_set_request_contents( + ffi.Pointer interaction, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_sync_http_set_request_contents( + interaction, + contents, + content_type, + ); + } + + late final _pactffi_sync_http_set_request_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_sync_http_set_request_contents'); + late final _pactffi_sync_http_set_request_contents = + _pactffi_sync_http_set_request_contentsPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the request contents of a `SynchronousHttp` interaction. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns 0. If the body of the request + /// is missing, then this function also returns 0. + int pactffi_sync_http_get_request_contents_length( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_request_contents_length( + interaction, + ); + } + + late final _pactffi_sync_http_get_request_contents_lengthPtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_sync_http_get_request_contents_length'); + late final _pactffi_sync_http_get_request_contents_length = + _pactffi_sync_http_get_request_contents_lengthPtr + .asFunction)>(); + + /// Get the request contents of a `SynchronousHttp` interaction as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_sync_http_get_request_contents_length`. + /// It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer + /// after the interaction is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. If the body of the request + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_sync_http_get_request_contents_bin( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_request_contents_bin( + interaction, + ); + } + + late final _pactffi_sync_http_get_request_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_http_get_request_contents_bin'); + late final _pactffi_sync_http_get_request_contents_bin = + _pactffi_sync_http_get_request_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Sets the request contents of the interaction as an array of bytes. + /// + /// * `interaction` - the interaction to set the request contents for + /// * `contents` - pointer to contents to copy from + /// * `len` - number of bytes to copy from the contents pointer + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the request contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_http_set_request_contents_bin( + ffi.Pointer interaction, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_sync_http_set_request_contents_bin( + interaction, + contents, + len, + content_type, + ); + } + + late final _pactffi_sync_http_set_request_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_sync_http_set_request_contents_bin'); + late final _pactffi_sync_http_set_request_contents_bin = + _pactffi_sync_http_set_request_contents_binPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get the response of a `SynchronousHttp` interaction. + /// + /// # Safety + /// + /// The data pointed to by the pointer this function returns will be deleted when the interaction + /// is deleted. Trying to use if after the interaction is deleted will result in undefined behaviour. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. + ffi.Pointer pactffi_sync_http_get_response( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_response( + interaction, + ); + } + + late final _pactffi_sync_http_get_responsePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_sync_http_get_response'); + late final _pactffi_sync_http_get_response = + _pactffi_sync_http_get_responsePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get the response contents of a `SynchronousHttp` interaction in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the interaction. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. + /// + /// If the body of the response is missing, then this function also returns NULL. + /// This means there's no mechanism to differentiate with this function call alone between + /// a NULL body and a missing body. + ffi.Pointer pactffi_sync_http_get_response_contents( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_response_contents( + interaction, + ); + } + + late final _pactffi_sync_http_get_response_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_sync_http_get_response_contents'); + late final _pactffi_sync_http_get_response_contents = + _pactffi_sync_http_get_response_contentsPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the response contents of the interaction. + /// + /// * `interaction` - the interaction to set the response contents for + /// * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The response contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the response contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_http_set_response_contents( + ffi.Pointer interaction, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_sync_http_set_response_contents( + interaction, + contents, + content_type, + ); + } + + late final _pactffi_sync_http_set_response_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_sync_http_set_response_contents'); + late final _pactffi_sync_http_set_response_contents = + _pactffi_sync_http_set_response_contentsPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the response contents of a `SynchronousHttp` interaction. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the interaction is NULL or the index is not valid, returns 0. If the body of the response + /// is missing, then this function also returns 0. + int pactffi_sync_http_get_response_contents_length( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_response_contents_length( + interaction, + ); + } + + late final _pactffi_sync_http_get_response_contents_lengthPtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_sync_http_get_response_contents_length'); + late final _pactffi_sync_http_get_response_contents_length = + _pactffi_sync_http_get_response_contents_lengthPtr + .asFunction)>(); + + /// Get the response contents of a `SynchronousHttp` interaction as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_sync_http_get_response_contents_length`. + /// It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer + /// after the interaction is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the interaction is NULL, returns NULL. If the body of the response + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_sync_http_get_response_contents_bin( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_response_contents_bin( + interaction, + ); + } + + late final _pactffi_sync_http_get_response_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_http_get_response_contents_bin'); + late final _pactffi_sync_http_get_response_contents_bin = + _pactffi_sync_http_get_response_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Sets the response contents of the `SynchronousHttp` interaction as an array of bytes. + /// + /// * `interaction` - the interaction to set the response contents for + /// * `contents` - pointer to contents to copy from + /// * `len` - number of bytes to copy + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the response contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_http_set_response_contents_bin( + ffi.Pointer interaction, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_sync_http_set_response_contents_bin( + interaction, + contents, + len, + content_type, + ); + } + + late final _pactffi_sync_http_set_response_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_sync_http_set_response_contents_bin'); + late final _pactffi_sync_http_set_response_contents_bin = + _pactffi_sync_http_set_response_contents_binPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get a copy of the description. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// Since it is a copy, the returned string may safely outlive + /// the `SynchronousHttp` interaction. + /// + /// # Errors + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the Rust string contains embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_sync_http_get_description( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_description( + interaction, + ); + } + + late final _pactffi_sync_http_get_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_sync_http_get_description'); + late final _pactffi_sync_http_get_description = + _pactffi_sync_http_get_descriptionPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Write the `description` field on the `SynchronousHttp`. + /// + /// # Safety + /// + /// `description` must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + /// + /// This function will only reallocate if the new string + /// does not fit in the existing buffer. + /// + /// # Error Handling + /// + /// Errors will be reported with a non-zero return value. + int pactffi_sync_http_set_description( + ffi.Pointer interaction, + ffi.Pointer description, + ) { + return _pactffi_sync_http_set_description( + interaction, + description, + ); + } + + late final _pactffi_sync_http_set_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_sync_http_set_description'); + late final _pactffi_sync_http_set_description = + _pactffi_sync_http_set_descriptionPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + /// Get a copy of the provider state at the given index from this interaction. + /// + /// # Safety + /// + /// The returned structure must be deleted with `provider_state_delete`. + /// + /// Since it is a copy, the returned structure may safely outlive + /// the `SynchronousHttp`. + /// + /// # Error Handling + /// + /// On failure, this function will return a variant other than Success. + /// + /// This function may fail if the index requested is out of bounds, + /// or if any of the Rust strings contain embedded null ('\0') bytes. + ffi.Pointer pactffi_sync_http_get_provider_state( + ffi.Pointer interaction, + int index, + ) { + return _pactffi_sync_http_get_provider_state( + interaction, + index, + ); + } + + late final _pactffi_sync_http_get_provider_statePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.UnsignedInt)>>('pactffi_sync_http_get_provider_state'); + late final _pactffi_sync_http_get_provider_state = + _pactffi_sync_http_get_provider_statePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over provider states. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// + /// # Error Handling + /// + /// Returns NULL if an error occurs. + ffi.Pointer pactffi_sync_http_get_provider_state_iter( + ffi.Pointer interaction, + ) { + return _pactffi_sync_http_get_provider_state_iter( + interaction, + ); + } + + late final _pactffi_sync_http_get_provider_state_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_http_get_provider_state_iter'); + late final _pactffi_sync_http_get_provider_state_iter = + _pactffi_sync_http_get_provider_state_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Casts this interaction to a `SynchronousHttp` interaction. Returns a NULL pointer if the + /// interaction can not be casted to a `SynchronousHttp` interaction (for instance, it is a + /// message interaction). The returned pointer must be freed with `pactffi_sync_http_delete` + /// when no longer required. + /// + /// # Safety + /// This function is safe as long as the interaction pointer is a valid pointer. + /// + /// # Errors + /// On any error, this function will return a NULL pointer. + ffi.Pointer pactffi_pact_interaction_as_synchronous_http( + ffi.Pointer interaction, + ) { + return _pactffi_pact_interaction_as_synchronous_http( + interaction, + ); + } + + late final _pactffi_pact_interaction_as_synchronous_httpPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_interaction_as_synchronous_http'); + late final _pactffi_pact_interaction_as_synchronous_http = + _pactffi_pact_interaction_as_synchronous_httpPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Casts this interaction to a `Message` interaction. Returns a NULL pointer if the + /// interaction can not be casted to a `Message` interaction (for instance, it is a + /// http interaction). The returned pointer must be freed with `pactffi_message_delete` + /// when no longer required. + /// + /// Note that if the interaction is a V4 `AsynchronousMessage`, it will be converted to a V3 + /// `Message` before being returned. + /// + /// # Safety + /// This function is safe as long as the interaction pointer is a valid pointer. + /// + /// # Errors + /// On any error, this function will return a NULL pointer. + ffi.Pointer pactffi_pact_interaction_as_message( + ffi.Pointer interaction, + ) { + return _pactffi_pact_interaction_as_message( + interaction, + ); + } + + late final _pactffi_pact_interaction_as_messagePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_pact_interaction_as_message'); + late final _pactffi_pact_interaction_as_message = + _pactffi_pact_interaction_as_messagePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Casts this interaction to a `AsynchronousMessage` interaction. Returns a NULL pointer if the + /// interaction can not be casted to a `AsynchronousMessage` interaction (for instance, it is a + /// http interaction). The returned pointer must be freed with `pactffi_async_message_delete` + /// when no longer required. + /// + /// Note that if the interaction is a V3 `Message`, it will be converted to a V4 + /// `AsynchronousMessage` before being returned. + /// + /// # Safety + /// This function is safe as long as the interaction pointer is a valid pointer. + /// + /// # Errors + /// On any error, this function will return a NULL pointer. + ffi.Pointer + pactffi_pact_interaction_as_asynchronous_message( + ffi.Pointer interaction, + ) { + return _pactffi_pact_interaction_as_asynchronous_message( + interaction, + ); + } + + late final _pactffi_pact_interaction_as_asynchronous_messagePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_interaction_as_asynchronous_message'); + late final _pactffi_pact_interaction_as_asynchronous_message = + _pactffi_pact_interaction_as_asynchronous_messagePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Casts this interaction to a `SynchronousMessage` interaction. Returns a NULL pointer if the + /// interaction can not be casted to a `SynchronousMessage` interaction (for instance, it is a + /// http interaction). The returned pointer must be freed with `pactffi_sync_message_delete` + /// when no longer required. + /// + /// # Safety + /// This function is safe as long as the interaction pointer is a valid pointer. + /// + /// # Errors + /// On any error, this function will return a NULL pointer. + ffi.Pointer + pactffi_pact_interaction_as_synchronous_message( + ffi.Pointer interaction, + ) { + return _pactffi_pact_interaction_as_synchronous_message( + interaction, + ); + } + + late final _pactffi_pact_interaction_as_synchronous_messagePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_interaction_as_synchronous_message'); + late final _pactffi_pact_interaction_as_synchronous_message = + _pactffi_pact_interaction_as_synchronous_messagePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_pact_message_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_pact_message_iter_delete( + iter, + ); + } + + late final _pactffi_pact_message_iter_deletePtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_pact_message_iter_delete'); + late final _pactffi_pact_message_iter_delete = + _pactffi_pact_message_iter_deletePtr + .asFunction)>(); + + /// Get the next message from the message pact. As the messages returned are owned by the + /// iterator, they do not need to be deleted but will be cleaned up when the iterator is + /// deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// Deleting a message returned by the iterator can lead to undefined behaviour. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_pact_message_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_pact_message_iter_next( + iter, + ); + } + + late final _pactffi_pact_message_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_pact_message_iter_next'); + late final _pactffi_pact_message_iter_next = + _pactffi_pact_message_iter_nextPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get the next asynchronous from the V4 pact. As the messages returned are + /// owned by the iterator, they do not need to be deleted but will be + /// cleaned up when the iterator is deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end + /// of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// Deleting a message returned by the iterator can lead to undefined + /// behaviour. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if + /// an error occurs. + ffi.Pointer pactffi_pact_async_message_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_pact_async_message_iter_next( + iter, + ); + } + + late final _pactffi_pact_async_message_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_async_message_iter_next'); + late final _pactffi_pact_async_message_iter_next = + _pactffi_pact_async_message_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_pact_async_message_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_pact_async_message_iter_delete( + iter, + ); + } + + late final _pactffi_pact_async_message_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_pact_async_message_iter_delete'); + late final _pactffi_pact_async_message_iter_delete = + _pactffi_pact_async_message_iter_deletePtr + .asFunction)>(); + + /// Get the next synchronous request/response message from the V4 pact. As the messages returned are owned by the + /// iterator, they do not need to be deleted but will be cleaned up when the iterator is + /// deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// Deleting a message returned by the iterator can lead to undefined behaviour. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_pact_sync_message_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_pact_sync_message_iter_next( + iter, + ); + } + + late final _pactffi_pact_sync_message_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_sync_message_iter_next'); + late final _pactffi_pact_sync_message_iter_next = + _pactffi_pact_sync_message_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_pact_sync_message_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_pact_sync_message_iter_delete( + iter, + ); + } + + late final _pactffi_pact_sync_message_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_pact_sync_message_iter_delete'); + late final _pactffi_pact_sync_message_iter_delete = + _pactffi_pact_sync_message_iter_deletePtr + .asFunction)>(); + + /// Get the next synchronous HTTP request/response interaction from the V4 pact. As the + /// interactions returned are owned by the iterator, they do not need to be deleted but + /// will be cleaned up when the iterator is deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// Deleting an interaction returned by the iterator can lead to undefined behaviour. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_pact_sync_http_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_pact_sync_http_iter_next( + iter, + ); + } + + late final _pactffi_pact_sync_http_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_sync_http_iter_next'); + late final _pactffi_pact_sync_http_iter_next = + _pactffi_pact_sync_http_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_pact_sync_http_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_pact_sync_http_iter_delete( + iter, + ); + } + + late final _pactffi_pact_sync_http_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_pact_sync_http_iter_delete'); + late final _pactffi_pact_sync_http_iter_delete = + _pactffi_pact_sync_http_iter_deletePtr + .asFunction)>(); + + /// Get the next interaction from the pact. As the interactions returned are owned by the + /// iterator, they do not need to be deleted but will be cleaned up when the iterator is + /// deleted. + /// + /// Will return a NULL pointer when the iterator has advanced past the end of the list. + /// + /// # Safety + /// + /// This function is safe. + /// + /// Deleting an interaction returned by the iterator can lead to undefined behaviour. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_pact_interaction_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_pact_interaction_iter_next( + iter, + ); + } + + late final _pactffi_pact_interaction_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_pact_interaction_iter_next'); + late final _pactffi_pact_interaction_iter_next = + _pactffi_pact_interaction_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_pact_interaction_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_pact_interaction_iter_delete( + iter, + ); + } + + late final _pactffi_pact_interaction_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_pact_interaction_iter_delete'); + late final _pactffi_pact_interaction_iter_delete = + _pactffi_pact_interaction_iter_deletePtr + .asFunction)>(); + + /// Get the JSON form of the matching rule. + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// # Safety + /// + /// This function will fail if it is passed a NULL pointer, or the iterator that owns the + /// value of the matching rule has been deleted. + ffi.Pointer pactffi_matching_rule_to_json( + ffi.Pointer rule, + ) { + return _pactffi_matching_rule_to_json( + rule, + ); + } + + late final _pactffi_matching_rule_to_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_matching_rule_to_json'); + late final _pactffi_matching_rule_to_json = _pactffi_matching_rule_to_jsonPtr + .asFunction Function(ffi.Pointer)>(); + + /// Free the iterator when you're done using it. + void pactffi_matching_rules_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_matching_rules_iter_delete( + iter, + ); + } + + late final _pactffi_matching_rules_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_matching_rules_iter_delete'); + late final _pactffi_matching_rules_iter_delete = + _pactffi_matching_rules_iter_deletePtr.asFunction< + void Function(ffi.Pointer)>(); + + /// Get the next path and matching rule out of the iterator, if possible. + /// + /// The returned pointer must be deleted with `pactffi_matching_rules_iter_pair_delete`. + /// + /// # Safety + /// + /// The underlying data is owned by the `MatchingRuleKeyValuePair`, so is always safe to use. + /// + /// # Error Handling + /// + /// If no further data is present, returns NULL. + ffi.Pointer pactffi_matching_rules_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_matching_rules_iter_next( + iter, + ); + } + + late final _pactffi_matching_rules_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_matching_rules_iter_next'); + late final _pactffi_matching_rules_iter_next = + _pactffi_matching_rules_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free a pair of key and value returned from `message_metadata_iter_next`. + void pactffi_matching_rules_iter_pair_delete( + ffi.Pointer pair, + ) { + return _pactffi_matching_rules_iter_pair_delete( + pair, + ); + } + + late final _pactffi_matching_rules_iter_pair_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_matching_rules_iter_pair_delete'); + late final _pactffi_matching_rules_iter_pair_delete = + _pactffi_matching_rules_iter_pair_deletePtr + .asFunction)>(); + + /// Get a mutable pointer to a newly-created default message on the heap. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_message_new() { + return _pactffi_message_new(); + } + + late final _pactffi_message_newPtr = + _lookup Function()>>( + 'pactffi_message_new'); + late final _pactffi_message_new = + _pactffi_message_newPtr.asFunction Function()>(); + + /// Constructs a `Message` from the JSON string + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the JSON string is invalid or not UTF-8 encoded, returns a NULL. + ffi.Pointer pactffi_message_new_from_json( + int index, + ffi.Pointer json_str, + int spec_version, + ) { + return _pactffi_message_new_from_json( + index, + json_str, + spec_version, + ); + } + + late final _pactffi_message_new_from_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.UnsignedInt, ffi.Pointer, + ffi.Int32)>>('pactffi_message_new_from_json'); + late final _pactffi_message_new_from_json = + _pactffi_message_new_from_jsonPtr.asFunction< + ffi.Pointer Function(int, ffi.Pointer, int)>(); + + /// Constructs a `Message` from a body with a given content-type. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the body or content type are invalid or not UTF-8 encoded, returns NULL. + ffi.Pointer pactffi_message_new_from_body( + ffi.Pointer body, + ffi.Pointer content_type, + ) { + return _pactffi_message_new_from_body( + body, + content_type, + ); + } + + late final _pactffi_message_new_from_bodyPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_message_new_from_body'); + late final _pactffi_message_new_from_body = + _pactffi_message_new_from_bodyPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Destroy the `Message` being pointed to. + void pactffi_message_delete( + ffi.Pointer message, + ) { + return _pactffi_message_delete( + message, + ); + } + + late final _pactffi_message_deletePtr = + _lookup)>>( + 'pactffi_message_delete'); + late final _pactffi_message_delete = _pactffi_message_deletePtr + .asFunction)>(); + + /// Get the contents of a `Message` in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete` and can outlive the message. + /// This function must only ever be called from a foreign language. Calling it from a Rust function + /// that has a Tokio runtime in its call stack can result in a deadlock. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. This means there's + /// no mechanism to differentiate with this function call alone between + /// a NULL message and a missing message body. + ffi.Pointer pactffi_message_get_contents( + ffi.Pointer message, + ) { + return _pactffi_message_get_contents( + message, + ); + } + + late final _pactffi_message_get_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_get_contents'); + late final _pactffi_message_get_contents = _pactffi_message_get_contentsPtr + .asFunction Function(ffi.Pointer)>(); + + /// Sets the contents of the message. + /// + /// # Safety + /// + /// The message contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_message_set_contents( + ffi.Pointer message, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_message_set_contents( + message, + contents, + content_type, + ); + } + + late final _pactffi_message_set_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('pactffi_message_set_contents'); + late final _pactffi_message_set_contents = + _pactffi_message_set_contentsPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the contents of a `Message`. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the message is NULL, returns 0. If the body of the message + /// is missing, then this function also returns 0. + int pactffi_message_get_contents_length( + ffi.Pointer message, + ) { + return _pactffi_message_get_contents_length( + message, + ); + } + + late final _pactffi_message_get_contents_lengthPtr = + _lookup)>>( + 'pactffi_message_get_contents_length'); + late final _pactffi_message_get_contents_length = + _pactffi_message_get_contents_lengthPtr + .asFunction)>(); + + /// Get the contents of a `Message` as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_message_get_contents_length`. + /// It is safe to use the pointer while the message is not deleted or changed. Using the pointer + /// after the message is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_message_get_contents_bin( + ffi.Pointer message, + ) { + return _pactffi_message_get_contents_bin( + message, + ); + } + + late final _pactffi_message_get_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_get_contents_bin'); + late final _pactffi_message_get_contents_bin = + _pactffi_message_get_contents_binPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the contents of the message as an array of bytes. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_message_set_contents_bin( + ffi.Pointer message, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_message_set_contents_bin( + message, + contents, + len, + content_type, + ); + } + + late final _pactffi_message_set_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>('pactffi_message_set_contents_bin'); + late final _pactffi_message_set_contents_bin = + _pactffi_message_set_contents_binPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + int, ffi.Pointer)>(); + + /// Get a copy of the description. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// Since it is a copy, the returned string may safely outlive + /// the `Message`. + /// + /// # Errors + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the Rust string contains embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_message_get_description( + ffi.Pointer message, + ) { + return _pactffi_message_get_description( + message, + ); + } + + late final _pactffi_message_get_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_get_description'); + late final _pactffi_message_get_description = + _pactffi_message_get_descriptionPtr + .asFunction Function(ffi.Pointer)>(); + + /// Write the `description` field on the `Message`. + /// + /// # Safety + /// + /// `description` must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + /// + /// This function will only reallocate if the new string + /// does not fit in the existing buffer. + /// + /// # Error Handling + /// + /// Errors will be reported with a non-zero return value. + int pactffi_message_set_description( + ffi.Pointer message, + ffi.Pointer description, + ) { + return _pactffi_message_set_description( + message, + description, + ); + } + + late final _pactffi_message_set_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_message_set_description'); + late final _pactffi_message_set_description = + _pactffi_message_set_descriptionPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); + + /// Get a copy of the provider state at the given index from this message. + /// + /// # Safety + /// + /// The returned structure must be deleted with `provider_state_delete`. + /// + /// Since it is a copy, the returned structure may safely outlive + /// the `Message`. + /// + /// # Error Handling + /// + /// On failure, this function will return a variant other than Success. + /// + /// This function may fail if the index requested is out of bounds, + /// or if any of the Rust strings contain embedded null ('\0') bytes. + ffi.Pointer pactffi_message_get_provider_state( + ffi.Pointer message, + int index, + ) { + return _pactffi_message_get_provider_state( + message, + index, + ); + } + + late final _pactffi_message_get_provider_statePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.UnsignedInt)>>('pactffi_message_get_provider_state'); + late final _pactffi_message_get_provider_state = + _pactffi_message_get_provider_statePtr.asFunction< + ffi.Pointer Function(ffi.Pointer, int)>(); + + /// Get an iterator over provider states. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// + /// # Error Handling + /// + /// Returns NULL if an error occurs. + ffi.Pointer pactffi_message_get_provider_state_iter( + ffi.Pointer message, + ) { + return _pactffi_message_get_provider_state_iter( + message, + ); + } + + late final _pactffi_message_get_provider_state_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_get_provider_state_iter'); + late final _pactffi_message_get_provider_state_iter = + _pactffi_message_get_provider_state_iterPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get the next value from the iterator. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// + /// If a previous call panicked, then the internal mutex will have been poisoned and this + /// function will return NULL. + /// + /// # Error Handling + /// + /// Returns NULL if an error occurs. + ffi.Pointer pactffi_provider_state_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_provider_state_iter_next( + iter, + ); + } + + late final _pactffi_provider_state_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_provider_state_iter_next'); + late final _pactffi_provider_state_iter_next = + _pactffi_provider_state_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Delete the iterator. + void pactffi_provider_state_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_provider_state_iter_delete( + iter, + ); + } + + late final _pactffi_provider_state_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_provider_state_iter_delete'); + late final _pactffi_provider_state_iter_delete = + _pactffi_provider_state_iter_deletePtr + .asFunction)>(); + + /// Get a copy of the metadata value indexed by `key`. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// Since it is a copy, the returned string may safely outlive + /// the `Message`. + /// + /// The returned pointer will be NULL if the metadata does not contain + /// the given key, or if an error occurred. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the provided `key` string contains + /// invalid UTF-8, or if the Rust string contains embedded null ('\0') + /// bytes. + ffi.Pointer pactffi_message_find_metadata( + ffi.Pointer message, + ffi.Pointer key, + ) { + return _pactffi_message_find_metadata( + message, + key, + ); + } + + late final _pactffi_message_find_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_message_find_metadata'); + late final _pactffi_message_find_metadata = + _pactffi_message_find_metadataPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Insert the (`key`, `value`) pair into this Message's + /// `metadata` HashMap. + /// + /// # Safety + /// + /// This function returns an enum indicating the result; + /// see the comments on HashMapInsertStatus for details. + /// + /// # Error Handling + /// + /// This function may fail if the provided `key` or `value` strings + /// contain invalid UTF-8. + int pactffi_message_insert_metadata( + ffi.Pointer message, + ffi.Pointer key, + ffi.Pointer value, + ) { + return _pactffi_message_insert_metadata( + message, + key, + value, + ); + } + + late final _pactffi_message_insert_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('pactffi_message_insert_metadata'); + late final _pactffi_message_insert_metadata = + _pactffi_message_insert_metadataPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the next key and value out of the iterator, if possible. + /// + /// The returned pointer must be deleted with `pactffi_message_metadata_pair_delete`. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// This function must only ever be called from a foreign language. Calling it from a Rust function + /// that has a Tokio runtime in its call stack can result in a deadlock. + /// + /// # Error Handling + /// + /// If no further data is present, returns NULL. + ffi.Pointer pactffi_message_metadata_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_message_metadata_iter_next( + iter, + ); + } + + late final _pactffi_message_metadata_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_metadata_iter_next'); + late final _pactffi_message_metadata_iter_next = + _pactffi_message_metadata_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get an iterator over the metadata of a message. + /// + /// # Safety + /// + /// This iterator carries a pointer to the message, and must + /// not outlive the message. + /// + /// The message metadata also must not be modified during iteration. If it is, + /// the old iterator must be deleted and a new iterator created. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain + /// embedded null ('\0') bytes. + ffi.Pointer pactffi_message_get_metadata_iter( + ffi.Pointer message, + ) { + return _pactffi_message_get_metadata_iter( + message, + ); + } + + late final _pactffi_message_get_metadata_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_get_metadata_iter'); + late final _pactffi_message_get_metadata_iter = + _pactffi_message_get_metadata_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the metadata iterator when you're done using it. + void pactffi_message_metadata_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_message_metadata_iter_delete( + iter, + ); + } + + late final _pactffi_message_metadata_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_message_metadata_iter_delete'); + late final _pactffi_message_metadata_iter_delete = + _pactffi_message_metadata_iter_deletePtr + .asFunction)>(); + + /// Free a pair of key and value returned from `message_metadata_iter_next`. + void pactffi_message_metadata_pair_delete( + ffi.Pointer pair, + ) { + return _pactffi_message_metadata_pair_delete( + pair, + ); + } + + late final _pactffi_message_metadata_pair_deletePtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_message_metadata_pair_delete'); + late final _pactffi_message_metadata_pair_delete = + _pactffi_message_metadata_pair_deletePtr + .asFunction)>(); + + /// Construct a new `MessagePact` from the JSON string. + /// The provided file name is used when generating error messages. + /// + /// # Safety + /// + /// The `file_name` and `json_str` parameters must both be valid UTF-8 + /// encoded strings. + /// + /// # Error Handling + /// + /// On error, this function will return a null pointer. + ffi.Pointer pactffi_message_pact_new_from_json( + ffi.Pointer file_name, + ffi.Pointer json_str, + ) { + return _pactffi_message_pact_new_from_json( + file_name, + json_str, + ); + } + + late final _pactffi_message_pact_new_from_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_message_pact_new_from_json'); + late final _pactffi_message_pact_new_from_json = + _pactffi_message_pact_new_from_jsonPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Delete the `MessagePact` being pointed to. + void pactffi_message_pact_delete( + ffi.Pointer message_pact, + ) { + return _pactffi_message_pact_delete( + message_pact, + ); + } + + late final _pactffi_message_pact_deletePtr = + _lookup)>>( + 'pactffi_message_pact_delete'); + late final _pactffi_message_pact_delete = _pactffi_message_pact_deletePtr + .asFunction)>(); + + /// Get a pointer to the Consumer struct inside the MessagePact. + /// This is a mutable borrow: The caller may mutate the Consumer + /// through this pointer. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// This function will only fail if it is passed a NULL pointer. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_message_pact_get_consumer( + ffi.Pointer message_pact, + ) { + return _pactffi_message_pact_get_consumer( + message_pact, + ); + } + + late final _pactffi_message_pact_get_consumerPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_pact_get_consumer'); + late final _pactffi_message_pact_get_consumer = + _pactffi_message_pact_get_consumerPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get a pointer to the Provider struct inside the MessagePact. + /// This is a mutable borrow: The caller may mutate the Provider + /// through this pointer. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// This function will only fail if it is passed a NULL pointer. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_message_pact_get_provider( + ffi.Pointer message_pact, + ) { + return _pactffi_message_pact_get_provider( + message_pact, + ); + } + + late final _pactffi_message_pact_get_providerPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_message_pact_get_provider'); + late final _pactffi_message_pact_get_provider = + _pactffi_message_pact_get_providerPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get an iterator over the messages of a message pact. + /// + /// # Safety + /// + /// This iterator carries a pointer to the message pact, and must + /// not outlive the message pact. + /// + /// The message pact messages also must not be modified during iteration. + /// If they are, the old iterator must be deleted and a new iterator created. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_message_pact_get_message_iter( + ffi.Pointer message_pact, + ) { + return _pactffi_message_pact_get_message_iter( + message_pact, + ); + } + + late final _pactffi_message_pact_get_message_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_pact_get_message_iter'); + late final _pactffi_message_pact_get_message_iter = + _pactffi_message_pact_get_message_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the next message from the message pact. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// This function will return a NULL pointer if passed a NULL pointer or if an error occurs. + ffi.Pointer pactffi_message_pact_message_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_message_pact_message_iter_next( + iter, + ); + } + + late final _pactffi_message_pact_message_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_pact_message_iter_next'); + late final _pactffi_message_pact_message_iter_next = + _pactffi_message_pact_message_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Delete the iterator. + void pactffi_message_pact_message_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_message_pact_message_iter_delete( + iter, + ); + } + + late final _pactffi_message_pact_message_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_message_pact_message_iter_delete'); + late final _pactffi_message_pact_message_iter_delete = + _pactffi_message_pact_message_iter_deletePtr + .asFunction)>(); + + /// Get a copy of the metadata value indexed by `key1` and `key2`. + /// + /// # Safety + /// + /// Since it is a copy, the returned string may safely outlive + /// the `Message`. + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned pointer will be NULL if the metadata does not contain + /// the given key, or if an error occurred. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the provided `key1` or `key2` strings contains + /// invalid UTF-8, or if the Rust string contains embedded null ('\0') + /// bytes. + ffi.Pointer pactffi_message_pact_find_metadata( + ffi.Pointer message_pact, + ffi.Pointer key1, + ffi.Pointer key2, + ) { + return _pactffi_message_pact_find_metadata( + message_pact, + key1, + key2, + ); + } + + late final _pactffi_message_pact_find_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_message_pact_find_metadata'); + late final _pactffi_message_pact_find_metadata = + _pactffi_message_pact_find_metadataPtr.asFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>(); + + /// Get an iterator over the metadata of a message pact. + /// + /// # Safety + /// + /// This iterator carries a pointer to the message pact, and must + /// not outlive the message pact. + /// + /// The message pact metadata also must not be modified during iteration. If it is, + /// the old iterator must be deleted and a new iterator created. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain + /// embedded null ('\0') bytes. + ffi.Pointer + pactffi_message_pact_get_metadata_iter( + ffi.Pointer message_pact, + ) { + return _pactffi_message_pact_get_metadata_iter( + message_pact, + ); + } + + late final _pactffi_message_pact_get_metadata_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_pact_get_metadata_iter'); + late final _pactffi_message_pact_get_metadata_iter = + _pactffi_message_pact_get_metadata_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the next triple out of the iterator, if possible + /// + /// # Safety + /// + /// This operation is invalid if the underlying data has been changed during iteration. + /// + /// # Error Handling + /// + /// Returns null if no next element is present. + ffi.Pointer + pactffi_message_pact_metadata_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_message_pact_metadata_iter_next( + iter, + ); + } + + late final _pactffi_message_pact_metadata_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_message_pact_metadata_iter_next'); + late final _pactffi_message_pact_metadata_iter_next = + _pactffi_message_pact_metadata_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the metadata iterator when you're done using it. + void pactffi_message_pact_metadata_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_message_pact_metadata_iter_delete( + iter, + ); + } + + late final _pactffi_message_pact_metadata_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_message_pact_metadata_iter_delete'); + late final _pactffi_message_pact_metadata_iter_delete = + _pactffi_message_pact_metadata_iter_deletePtr.asFunction< + void Function(ffi.Pointer)>(); + + /// Free a triple returned from `pactffi_message_pact_metadata_iter_next`. + void pactffi_message_pact_metadata_triple_delete( + ffi.Pointer triple, + ) { + return _pactffi_message_pact_metadata_triple_delete( + triple, + ); + } + + late final _pactffi_message_pact_metadata_triple_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_message_pact_metadata_triple_delete'); + late final _pactffi_message_pact_metadata_triple_delete = + _pactffi_message_pact_metadata_triple_deletePtr + .asFunction)>(); + + /// Get a copy of this provider's name. + /// + /// The copy must be deleted with `pactffi_string_delete`. + /// + /// # Usage + /// + /// ```c + /// // Assuming `file_name` and `json_str` are already defined. + /// + /// MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str); + /// if (message_pact == NULLPTR) { + /// // handle error. + /// } + /// + /// Provider *provider = pactffi_message_pact_get_provider(message_pact); + /// if (provider == NULLPTR) { + /// // handle error. + /// } + /// + /// char *name = pactffi_provider_get_name(provider); + /// if (name == NULL) { + /// // handle error. + /// } + /// + /// printf("%s\n", name); + /// + /// pactffi_string_delete(name); + /// ``` + /// + /// # Errors + /// + /// This function will fail if it is passed a NULL pointer, + /// or the Rust string contains an embedded NULL byte. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_provider_get_name( + ffi.Pointer provider, + ) { + return _pactffi_provider_get_name( + provider, + ); + } + + late final _pactffi_provider_get_namePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_provider_get_name'); + late final _pactffi_provider_get_name = _pactffi_provider_get_namePtr + .asFunction Function(ffi.Pointer)>(); + + /// Get the provider from a Pact. This returns a copy of the provider model, and needs to + /// be cleaned up with `pactffi_pact_provider_delete` when no longer required. + /// + /// # Errors + /// + /// This function will fail if it is passed a NULL pointer. + /// In the case of error, a NULL pointer will be returned. + ffi.Pointer pactffi_pact_get_provider( + ffi.Pointer pact, + ) { + return _pactffi_pact_get_provider( + pact, + ); + } + + late final _pactffi_pact_get_providerPtr = _lookup< + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'pactffi_pact_get_provider'); + late final _pactffi_pact_get_provider = _pactffi_pact_get_providerPtr + .asFunction Function(ffi.Pointer)>(); + + /// Frees the memory used by the Pact provider + void pactffi_pact_provider_delete( + ffi.Pointer provider, + ) { + return _pactffi_pact_provider_delete( + provider, + ); + } + + late final _pactffi_pact_provider_deletePtr = + _lookup)>>( + 'pactffi_pact_provider_delete'); + late final _pactffi_pact_provider_delete = _pactffi_pact_provider_deletePtr + .asFunction)>(); + + /// Get the name of the provider state as a string, which needs to be deleted with `pactffi_string_delete`. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the provider_state param is NULL, this returns NULL. + ffi.Pointer pactffi_provider_state_get_name( + ffi.Pointer provider_state, + ) { + return _pactffi_provider_state_get_name( + provider_state, + ); + } + + late final _pactffi_provider_state_get_namePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_provider_state_get_name'); + late final _pactffi_provider_state_get_name = + _pactffi_provider_state_get_namePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Get an iterator over the params of a provider state. + /// + /// # Safety + /// + /// This iterator carries a pointer to the provider state, and must + /// not outlive the provider state. + /// + /// The provider state params also must not be modified during iteration. If it is, + /// the old iterator must be deleted and a new iterator created. + /// + /// # Errors + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain + /// embedded null ('\0') bytes. + ffi.Pointer pactffi_provider_state_get_param_iter( + ffi.Pointer provider_state, + ) { + return _pactffi_provider_state_get_param_iter( + provider_state, + ); + } + + late final _pactffi_provider_state_get_param_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_provider_state_get_param_iter'); + late final _pactffi_provider_state_get_param_iter = + _pactffi_provider_state_get_param_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the next key and value out of the iterator, if possible + /// + /// Returns a pointer to a heap allocated array of 2 elements, the pointer to the + /// key string on the heap, and the pointer to the value string on the heap. + /// + /// # Safety + /// + /// The underlying data must not be modified during iteration. + /// + /// The user needs to free both the contained strings and the array. + /// + /// # Error Handling + /// + /// Returns NULL if there's no further elements or the iterator is NULL. + ffi.Pointer pactffi_provider_state_param_iter_next( + ffi.Pointer iter, + ) { + return _pactffi_provider_state_param_iter_next( + iter, + ); + } + + late final _pactffi_provider_state_param_iter_nextPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_provider_state_param_iter_next'); + late final _pactffi_provider_state_param_iter_next = + _pactffi_provider_state_param_iter_nextPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Free the provider state when you're done using it. + void pactffi_provider_state_delete( + ffi.Pointer provider_state, + ) { + return _pactffi_provider_state_delete( + provider_state, + ); + } + + late final _pactffi_provider_state_deletePtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_provider_state_delete'); + late final _pactffi_provider_state_delete = _pactffi_provider_state_deletePtr + .asFunction)>(); + + /// Free the provider state param iterator when you're done using it. + void pactffi_provider_state_param_iter_delete( + ffi.Pointer iter, + ) { + return _pactffi_provider_state_param_iter_delete( + iter, + ); + } + + late final _pactffi_provider_state_param_iter_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_provider_state_param_iter_delete'); + late final _pactffi_provider_state_param_iter_delete = + _pactffi_provider_state_param_iter_deletePtr + .asFunction)>(); + + /// Free a pair of key and value returned from `pactffi_provider_state_param_iter_next`. + void pactffi_provider_state_param_pair_delete( + ffi.Pointer pair, + ) { + return _pactffi_provider_state_param_pair_delete( + pair, + ); + } + + late final _pactffi_provider_state_param_pair_deletePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>( + 'pactffi_provider_state_param_pair_delete'); + late final _pactffi_provider_state_param_pair_delete = + _pactffi_provider_state_param_pair_deletePtr + .asFunction)>(); + + /// Get a mutable pointer to a newly-created default message on the heap. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_sync_message_new() { + return _pactffi_sync_message_new(); + } + + late final _pactffi_sync_message_newPtr = + _lookup Function()>>( + 'pactffi_sync_message_new'); + late final _pactffi_sync_message_new = _pactffi_sync_message_newPtr + .asFunction Function()>(); + + /// Destroy the `Message` being pointed to. + void pactffi_sync_message_delete( + ffi.Pointer message, + ) { + return _pactffi_sync_message_delete( + message, + ); + } + + late final _pactffi_sync_message_deletePtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_sync_message_delete'); + late final _pactffi_sync_message_delete = _pactffi_sync_message_deletePtr + .asFunction)>(); + + /// Get the request contents of a `SynchronousMessage` in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the message. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the request message + /// is missing, then this function also returns NULL. This means there's + /// no mechanism to differentiate with this function call alone between + /// a NULL message and a missing message body. + ffi.Pointer pactffi_sync_message_get_request_contents_str( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_request_contents_str( + message, + ); + } + + late final _pactffi_sync_message_get_request_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_sync_message_get_request_contents_str'); + late final _pactffi_sync_message_get_request_contents_str = + _pactffi_sync_message_get_request_contents_strPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Sets the request contents of the message. + /// + /// * `message` - the message to set the request contents for + /// * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The message contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_message_set_request_contents_str( + ffi.Pointer message, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_sync_message_set_request_contents_str( + message, + contents, + content_type, + ); + } + + late final _pactffi_sync_message_set_request_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_sync_message_set_request_contents_str'); + late final _pactffi_sync_message_set_request_contents_str = + _pactffi_sync_message_set_request_contents_strPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Get the length of the request contents of a `SynchronousMessage`. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the message is NULL, returns 0. If the body of the request + /// is missing, then this function also returns 0. + int pactffi_sync_message_get_request_contents_length( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_request_contents_length( + message, + ); + } + + late final _pactffi_sync_message_get_request_contents_lengthPtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_sync_message_get_request_contents_length'); + late final _pactffi_sync_message_get_request_contents_length = + _pactffi_sync_message_get_request_contents_lengthPtr + .asFunction)>(); + + /// Get the request contents of a `SynchronousMessage` as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_sync_message_get_request_contents_length`. + /// It is safe to use the pointer while the message is not deleted or changed. Using the pointer + /// after the message is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_sync_message_get_request_contents_bin( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_request_contents_bin( + message, + ); + } + + late final _pactffi_sync_message_get_request_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_message_get_request_contents_bin'); + late final _pactffi_sync_message_get_request_contents_bin = + _pactffi_sync_message_get_request_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Sets the request contents of the message as an array of bytes. + /// + /// * `message` - the message to set the request contents for + /// * `contents` - pointer to contents to copy from + /// * `len` - number of bytes to copy from the contents pointer + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_message_set_request_contents_bin( + ffi.Pointer message, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_sync_message_set_request_contents_bin( + message, + contents, + len, + content_type, + ); + } + + late final _pactffi_sync_message_set_request_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_sync_message_set_request_contents_bin'); + late final _pactffi_sync_message_set_request_contents_bin = + _pactffi_sync_message_set_request_contents_binPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get the request contents of an `SynchronousMessage` as a `MessageContents` pointer. + /// + /// # Safety + /// + /// The data pointed to by the pointer this function returns will be deleted when the message + /// is deleted. Trying to use if after the message is deleted will result in undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. + ffi.Pointer pactffi_sync_message_get_request_contents( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_request_contents( + message, + ); + } + + late final _pactffi_sync_message_get_request_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_message_get_request_contents'); + late final _pactffi_sync_message_get_request_contents = + _pactffi_sync_message_get_request_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Generate the request contents of a `SynchronousMessage` as a + /// `MessageContents` pointer. + /// + /// This function differs from [`pactffi_sync_message_get_request_contents`] + /// in that it will process the message contents for any generators or + /// matchers that are present in the message in order to generate the actual + /// message contents as would be received by the consumer. + /// + /// # Safety + /// + /// The data pointed to by the pointer must be deleted with + /// [`pactffi_message_contents_delete`][crate::models::contents::pactffi_message_contents_delete] + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. + ffi.Pointer pactffi_sync_message_generate_request_contents( + ffi.Pointer message, + ) { + return _pactffi_sync_message_generate_request_contents( + message, + ); + } + + late final _pactffi_sync_message_generate_request_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_message_generate_request_contents'); + late final _pactffi_sync_message_generate_request_contents = + _pactffi_sync_message_generate_request_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Get the number of response messages in the `SynchronousMessage`. + /// + /// # Safety + /// + /// The message pointer must point to a valid SynchronousMessage. + /// + /// # Error Handling + /// + /// If the message is NULL, returns 0. + int pactffi_sync_message_get_number_responses( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_number_responses( + message, + ); + } + + late final _pactffi_sync_message_get_number_responsesPtr = _lookup< + ffi + .NativeFunction)>>( + 'pactffi_sync_message_get_number_responses'); + late final _pactffi_sync_message_get_number_responses = + _pactffi_sync_message_get_number_responsesPtr + .asFunction)>(); + + /// Get the response contents of a `SynchronousMessage` in string form. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// The returned string can outlive the message. + /// + /// # Error Handling + /// + /// If the message is NULL or the index is not valid, returns NULL. + /// + /// If the body of the response message is missing, then this function also returns NULL. + /// This means there's no mechanism to differentiate with this function call alone between + /// a NULL message and a missing message body. + ffi.Pointer pactffi_sync_message_get_response_contents_str( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_get_response_contents_str( + message, + index, + ); + } + + late final _pactffi_sync_message_get_response_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Size)>>('pactffi_sync_message_get_response_contents_str'); + late final _pactffi_sync_message_get_response_contents_str = + _pactffi_sync_message_get_response_contents_strPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Sets the response contents of the message as a string. If index is greater than the number of responses + /// in the message, the responses will be padded with default values. + /// + /// * `message` - the message to set the response contents for + /// * `index` - index of the response to set. 0 is the first response. + /// * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer. + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The message contents and content type must either be NULL pointers, or point to valid + /// UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the response contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_message_set_response_contents_str( + ffi.Pointer message, + int index, + ffi.Pointer contents, + ffi.Pointer content_type, + ) { + return _pactffi_sync_message_set_response_contents_str( + message, + index, + contents, + content_type, + ); + } + + late final _pactffi_sync_message_set_response_contents_strPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Size, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_sync_message_set_response_contents_str'); + late final _pactffi_sync_message_set_response_contents_str = + _pactffi_sync_message_set_response_contents_strPtr.asFunction< + void Function(ffi.Pointer, int, + ffi.Pointer, ffi.Pointer)>(); + + /// Get the length of the response contents of a `SynchronousMessage`. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// If the message is NULL or the index is not valid, returns 0. If the body of the request + /// is missing, then this function also returns 0. + int pactffi_sync_message_get_response_contents_length( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_get_response_contents_length( + message, + index, + ); + } + + late final _pactffi_sync_message_get_response_contents_lengthPtr = _lookup< + ffi.NativeFunction< + ffi.Size Function(ffi.Pointer, + ffi.Size)>>('pactffi_sync_message_get_response_contents_length'); + late final _pactffi_sync_message_get_response_contents_length = + _pactffi_sync_message_get_response_contents_lengthPtr + .asFunction, int)>(); + + /// Get the response contents of a `SynchronousMessage` as a pointer to an array of bytes. + /// + /// # Safety + /// + /// The number of bytes in the buffer will be returned by `pactffi_sync_message_get_response_contents_length`. + /// It is safe to use the pointer while the message is not deleted or changed. Using the pointer + /// after the message is mutated or deleted may lead to undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL or the index is not valid, returns NULL. If the body of the message + /// is missing, then this function also returns NULL. + ffi.Pointer pactffi_sync_message_get_response_contents_bin( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_get_response_contents_bin( + message, + index, + ); + } + + late final _pactffi_sync_message_get_response_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Size)>>('pactffi_sync_message_get_response_contents_bin'); + late final _pactffi_sync_message_get_response_contents_bin = + _pactffi_sync_message_get_response_contents_binPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Sets the response contents of the message at the given index as an array of bytes. If index + /// is greater than the number of responses in the message, the responses will be padded with + /// default values. + /// + /// * `message` - the message to set the response contents for + /// * `index` - index of the response to set. 0 is the first response + /// * `contents` - pointer to contents to copy from + /// * `len` - number of bytes to copy + /// * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data. + /// + /// # Safety + /// + /// The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned + /// and consecutive. Otherwise behaviour is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the message contents as null. If the content + /// type is a null pointer, or can't be parsed, it will set the content type as unknown. + void pactffi_sync_message_set_response_contents_bin( + ffi.Pointer message, + int index, + ffi.Pointer contents, + int len, + ffi.Pointer content_type, + ) { + return _pactffi_sync_message_set_response_contents_bin( + message, + index, + contents, + len, + content_type, + ); + } + + late final _pactffi_sync_message_set_response_contents_binPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>( + 'pactffi_sync_message_set_response_contents_bin'); + late final _pactffi_sync_message_set_response_contents_bin = + _pactffi_sync_message_set_response_contents_binPtr.asFunction< + void Function(ffi.Pointer, int, + ffi.Pointer, int, ffi.Pointer)>(); + + /// Get the response contents of an `SynchronousMessage` as a `MessageContents` pointer. + /// + /// # Safety + /// + /// The data pointed to by the pointer this function returns will be deleted when the message + /// is deleted. Trying to use if after the message is deleted will result in undefined behaviour. + /// + /// # Error Handling + /// + /// If the message is NULL or the index is not valid, returns NULL. + ffi.Pointer pactffi_sync_message_get_response_contents( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_get_response_contents( + message, + index, + ); + } + + late final _pactffi_sync_message_get_response_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Size)>>('pactffi_sync_message_get_response_contents'); + late final _pactffi_sync_message_get_response_contents = + _pactffi_sync_message_get_response_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Generate the response contents of a `SynchronousMessage` as a + /// `MessageContents` pointer. + /// + /// This function differs from + /// [`pactffi_sync_message_get_response_contents`] in that it will process + /// the message contents for any generators or matchers that are present in + /// the message in order to generate the actual message contents as would be + /// received by the consumer. + /// + /// # Safety + /// + /// The data pointed to by the pointer must be deleted with + /// [`pactffi_message_contents_delete`][crate::models::contents::pactffi_message_contents_delete] + /// + /// # Error Handling + /// + /// If the message is NULL, returns NULL. + ffi.Pointer pactffi_sync_message_generate_response_contents( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_generate_response_contents( + message, + index, + ); + } + + late final _pactffi_sync_message_generate_response_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Size)>>('pactffi_sync_message_generate_response_contents'); + late final _pactffi_sync_message_generate_response_contents = + _pactffi_sync_message_generate_response_contentsPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get a copy of the description. + /// + /// # Safety + /// + /// The returned string must be deleted with `pactffi_string_delete`. + /// + /// Since it is a copy, the returned string may safely outlive + /// the `SynchronousMessage`. + /// + /// # Errors + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if the Rust string contains embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_sync_message_get_description( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_description( + message, + ); + } + + late final _pactffi_sync_message_get_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>( + 'pactffi_sync_message_get_description'); + late final _pactffi_sync_message_get_description = + _pactffi_sync_message_get_descriptionPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Write the `description` field on the `SynchronousMessage`. + /// + /// # Safety + /// + /// `description` must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + /// + /// This function will only reallocate if the new string + /// does not fit in the existing buffer. + /// + /// # Error Handling + /// + /// Errors will be reported with a non-zero return value. + int pactffi_sync_message_set_description( + ffi.Pointer message, + ffi.Pointer description, + ) { + return _pactffi_sync_message_set_description( + message, + description, + ); + } + + late final _pactffi_sync_message_set_descriptionPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_sync_message_set_description'); + late final _pactffi_sync_message_set_description = + _pactffi_sync_message_set_descriptionPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Get a copy of the provider state at the given index from this message. + /// + /// # Safety + /// + /// The returned structure must be deleted with `provider_state_delete`. + /// + /// Since it is a copy, the returned structure may safely outlive + /// the `SynchronousMessage`. + /// + /// # Error Handling + /// + /// On failure, this function will return a variant other than Success. + /// + /// This function may fail if the index requested is out of bounds, + /// or if any of the Rust strings contain embedded null ('\0') bytes. + ffi.Pointer pactffi_sync_message_get_provider_state( + ffi.Pointer message, + int index, + ) { + return _pactffi_sync_message_get_provider_state( + message, + index, + ); + } + + late final _pactffi_sync_message_get_provider_statePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.UnsignedInt)>>('pactffi_sync_message_get_provider_state'); + late final _pactffi_sync_message_get_provider_state = + _pactffi_sync_message_get_provider_statePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int)>(); + + /// Get an iterator over provider states. + /// + /// # Safety + /// + /// The underlying data must not change during iteration. + /// + /// # Error Handling + /// + /// Returns NULL if an error occurs. + ffi.Pointer + pactffi_sync_message_get_provider_state_iter( + ffi.Pointer message, + ) { + return _pactffi_sync_message_get_provider_state_iter( + message, + ); + } + + late final _pactffi_sync_message_get_provider_state_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>( + 'pactffi_sync_message_get_provider_state_iter'); + late final _pactffi_sync_message_get_provider_state_iter = + _pactffi_sync_message_get_provider_state_iterPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer)>(); + + /// Delete a string previously returned by this FFI. + /// + /// It is explicitly allowed to pass a null pointer to this function; + /// in that case the function will do nothing. + /// + /// # Safety + /// Passing an invalid pointer, or one that was not returned by a FFI function can result in + /// undefined behaviour. + void pactffi_string_delete( + ffi.Pointer string, + ) { + return _pactffi_string_delete( + string, + ); + } + + late final _pactffi_string_deletePtr = + _lookup)>>( + 'pactffi_string_delete'); + late final _pactffi_string_delete = _pactffi_string_deletePtr + .asFunction)>(); + + /// [DEPRECATED] External interface to create a HTTP mock server. A pointer to the pact JSON as a NULL-terminated C + /// string is passed in, as well as the port for the mock server to run on. A value of 0 for the + /// port will result in a port being allocated by the operating system. The port of the mock server is returned. + /// + /// * `pact_str` - Pact JSON + /// * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0) + /// * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate) + /// + /// This function is deprecated and replaced with `pactffi_create_mock_server_for_transport`. + /// + /// # Errors + /// + /// Errors are returned as negative values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | -1 | A null pointer was received | + /// | -2 | The pact JSON could not be parsed | + /// | -3 | The mock server could not be started | + /// | -4 | The method panicked | + /// | -5 | The address is not valid | + /// | -6 | Could not create the TLS configuration with the self-signed certificate | + int pactffi_create_mock_server( + ffi.Pointer pact_str, + ffi.Pointer addr_str, + bool tls, + ) { + return _pactffi_create_mock_server( + pact_str, + addr_str, + tls, + ); + } + + late final _pactffi_create_mock_serverPtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(ffi.Pointer, ffi.Pointer, + ffi.Bool)>>('pactffi_create_mock_server'); + late final _pactffi_create_mock_server = + _pactffi_create_mock_serverPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, bool)>(); + + /// Fetch the CA Certificate used to generate the self-signed certificate for the TLS mock server. + /// + /// **NOTE:** The string for the result is allocated on the heap, and will have to be freed + /// by the caller using pactffi_string_delete. + /// + /// # Errors + /// + /// An empty string indicates an error reading the pem file. + ffi.Pointer pactffi_get_tls_ca_certificate() { + return _pactffi_get_tls_ca_certificate(); + } + + late final _pactffi_get_tls_ca_certificatePtr = + _lookup Function()>>( + 'pactffi_get_tls_ca_certificate'); + late final _pactffi_get_tls_ca_certificate = + _pactffi_get_tls_ca_certificatePtr + .asFunction Function()>(); + + /// [DEPRECATED] External interface to create a HTTP mock server. A Pact handle is passed in, + /// as well as the port for the mock server to run on. A value of 0 for the port will result in a + /// port being allocated by the operating system. The port of the mock server is returned. + /// + /// * `pact` - Handle to a Pact model created with created with `pactffi_new_pact`. + /// * `addr_str` - Address to bind to in the form name:port (i.e. 127.0.0.1:0). Must be a valid UTF-8 NULL-terminated string. + /// * `tls` - boolean flag to indicate of the mock server should use TLS (using a self-signed certificate) + /// + /// This function is deprecated and replaced with `pactffi_create_mock_server_for_transport`. + /// + /// # Errors + /// + /// Errors are returned as negative values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | -1 | An invalid handle was received. Handles should be created with `pactffi_new_pact` | + /// | -3 | The mock server could not be started | + /// | -4 | The method panicked | + /// | -5 | The address is not valid | + /// | -6 | Could not create the TLS configuration with the self-signed certificate | + int pactffi_create_mock_server_for_pact( + int pact, + ffi.Pointer addr_str, + bool tls, + ) { + return _pactffi_create_mock_server_for_pact( + pact, + addr_str, + tls, + ); + } + + late final _pactffi_create_mock_server_for_pactPtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(PactHandle, ffi.Pointer, + ffi.Bool)>>('pactffi_create_mock_server_for_pact'); + late final _pactffi_create_mock_server_for_pact = + _pactffi_create_mock_server_for_pactPtr + .asFunction, bool)>(); + + /// Create a mock server for the provided Pact handle and transport. If the transport is not + /// provided (it is a NULL pointer or an empty string), will default to an HTTP transport. The + /// address is the interface bind to, and will default to the loopback adapter if not specified. + /// Specifying a value of zero for the port will result in the operating system allocating the port. + /// + /// Parameters: + /// * `pact` - Handle to a Pact model created with created with `pactffi_new_pact`. + /// * `addr` - Address to bind to (i.e. `127.0.0.1` or `[::1]`). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case the loopback adapter is used. + /// * `port` - Port number to bind to. A value of zero will result in the operating system allocating an available port. + /// * `transport` - The transport to use (i.e. http, https, grpc). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case http will be used. + /// * `transport_config` - (OPTIONAL) Configuration for the transport as a valid JSON string. Set to NULL or empty if not required. + /// + /// The port of the mock server is returned. + /// + /// # Safety + /// NULL pointers or empty strings can be passed in for the address, transport and transport_config, + /// in which case a default value will be used. Passing in an invalid pointer will result in undefined behaviour. + /// + /// # Errors + /// + /// Errors are returned as negative values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | -1 | An invalid handle was received. Handles should be created with `pactffi_new_pact` | + /// | -2 | transport_config is not valid JSON | + /// | -3 | The mock server could not be started | + /// | -4 | The method panicked | + /// | -5 | The address is not valid | + int pactffi_create_mock_server_for_transport( + int pact, + ffi.Pointer addr, + int port, + ffi.Pointer transport, + ffi.Pointer transport_config, + ) { + return _pactffi_create_mock_server_for_transport( + pact, + addr, + port, + transport, + transport_config, + ); + } + + late final _pactffi_create_mock_server_for_transportPtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(PactHandle, ffi.Pointer, ffi.Uint16, + ffi.Pointer, ffi.Pointer)>>( + 'pactffi_create_mock_server_for_transport'); + late final _pactffi_create_mock_server_for_transport = + _pactffi_create_mock_server_for_transportPtr.asFunction< + int Function(int, ffi.Pointer, int, ffi.Pointer, + ffi.Pointer)>(); + + /// External interface to check if a mock server has matched all its requests. The port number is + /// passed in, and if all requests have been matched, true is returned. False is returned if there + /// is no mock server on the given port, or if any request has not been successfully matched, or + /// the method panics. + bool pactffi_mock_server_matched( + int mock_server_port, + ) { + return _pactffi_mock_server_matched( + mock_server_port, + ); + } + + late final _pactffi_mock_server_matchedPtr = + _lookup>( + 'pactffi_mock_server_matched'); + late final _pactffi_mock_server_matched = + _pactffi_mock_server_matchedPtr.asFunction(); + + /// External interface to get all the mismatches from a mock server. The port number of the mock + /// server is passed in, and a pointer to a C string with the mismatches in JSON format is + /// returned. + /// + /// **NOTE:** The JSON string for the result is allocated on the heap, and will have to be freed + /// once the code using the mock server is complete. The [`cleanup_mock_server`](fn.cleanup_mock_server.html) function is + /// provided for this purpose. + /// + /// # Errors + /// + /// If there is no mock server with the provided port number, or the function panics, a NULL + /// pointer will be returned. Don't try to dereference it, it will not end well for you. + ffi.Pointer pactffi_mock_server_mismatches( + int mock_server_port, + ) { + return _pactffi_mock_server_mismatches( + mock_server_port, + ); + } + + late final _pactffi_mock_server_mismatchesPtr = + _lookup Function(ffi.Int32)>>( + 'pactffi_mock_server_mismatches'); + late final _pactffi_mock_server_mismatches = + _pactffi_mock_server_mismatchesPtr + .asFunction Function(int)>(); + + /// External interface to cleanup a mock server. This function will try terminate the mock server + /// with the given port number and cleanup any memory allocated for it. Returns true, unless a + /// mock server with the given port number does not exist, or the function panics. + bool pactffi_cleanup_mock_server( + int mock_server_port, + ) { + return _pactffi_cleanup_mock_server( + mock_server_port, + ); + } + + late final _pactffi_cleanup_mock_serverPtr = + _lookup>( + 'pactffi_cleanup_mock_server'); + late final _pactffi_cleanup_mock_server = + _pactffi_cleanup_mock_serverPtr.asFunction(); + + /// External interface to trigger a mock server to write out its pact file. This function should + /// be called if all the consumer tests have passed. The directory to write the file to is passed + /// as the second parameter. If a NULL pointer is passed, the current working directory is used. + /// + /// If overwrite is true, the file will be overwritten with the contents of the current pact. + /// Otherwise, it will be merged with any existing pact file. + /// + /// Returns 0 if the pact file was successfully written. Returns a positive code if the file can + /// not be written, or there is no mock server running on that port or the function panics. + /// + /// # Errors + /// + /// Errors are returned as positive values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | 1 | A general panic was caught | + /// | 2 | The pact file was not able to be written | + /// | 3 | A mock server with the provided port was not found | + int pactffi_write_pact_file( + int mock_server_port, + ffi.Pointer directory, + bool overwrite, + ) { + return _pactffi_write_pact_file( + mock_server_port, + directory, + overwrite, + ); + } + + late final _pactffi_write_pact_filePtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(ffi.Int32, ffi.Pointer, + ffi.Bool)>>('pactffi_write_pact_file'); + late final _pactffi_write_pact_file = _pactffi_write_pact_filePtr + .asFunction, bool)>(); + + /// Fetch the logs for the mock server. This needs the memory buffer log sink to be setup before + /// the mock server is started. Returned string will be freed with the `cleanup_mock_server` + /// function call. + /// + /// Will return a NULL pointer if the logs for the mock server can not be retrieved. + ffi.Pointer pactffi_mock_server_logs( + int mock_server_port, + ) { + return _pactffi_mock_server_logs( + mock_server_port, + ); + } + + late final _pactffi_mock_server_logsPtr = + _lookup Function(ffi.Int32)>>( + 'pactffi_mock_server_logs'); + late final _pactffi_mock_server_logs = _pactffi_mock_server_logsPtr + .asFunction Function(int)>(); + + /// Generates a datetime value from the provided format string, using the current system date and time + /// NOTE: The memory for the returned string needs to be freed with the `pactffi_string_delete` function + /// + /// # Safety + /// + /// If the format string pointer is NULL or has invalid UTF-8 characters, an error result will be + /// returned. If the format string pointer is not a valid pointer or is not a NULL-terminated string, + /// this will lead to undefined behaviour. + StringResult pactffi_generate_datetime_string( + ffi.Pointer format, + ) { + return _pactffi_generate_datetime_string( + format, + ); + } + + late final _pactffi_generate_datetime_stringPtr = + _lookup)>>( + 'pactffi_generate_datetime_string'); + late final _pactffi_generate_datetime_string = + _pactffi_generate_datetime_stringPtr + .asFunction)>(); + + /// Checks that the example string matches the given regex. + /// + /// # Safety + /// + /// Both the regex and example pointers must be valid pointers to NULL-terminated strings. Invalid + /// pointers will result in undefined behaviour. + bool pactffi_check_regex( + ffi.Pointer regex, + ffi.Pointer example, + ) { + return _pactffi_check_regex( + regex, + example, + ); + } + + late final _pactffi_check_regexPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_check_regex'); + late final _pactffi_check_regex = _pactffi_check_regexPtr.asFunction< + bool Function(ffi.Pointer, ffi.Pointer)>(); + + /// Generates an example string based on the provided regex. + /// NOTE: The memory for the returned string needs to be freed with the `pactffi_string_delete` function. + /// + /// # Safety + /// + /// The regex pointer must be a valid pointer to a NULL-terminated string. Invalid pointers will + /// result in undefined behaviour. + StringResult pactffi_generate_regex_value( + ffi.Pointer regex, + ) { + return _pactffi_generate_regex_value( + regex, + ); + } + + late final _pactffi_generate_regex_valuePtr = + _lookup)>>( + 'pactffi_generate_regex_value'); + late final _pactffi_generate_regex_value = _pactffi_generate_regex_valuePtr + .asFunction)>(); + + /// [DEPRECATED] Frees the memory allocated to a string by another function + /// + /// This function is deprecated. Use `pactffi_string_delete` instead. + /// + /// # Safety + /// + /// The string pointer can be NULL (which is a no-op), but if it is not a valid pointer the call + /// will result in undefined behaviour. + void pactffi_free_string( + ffi.Pointer s, + ) { + return _pactffi_free_string( + s, + ); + } + + late final _pactffi_free_stringPtr = + _lookup)>>( + 'pactffi_free_string'); + late final _pactffi_free_string = _pactffi_free_stringPtr + .asFunction)>(); + + /// Creates a new Pact model and returns a handle to it. + /// + /// * `consumer_name` - The name of the consumer for the pact. + /// * `provider_name` - The name of the provider for the pact. + /// + /// Returns a new `PactHandle`. The handle will need to be freed with the `pactffi_free_pact_handle` + /// method to release its resources. + int pactffi_new_pact( + ffi.Pointer consumer_name, + ffi.Pointer provider_name, + ) { + return _pactffi_new_pact( + consumer_name, + provider_name, + ); + } + + late final _pactffi_new_pactPtr = _lookup< + ffi.NativeFunction< + PactHandle Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_new_pact'); + late final _pactffi_new_pact = _pactffi_new_pactPtr + .asFunction, ffi.Pointer)>(); + + /// Returns a mutable pointer to a Pact model which has been cloned from the Pact handle's inner + /// Pact model. The returned Pact model must be freed with the `pactffi_pact_model_delete` + /// function when no longer needed. + ffi.Pointer pactffi_pact_handle_to_pointer( + int pact, + ) { + return _pactffi_pact_handle_to_pointer( + pact, + ); + } + + late final _pactffi_pact_handle_to_pointerPtr = + _lookup Function(PactHandle)>>( + 'pactffi_pact_handle_to_pointer'); + late final _pactffi_pact_handle_to_pointer = + _pactffi_pact_handle_to_pointerPtr + .asFunction Function(int)>(); + + /// Creates a new HTTP Interaction and returns a handle to it. Calling this function with the + /// same description as an existing interaction will result in that interaction being replaced + /// with the new one. + /// + /// * `description` - The interaction description. It needs to be unique for each interaction. + /// + /// Returns a new `InteractionHandle`. + int pactffi_new_interaction( + int pact, + ffi.Pointer description, + ) { + return _pactffi_new_interaction( + pact, + description, + ); + } + + late final _pactffi_new_interactionPtr = _lookup< + ffi.NativeFunction< + InteractionHandle Function( + PactHandle, ffi.Pointer)>>('pactffi_new_interaction'); + late final _pactffi_new_interaction = _pactffi_new_interactionPtr + .asFunction)>(); + + /// Creates a new message interaction and returns a handle to it. Calling this function with the + /// same description as an existing interaction will result in that interaction being replaced + /// with the new one. + /// + /// * `description` - The interaction description. It needs to be unique for each interaction. + /// + /// Returns a new `InteractionHandle`. + int pactffi_new_message_interaction( + int pact, + ffi.Pointer description, + ) { + return _pactffi_new_message_interaction( + pact, + description, + ); + } + + late final _pactffi_new_message_interactionPtr = _lookup< + ffi.NativeFunction< + InteractionHandle Function(PactHandle, + ffi.Pointer)>>('pactffi_new_message_interaction'); + late final _pactffi_new_message_interaction = + _pactffi_new_message_interactionPtr + .asFunction)>(); + + /// Creates a new synchronous message interaction (request/response) and returns a handle to it. + /// Calling this function with the same description as an existing interaction will result in + /// that interaction being replaced with the new one. + /// + /// * `description` - The interaction description. It needs to be unique for each interaction. + /// + /// Returns a new `InteractionHandle`. + int pactffi_new_sync_message_interaction( + int pact, + ffi.Pointer description, + ) { + return _pactffi_new_sync_message_interaction( + pact, + description, + ); + } + + late final _pactffi_new_sync_message_interactionPtr = _lookup< + ffi.NativeFunction< + InteractionHandle Function(PactHandle, + ffi.Pointer)>>('pactffi_new_sync_message_interaction'); + late final _pactffi_new_sync_message_interaction = + _pactffi_new_sync_message_interactionPtr + .asFunction)>(); + + /// Sets the description for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `description` - The interaction description. It needs to be unique for each interaction. + bool pactffi_upon_receiving( + int interaction, + ffi.Pointer description, + ) { + return _pactffi_upon_receiving( + interaction, + description, + ); + } + + late final _pactffi_upon_receivingPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, + ffi.Pointer)>>('pactffi_upon_receiving'); + late final _pactffi_upon_receiving = _pactffi_upon_receivingPtr + .asFunction)>(); + + /// Adds a provider state to the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `description` - The provider state description. It needs to be unique. + bool pactffi_given( + int interaction, + ffi.Pointer description, + ) { + return _pactffi_given( + interaction, + description, + ); + } + + late final _pactffi_givenPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + InteractionHandle, ffi.Pointer)>>('pactffi_given'); + late final _pactffi_given = + _pactffi_givenPtr.asFunction)>(); + + /// Sets the test name annotation for the interaction. This allows capturing the name of + /// the test as metadata. This can only be used with V4 interactions. + /// + /// # Safety + /// + /// The test name parameter must be a valid pointer to a NULL terminated string. + /// + /// # Error Handling + /// + /// If the test name can not be set, this will return a positive value. + /// + /// * `1` - Function panicked. Error message will be available by calling `pactffi_get_error_message`. + /// * `2` - Handle was not valid. + /// * `3` - Mock server was already started and the integration can not be modified. + /// * `4` - Not a V4 interaction. + int pactffi_interaction_test_name( + int interaction, + ffi.Pointer test_name, + ) { + return _pactffi_interaction_test_name( + interaction, + test_name, + ); + } + + late final _pactffi_interaction_test_namePtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function(InteractionHandle, + ffi.Pointer)>>('pactffi_interaction_test_name'); + late final _pactffi_interaction_test_name = _pactffi_interaction_test_namePtr + .asFunction)>(); + + /// Adds a parameter key and value to a provider state to the Interaction. If the provider state + /// does not exist, a new one will be created, otherwise the parameter will be merged into the + /// existing one. The parameter value will be parsed as JSON. + /// + /// Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has + /// already started). + /// + /// # Parameters + /// * `description` - The provider state description. It needs to be unique. + /// * `name` - Parameter name. + /// * `value` - Parameter value as JSON. + bool pactffi_given_with_param( + int interaction, + ffi.Pointer description, + ffi.Pointer name, + ffi.Pointer value, + ) { + return _pactffi_given_with_param( + interaction, + description, + name, + value, + ); + } + + late final _pactffi_given_with_paramPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + InteractionHandle, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_given_with_param'); + late final _pactffi_given_with_param = + _pactffi_given_with_paramPtr.asFunction< + bool Function(int, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Adds a provider state to the Interaction with a set of parameter key and value pairs in JSON + /// form. If the params is not an JSON object, it will add it as a single parameter with a `value` + /// key. + /// + /// # Parameters + /// * `description` - The provider state description. + /// * `params` - Parameter values as a JSON fragment. + /// + /// # Errors + /// Returns EXIT_FAILURE (1) if the interaction or Pact can't be modified (i.e. the mock server + /// for it has already started). + /// Returns 2 and sets the error message (which can be retrieved with `pactffi_get_error_message`) + /// if the parameter values con't be parsed as JSON. + /// Returns 3 if any of the C strings are not valid. + int pactffi_given_with_params( + int interaction, + ffi.Pointer description, + ffi.Pointer params, + ) { + return _pactffi_given_with_params( + interaction, + description, + params, + ); + } + + late final _pactffi_given_with_paramsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(InteractionHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_given_with_params'); + late final _pactffi_given_with_params = + _pactffi_given_with_paramsPtr.asFunction< + int Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Configures the request for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `method` - The request method. Defaults to GET. + /// * `path` - The request path. Defaults to `/`. + /// + /// To include matching rules for the path (only regex really makes sense to use), include the + /// matching rule JSON format with the value as a single JSON document. I.e. + /// + /// ```c + /// const char* value = "{\"value\":\"/path/to/100\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\/path\\/to\\/\\\\d+\"}"; + /// pactffi_with_request(handle, "GET", value); + /// ``` + /// See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + bool pactffi_with_request( + int interaction, + ffi.Pointer method, + ffi.Pointer path, + ) { + return _pactffi_with_request( + interaction, + method, + path, + ); + } + + late final _pactffi_with_requestPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_with_request'); + late final _pactffi_with_request = _pactffi_with_requestPtr.asFunction< + bool Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Configures a query parameter for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `name` - the query parameter name. + /// * `value` - the query parameter value. + /// * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values + /// + /// **DEPRECATED:** Use `pactffi_with_query_parameter_v2`, which deals with multiple values correctly + bool pactffi_with_query_parameter( + int interaction, + ffi.Pointer name, + int index, + ffi.Pointer value, + ) { + return _pactffi_with_query_parameter( + interaction, + name, + index, + value, + ); + } + + late final _pactffi_with_query_parameterPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Pointer, ffi.Size, + ffi.Pointer)>>('pactffi_with_query_parameter'); + late final _pactffi_with_query_parameter = + _pactffi_with_query_parameterPtr.asFunction< + bool Function( + int, ffi.Pointer, int, ffi.Pointer)>(); + + /// Configures a query parameter for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `name` - the query parameter name. + /// * `value` - the query parameter value. Either a simple string or a JSON document. + /// * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values + /// + /// To setup a query parameter with multiple values, you can either call this function multiple times + /// with a different index value, i.e. to create `id=2&id=3` + /// + /// ```c + /// pactffi_with_query_parameter_v2(handle, "id", 0, "2"); + /// pactffi_with_query_parameter_v2(handle, "id", 1, "3"); + /// ``` + /// + /// Or you can call it once with a JSON value that contains multiple values: + /// + /// ```c + /// const char* value = "{\"value\": [\"2\",\"3\"]}"; + /// pactffi_with_query_parameter_v2(handle, "id", 0, value); + /// ``` + /// + /// To include matching rules for the query parameter, include the matching rule JSON format with + /// the value as a single JSON document. I.e. + /// + /// ```c + /// const char* value = "{\"value\":\"2\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\\\d+\"}"; + /// pactffi_with_query_parameter_v2(handle, "id", 0, value); + /// ``` + /// See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// If you want the matching rules to apply to all values (and not just the one with the given + /// index), make sure to set the value to be an array. + /// + /// ```c + /// const char* value = "{\"value\":[\"2\"], \"pact:matcher:type\":\"regex\", \"regex\":\"\\\\d+\"}"; + /// pactffi_with_query_parameter_v2(handle, "id", 0, value); + /// ``` + /// + /// For query parameters with no value, two distinct formats are provided: + /// + /// 1. Parameters with blank values, as specified by `?foo=&bar=`, require an empty string: + /// + /// ```c + /// pactffi_with_query_parameter_v2(handle, "foo", 0, ""); + /// pactffi_with_query_parameter_v2(handle, "bar", 0, ""); + /// ``` + /// + /// 2. Parameters with no associated value, as specified by `?foo&bar`, require a NULL pointer: + /// + /// ```c + /// pactffi_with_query_parameter_v2(handle, "foo", 0, NULL); + /// pactffi_with_query_parameter_v2(handle, "bar", 0, NULL); + /// ``` + /// + /// # Safety + /// The name parameter must be a valid pointer to a NULL terminated string. If the value + /// parameter is not NULL, it must point to a valid NULL terminated string. + /// ``` + bool pactffi_with_query_parameter_v2( + int interaction, + ffi.Pointer name, + int index, + ffi.Pointer value, + ) { + return _pactffi_with_query_parameter_v2( + interaction, + name, + index, + value, + ); + } + + late final _pactffi_with_query_parameter_v2Ptr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Pointer, ffi.Size, + ffi.Pointer)>>('pactffi_with_query_parameter_v2'); + late final _pactffi_with_query_parameter_v2 = + _pactffi_with_query_parameter_v2Ptr.asFunction< + bool Function( + int, ffi.Pointer, int, ffi.Pointer)>(); + + /// Sets the specification version for a given Pact model. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) or the version is invalid. + /// + /// * `pact` - Handle to a Pact model + /// * `version` - the spec version to use + bool pactffi_with_specification( + int pact, + int version, + ) { + return _pactffi_with_specification( + pact, + version, + ); + } + + late final _pactffi_with_specificationPtr = + _lookup>( + 'pactffi_with_specification'); + late final _pactffi_with_specification = + _pactffi_with_specificationPtr.asFunction(); + + /// Returns the Pact specification enum that the Pact is for. + int pactffi_handle_get_pact_spec_version( + int pact, + ) { + return _pactffi_handle_get_pact_spec_version( + pact, + ); + } + + late final _pactffi_handle_get_pact_spec_versionPtr = + _lookup>( + 'pactffi_handle_get_pact_spec_version'); + late final _pactffi_handle_get_pact_spec_version = + _pactffi_handle_get_pact_spec_versionPtr.asFunction(); + + /// Sets the additional metadata on the Pact file. Common uses are to add the client library + /// details such as the name and version. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) or the namespace is readonly. + /// + /// * `pact` - Handle to a Pact model + /// * `namespace` - the top level metadata key to set any key values on + /// * `name` - the key to set + /// * `value` - the value to set + bool pactffi_with_pact_metadata( + int pact, + ffi.Pointer namespace_, + ffi.Pointer name, + ffi.Pointer value, + ) { + return _pactffi_with_pact_metadata( + pact, + namespace_, + name, + value, + ); + } + + late final _pactffi_with_pact_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + PactHandle, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_with_pact_metadata'); + late final _pactffi_with_pact_metadata = + _pactffi_with_pact_metadataPtr.asFunction< + bool Function(int, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Adds metadata to the interaction. + /// + /// Metadata is only relevant for message interactions to provide additional + /// information about the message, such as the queue name, message type, tags, + /// timestamps, etc. + /// + /// * `key` - metadata key + /// * `value` - metadata value, supports JSON structures with matchers and + /// generators. Passing a `NULL` point will remove the metadata key instead. + /// * `part` - the part of the interaction to add the metadata to (only + /// relevant for synchronous message interactions). + /// + /// Returns `true` if the metadata was added successfully, `false` otherwise. + /// + /// To include matching rules for the value, include the matching rule JSON + /// format with the value as a single JSON document. I.e. + /// + /// ```c + /// const char* value = "{\"value\": { \"ID\": \"sjhdjkshsdjh\", \"weight\": 100.5 }, \"pact:matcher:type\":\"type\"}"; + /// pactffi_message_with_metadata_v2(handle, "TagData", value); + /// ``` + /// + /// See + /// [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// # Note + /// + /// For HTTP interactions, use [`pactffi_with_header_v2`] instead. This + /// function will not have any effect on HTTP interactions and returns + /// `false`. + /// + /// For synchronous message interactions, the `part` parameter is required to + /// specify whether the metadata should be added to the request or response + /// part. For responses which can have multiple messages, the metadata will be + /// set on all response messages. This also requires for responses to have + /// been defined in the interaction. + /// + /// The [`pactffi_with_body`] will also contribute to the metadata of the + /// message (both sync and async) by setting the key `contentType` with the + /// content type of the message. + /// + /// # Safety + /// + /// The key and value parameters must be valid pointers to NULL terminated + /// strings, or `NULL` for the value parameter if the metadata key should be + /// removed. + bool pactffi_with_metadata( + int interaction, + ffi.Pointer key, + ffi.Pointer value, + int part1, + ) { + return _pactffi_with_metadata( + interaction, + key, + value, + part1, + ); + } + + late final _pactffi_with_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Pointer, + ffi.Pointer, ffi.Int32)>>('pactffi_with_metadata'); + late final _pactffi_with_metadata = _pactffi_with_metadataPtr.asFunction< + bool Function(int, ffi.Pointer, ffi.Pointer, int)>(); + + /// Configures a header for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `part` - The part of the interaction to add the header to (Request or Response). + /// * `name` - the header name. + /// * `value` - the header value. + /// * `index` - the index of the value (starts at 0). You can use this to create a header with multiple values + /// + /// **DEPRECATED:** Use `pactffi_with_header_v2`, which deals with multiple values correctly + bool pactffi_with_header( + int interaction, + int part1, + ffi.Pointer name, + int index, + ffi.Pointer value, + ) { + return _pactffi_with_header( + interaction, + part1, + name, + index, + value, + ); + } + + late final _pactffi_with_headerPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Size, ffi.Pointer)>>('pactffi_with_header'); + late final _pactffi_with_header = _pactffi_with_headerPtr.asFunction< + bool Function( + int, int, ffi.Pointer, int, ffi.Pointer)>(); + + /// Configures a header for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `part` - The part of the interaction to add the header to (Request or Response). + /// * `name` - the header name. + /// * `value` - the header value. + /// * `index` - the index of the value (starts at 0). You can use this to create a header with multiple values + /// + /// To setup a header with multiple values, you can either call this function multiple times + /// with a different index value, i.e. to create `x-id=2, 3` + /// + /// ```c + /// pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 0, "2"); + /// pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 1, "3"); + /// ``` + /// + /// Or you can call it once with a JSON value that contains multiple values: + /// + /// ```c + /// const char* value = "{\"value\": [\"2\",\"3\"]}"; + /// pactffi_with_header_v2(handle, InteractionPart::Request, "x-id", 0, value); + /// ``` + /// + /// To include matching rules for the header, include the matching rule JSON format with + /// the value as a single JSON document. I.e. + /// + /// ```c + /// const char* value = "{\"value\":\"2\", \"pact:matcher:type\":\"regex\", \"regex\":\"\\\\d+\"}"; + /// pactffi_with_header_v2(handle, InteractionPart::Request, "id", 0, value); + /// ``` + /// See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// NOTE: If you pass in a form with multiple values, the index will be ignored. + /// + /// # Safety + /// The name and value parameters must be valid pointers to NULL terminated strings. + bool pactffi_with_header_v2( + int interaction, + int part1, + ffi.Pointer name, + int index, + ffi.Pointer value, + ) { + return _pactffi_with_header_v2( + interaction, + part1, + name, + index, + value, + ); + } + + late final _pactffi_with_header_v2Ptr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Size, ffi.Pointer)>>('pactffi_with_header_v2'); + late final _pactffi_with_header_v2 = _pactffi_with_header_v2Ptr.asFunction< + bool Function( + int, int, ffi.Pointer, int, ffi.Pointer)>(); + + /// Sets a header for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started). Note that this function will + /// overwrite any previously set header values. Also, this function will not process the value in + /// any way, so matching rules and generators can not be configured with it. + /// + /// If matching rules are required to be set, use `pactffi_with_header_v2`. + /// + /// * `part` - The part of the interaction to add the header to (Request or Response). + /// * `name` - the header name. + /// * `value` - the header value. + /// + /// # Safety + /// The name and value parameters must be valid pointers to NULL terminated strings. + bool pactffi_set_header( + int interaction, + int part1, + ffi.Pointer name, + ffi.Pointer value, + ) { + return _pactffi_set_header( + interaction, + part1, + name, + value, + ); + } + + late final _pactffi_set_headerPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Pointer)>>('pactffi_set_header'); + late final _pactffi_set_header = _pactffi_set_headerPtr.asFunction< + bool Function(int, int, ffi.Pointer, ffi.Pointer)>(); + + /// Configures the response for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `status` - the response status. Defaults to 200. + bool pactffi_response_status( + int interaction, + int status, + ) { + return _pactffi_response_status( + interaction, + status, + ); + } + + late final _pactffi_response_statusPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, + ffi.UnsignedShort)>>('pactffi_response_status'); + late final _pactffi_response_status = + _pactffi_response_statusPtr.asFunction(); + + /// Configures the response for the Interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `status` - the response status. Defaults to 200. + /// + /// To include matching rules for the status (only statusCode or integer really makes sense to use), include the + /// matching rule JSON format with the value as a single JSON document. I.e. + /// + /// ```c + /// const char* status = "{ \"pact:generator:type\": \"RandomInt\", \"min\": 100, \"max\": 399, \"pact:matcher:type\":\"statusCode\", \"status\": \"nonError\"}"; + /// pactffi_response_status_v2(handle, status); + /// ``` + /// See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// # Safety + /// The status parameter must be valid pointers to NULL terminated strings. + bool pactffi_response_status_v2( + int interaction, + ffi.Pointer status, + ) { + return _pactffi_response_status_v2( + interaction, + status, + ); + } + + late final _pactffi_response_status_v2Ptr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, + ffi.Pointer)>>('pactffi_response_status_v2'); + late final _pactffi_response_status_v2 = _pactffi_response_status_v2Ptr + .asFunction)>(); + + /// Adds the body for the interaction. Returns false if the interaction or Pact + /// can't be modified (i.e. the mock server for it has already started) + /// + /// * `part` - The part of the interaction to add the body to (Request or + /// Response). This is ignored for asynchronous message interactions. + /// * `content_type` - The content type of the body, or `NULL` to use the + /// internal logic. + /// * `body` - The body contents. For JSON payloads, matching rules can be + /// embedded in the body. See + /// [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// If the `content_type` is determined as follows, whichever is first: + /// + /// - The `content_type` argument to this function + /// - The `Content-Type` header for HTTP interaction, or `contentType` metadata + /// entry for message interactions. + /// - From automatic detection of the body contents. + /// - Defaults to `text/plain` as a last resort. + /// + /// Furthermore, the `Content-Type` header or `contentType` metadata entry will + /// be updated with the above determined content type, _unless_ it is already + /// set. + /// + /// This function will overwrite the body contents if they exist, with the + /// exception of the response part of synchronous message interactions, where a + /// new response will be appended. + /// + /// # Safety + /// + /// The interaction contents and content type must either be NULL pointers, or + /// point to valid UTF-8 encoded NULL-terminated strings. Otherwise, behaviour + /// is undefined. + /// + /// # Error Handling + /// + /// If the contents is a NULL pointer, it will set the body contents as null. If + /// the content type is a null pointer, or can't be parsed, it will set the + /// content type as TEXT. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) or an error has + /// occurred. + bool pactffi_with_body( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer body, + ) { + return _pactffi_with_body( + interaction, + part1, + content_type, + body, + ); + } + + late final _pactffi_with_bodyPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Pointer)>>('pactffi_with_body'); + late final _pactffi_with_body = _pactffi_with_bodyPtr.asFunction< + bool Function(int, int, ffi.Pointer, ffi.Pointer)>(); + + /// Adds the body for the interaction. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `part` - The part of the interaction to add the body to (Request or Response). + /// * `content_type` - The content type of the body. Defaults to `application/octet-stream` if it + /// is NULL. Will be ignored if a content type header is already set. + /// * `body` - Body contents as a pointer to a byte array + /// * `size` - Number of bytes in the body + /// + /// For HTTP and async message interactions, this will overwrite the body. With asynchronous messages, the + /// part parameter will be ignored. With synchronous messages, the request contents will be overwritten, + /// while a new response will be appended to the message. + /// + /// # Safety + /// + /// This function is safe to use as long as the following conditions are true: + /// The content type must either be a NULL pointer, or point to valid UTF-8 encoded NULL-terminated + /// string. The body pointer must be valid for reads of `size` bytes, and it must be properly + /// aligned and consecutive (that just means it must point a continuous array of at least `size` + /// bytes that can be read in a single operation and not to non-continuous structures like linked + /// lists, etc.). + /// + /// # Error Handling + /// + /// If the body is a NULL pointer, it will set the body contents as empty. If the content + /// type is a null pointer, it will set the content type as `application/octet-stream`. + /// Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has + /// already started) or an error has occurred. + bool pactffi_with_binary_body( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer body, + int size, + ) { + return _pactffi_with_binary_body( + interaction, + part1, + content_type, + body, + size, + ); + } + + late final _pactffi_with_binary_bodyPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Pointer, ffi.Size)>>('pactffi_with_binary_body'); + late final _pactffi_with_binary_body = + _pactffi_with_binary_bodyPtr.asFunction< + bool Function( + int, int, ffi.Pointer, ffi.Pointer, int)>(); + + ///
+ /// + /// This function is deprecated. Use [`pactffi_with_binary_body`] in order to + /// set the binary body, and use [`pactffi_with_matching_rules`] to set the + /// matching rules to ensure that only the content type is being matched. + /// + ///
+ /// + /// Adds a binary file as the body with the expected content type and example contents. Will use + /// a mime type matcher to match the body. Returns false if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) + /// + /// * `interaction` - Interaction handle to set the body for. + /// * `part` - Request or response part. + /// * `content_type` - Expected content type. + /// * `body` - example body contents in bytes + /// * `size` - number of bytes in the body + /// + /// For HTTP and async message interactions, this will overwrite the body. With asynchronous messages, the + /// part parameter will be ignored. With synchronous messages, the request contents will be overwritten, + /// while a new response will be appended to the message. + /// + /// # Safety + /// + /// The content type must be a valid UTF-8 encoded NULL-terminated string. The body pointer must + /// be valid for reads of `size` bytes, and it must be properly aligned and consecutive. + /// + /// # Error Handling + /// + /// If the body is a NULL pointer, it will set the body contents as null. If the content + /// type is a null pointer, or can't be parsed, it will return false. + /// Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has + /// already started) or an error has occurred. + bool pactffi_with_binary_file( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer body, + int size, + ) { + return _pactffi_with_binary_file( + interaction, + part1, + content_type, + body, + size, + ); + } + + late final _pactffi_with_binary_filePtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, ffi.Pointer, + ffi.Pointer, ffi.Size)>>('pactffi_with_binary_file'); + late final _pactffi_with_binary_file = + _pactffi_with_binary_filePtr.asFunction< + bool Function( + int, int, ffi.Pointer, ffi.Pointer, int)>(); + + /// Add matching rules to the interaction. + /// + /// * `interaction` - Interaction handle to set the matching rules for. + /// * `part` - Request or response part (if applicable). + /// * `rules` - JSON string of the matching rules to add to the interaction. + /// + /// This function can be called multiple times, in which case the matching + /// rules will be merged. The function will return `true` if the rules were + /// successfully added, and `false` if an error occurred. + /// + /// For synchronous messages which allow multiple responses, the matching + /// rules will be added to all the responses. + /// + /// # Safety + /// + /// The rules parameter must be a valid pointer to a NULL terminated UTF-8 + /// string. + bool pactffi_with_matching_rules( + int interaction, + int part1, + ffi.Pointer rules, + ) { + return _pactffi_with_matching_rules( + interaction, + part1, + rules, + ); + } + + late final _pactffi_with_matching_rulesPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, + ffi.Pointer)>>('pactffi_with_matching_rules'); + late final _pactffi_with_matching_rules = _pactffi_with_matching_rulesPtr + .asFunction)>(); + + /// Add generators to the interaction. + /// + /// * `interaction` - Interaction handle to set the generators for. + /// * `part` - Request or response part (if applicable). + /// * `generators` - JSON string of the generators to add to the interaction. + /// + /// This function can be called multiple times, in which case the generators + /// will be combined (provided they don't clash). The function will return + /// `true` if the rules were successfully added, and `false` if an error + /// occurred. + /// + /// For synchronous messages which allow multiple responses, the generators + /// will be added to all the responses. + /// + /// # Safety + /// + /// The generators parameter must be a valid pointer to a NULL terminated + /// UTF-8 string. + bool pactffi_with_generators( + int interaction, + int part1, + ffi.Pointer generators, + ) { + return _pactffi_with_generators( + interaction, + part1, + generators, + ); + } + + late final _pactffi_with_generatorsPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Int32, + ffi.Pointer)>>('pactffi_with_generators'); + late final _pactffi_with_generators = _pactffi_with_generatorsPtr + .asFunction)>(); + + /// Adds a binary file as the body as a MIME multipart with the expected content type and example contents. Will use + /// a mime type matcher to match the body. Returns an error if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) or an error occurs. + /// + /// * `interaction` - Interaction handle to set the body for. + /// * `part` - Request or response part. + /// * `content_type` - Expected content type of the file. + /// * `file` - path to the example file + /// * `part_name` - name for the mime part + /// * `boundary` - boundary for the multipart separation + /// + /// This function can be called multiple times. In that case, each subsequent call will be + /// appended to the existing multipart body as a new part. + /// + /// # Safety + /// + /// The content type, file path and part name must be valid pointers to UTF-8 encoded NULL-terminated strings. + /// Passing invalid pointers or pointers to strings that are not NULL terminated will lead to undefined + /// behaviour. + /// + /// # Error Handling + /// + /// If the boundary is a NULL pointer, a random string will be used. + /// If the file path is a NULL pointer, it will set the body contents as as an empty mime-part. + /// If the file path does not point to a valid file, or is not able to be read, it will return an + /// error result. If the content type is a null pointer, or can't be parsed, it will return an error result. + /// Returns an error if the interaction or Pact can't be modified (i.e. the mock server for it has + /// already started), the interaction is not an HTTP interaction or some other error occurs. + StringResult pactffi_with_multipart_file_v2( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer file, + ffi.Pointer part_name, + ffi.Pointer boundary, + ) { + return _pactffi_with_multipart_file_v2( + interaction, + part1, + content_type, + file, + part_name, + boundary, + ); + } + + late final _pactffi_with_multipart_file_v2Ptr = _lookup< + ffi.NativeFunction< + StringResult Function( + InteractionHandle, + ffi.Int32, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_with_multipart_file_v2'); + late final _pactffi_with_multipart_file_v2 = + _pactffi_with_multipart_file_v2Ptr.asFunction< + StringResult Function( + int, + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + /// Adds a binary file as the body as a MIME multipart with the expected content type and example contents. Will use + /// a mime type matcher to match the body. Returns an error if the interaction or Pact can't be + /// modified (i.e. the mock server for it has already started) or an error occurs. + /// + /// * `interaction` - Interaction handle to set the body for. + /// * `part` - Request or response part. + /// * `content_type` - Expected content type of the file. + /// * `file` - path to the example file + /// * `part_name` - name for the mime part + /// + /// This function can be called multiple times. In that case, each subsequent call will be + /// appended to the existing multipart body as a new part. + /// + /// # Safety + /// + /// The content type, file path and part name must be valid pointers to UTF-8 encoded NULL-terminated strings. + /// Passing invalid pointers or pointers to strings that are not NULL terminated will lead to undefined + /// behaviour. + /// + /// # Error Handling + /// + /// If the file path is a NULL pointer, it will set the body contents as as an empty mime-part. + /// If the file path does not point to a valid file, or is not able to be read, it will return an + /// error result. If the content type is a null pointer, or can't be parsed, it will return an error result. + /// Returns an error if the interaction or Pact can't be modified (i.e. the mock server for it has + /// already started), the interaction is not an HTTP interaction or some other error occurs. + StringResult pactffi_with_multipart_file( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer file, + ffi.Pointer part_name, + ) { + return _pactffi_with_multipart_file( + interaction, + part1, + content_type, + file, + part_name, + ); + } + + late final _pactffi_with_multipart_filePtr = _lookup< + ffi.NativeFunction< + StringResult Function( + InteractionHandle, + ffi.Int32, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_with_multipart_file'); + late final _pactffi_with_multipart_file = + _pactffi_with_multipart_filePtr.asFunction< + StringResult Function(int, int, ffi.Pointer, + ffi.Pointer, ffi.Pointer)>(); + + /// Sets the key attribute for the interaction. + /// + /// * `interaction` - Interaction handle to modify. + /// * `value` - Key value. This must be a valid UTF-8 null-terminated string, + /// or NULL to clear the key. + /// + /// This function will return `true` if the key was successfully updated. + /// + /// # Safety + /// + /// The key parameter must be a valid pointer to a NULL terminated UTF-8, or + /// NULL if the key is to be cleared. + bool pactffi_set_key( + int interaction, + ffi.Pointer value, + ) { + return _pactffi_set_key( + interaction, + value, + ); + } + + late final _pactffi_set_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + InteractionHandle, ffi.Pointer)>>('pactffi_set_key'); + late final _pactffi_set_key = _pactffi_set_keyPtr + .asFunction)>(); + + /// Mark the interaction as pending. + /// + /// * `interaction` - Interaction handle to modify. + /// * `pending` - Boolean value to toggle the pending state of the interaction. + /// + /// This function will return `true` if the key was successfully updated. + bool pactffi_set_pending( + int interaction, + bool pending, + ) { + return _pactffi_set_pending( + interaction, + pending, + ); + } + + late final _pactffi_set_pendingPtr = _lookup< + ffi.NativeFunction>( + 'pactffi_set_pending'); + late final _pactffi_set_pending = + _pactffi_set_pendingPtr.asFunction(); + + /// Add a comment to the interaction. + /// + /// * `interaction` - Interaction handle to set the comments for. + /// * `key` - Key value + /// * `value` - Comment value. This may be any valid JSON value, or a NULL to + /// clear the comment. + /// + /// This function will return `true` if the comments were successfully + /// updated. Both `key` and `value` must be valid UTF-8 null-terminated + /// strings; or in the case of `value`, it may also be a NULL pointer in which + /// case the comment will be cleared. + /// + /// Note that a `value` that deserialize to a JSON null will result in a + /// comment being added, with the value being the JSON null. + /// + /// Note that the `text` key is special and is used by + /// [`pactffi_add_text_comment`] to append comments to the array of comments. + /// Overwriting the `text` key is allowed, but should be done with caution. + /// + /// # Safety + /// + /// The key parameter must be a valid pointer to a NULL terminated UTF-8. + /// The value parameter must be a valid pointer to a NULL terminated UTF-8, + /// or NULL if the comment is to be cleared. + bool pactffi_set_comment( + int interaction, + ffi.Pointer key, + ffi.Pointer value, + ) { + return _pactffi_set_comment( + interaction, + key, + value, + ); + } + + late final _pactffi_set_commentPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_set_comment'); + late final _pactffi_set_comment = _pactffi_set_commentPtr.asFunction< + bool Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Add a text comment to the interaction. + /// + /// * `interaction` - Interaction handle to set the comments for. + /// * `comment` - Comment value. + /// + /// This function will return `true` if the comments were successfully + /// updated. The `comment` must be a valid UTF-8 null-terminated string. + /// + /// Unlike [`pactffi_set_comment`], this function will always append the + /// comment to the array of comments under the `text` key. + /// + /// If, for any reason, the `text` key is not present or the associated + /// value not an array, it will be created as/replaced by an array and the + /// comment will be appended to it. + /// + /// # Safety + /// + /// The comment parameter must be a valid pointer to a NULL terminated UTF-8. + bool pactffi_add_text_comment( + int interaction, + ffi.Pointer comment, + ) { + return _pactffi_add_text_comment( + interaction, + comment, + ); + } + + late final _pactffi_add_text_commentPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(InteractionHandle, + ffi.Pointer)>>('pactffi_add_text_comment'); + late final _pactffi_add_text_comment = _pactffi_add_text_commentPtr + .asFunction)>(); + + /// Get an iterator over all the messages of the Pact. The returned iterator needs to be + /// freed with `pactffi_pact_message_iter_delete`. + /// + /// # Safety + /// + /// The iterator contains a copy of the Pact, so it is always safe to use. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_pact_handle_get_message_iter( + int pact, + ) { + return _pactffi_pact_handle_get_message_iter( + pact, + ); + } + + late final _pactffi_pact_handle_get_message_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + PactHandle)>>('pactffi_pact_handle_get_message_iter'); + late final _pactffi_pact_handle_get_message_iter = + _pactffi_pact_handle_get_message_iterPtr + .asFunction Function(int)>(); + + /// Get an iterator over all the asynchronous messages of the Pact. + /// The returned iterator needs to be freed with `pactffi_pact_async_message_iter_delete`. + /// + /// # Safety + /// + /// The iterator contains a copy of the Pact, so it is always safe to use. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain embedded + /// null ('\0') bytes. + ffi.Pointer + pactffi_pact_handle_get_async_message_iter( + int pact, + ) { + return _pactffi_pact_handle_get_async_message_iter( + pact, + ); + } + + late final _pactffi_pact_handle_get_async_message_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + PactHandle)>>('pactffi_pact_handle_get_async_message_iter'); + late final _pactffi_pact_handle_get_async_message_iter = + _pactffi_pact_handle_get_async_message_iterPtr + .asFunction Function(int)>(); + + /// Get an iterator over all the synchronous request/response messages of the Pact. + /// The returned iterator needs to be freed with `pactffi_pact_sync_message_iter_delete`. + /// + /// # Safety + /// + /// The iterator contains a copy of the Pact, so it is always safe to use. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain embedded + /// null ('\0') bytes. + ffi.Pointer + pactffi_pact_handle_get_sync_message_iter( + int pact, + ) { + return _pactffi_pact_handle_get_sync_message_iter( + pact, + ); + } + + late final _pactffi_pact_handle_get_sync_message_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + PactHandle)>>('pactffi_pact_handle_get_sync_message_iter'); + late final _pactffi_pact_handle_get_sync_message_iter = + _pactffi_pact_handle_get_sync_message_iterPtr + .asFunction Function(int)>(); + + /// Get an iterator over all the synchronous HTTP request/response interactions of the Pact. + /// The returned iterator needs to be freed with `pactffi_pact_sync_http_iter_delete`. + /// + /// # Safety + /// + /// The iterator contains a copy of the Pact, so it is always safe to use. + /// + /// # Error Handling + /// + /// On failure, this function will return a NULL pointer. + /// + /// This function may fail if any of the Rust strings contain embedded + /// null ('\0') bytes. + ffi.Pointer pactffi_pact_handle_get_sync_http_iter( + int pact, + ) { + return _pactffi_pact_handle_get_sync_http_iter( + pact, + ); + } + + late final _pactffi_pact_handle_get_sync_http_iterPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + PactHandle)>>('pactffi_pact_handle_get_sync_http_iter'); + late final _pactffi_pact_handle_get_sync_http_iter = + _pactffi_pact_handle_get_sync_http_iterPtr + .asFunction Function(int)>(); + + /// Creates a new Pact Message model and returns a handle to it. + /// + /// * `consumer_name` - The name of the consumer for the pact. + /// * `provider_name` - The name of the provider for the pact. + /// + /// Returns a new `MessagePactHandle`. The handle will need to be freed with the `pactffi_free_message_pact_handle` + /// function to release its resources. + int pactffi_new_message_pact( + ffi.Pointer consumer_name, + ffi.Pointer provider_name, + ) { + return _pactffi_new_message_pact( + consumer_name, + provider_name, + ); + } + + late final _pactffi_new_message_pactPtr = _lookup< + ffi.NativeFunction< + MessagePactHandle Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_new_message_pact'); + late final _pactffi_new_message_pact = _pactffi_new_message_pactPtr + .asFunction, ffi.Pointer)>(); + + /// Creates a new Message and returns a handle to it. + /// + /// * `description` - The message description. It needs to be unique for each Message. + /// + /// Returns a new `MessageHandle`. + int pactffi_new_message( + int pact, + ffi.Pointer description, + ) { + return _pactffi_new_message( + pact, + description, + ); + } + + late final _pactffi_new_messagePtr = _lookup< + ffi.NativeFunction< + MessageHandle Function(MessagePactHandle, + ffi.Pointer)>>('pactffi_new_message'); + late final _pactffi_new_message = _pactffi_new_messagePtr + .asFunction)>(); + + /// Sets the description for the Message. + /// + /// * `description` - The message description. It needs to be unique for each message. + void pactffi_message_expects_to_receive( + int message, + ffi.Pointer description, + ) { + return _pactffi_message_expects_to_receive( + message, + description, + ); + } + + late final _pactffi_message_expects_to_receivePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(MessageHandle, + ffi.Pointer)>>('pactffi_message_expects_to_receive'); + late final _pactffi_message_expects_to_receive = + _pactffi_message_expects_to_receivePtr + .asFunction)>(); + + /// Adds a provider state to the Interaction. + /// + /// * `description` - The provider state description. It needs to be unique for each message + void pactffi_message_given( + int message, + ffi.Pointer description, + ) { + return _pactffi_message_given( + message, + description, + ); + } + + late final _pactffi_message_givenPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + MessageHandle, ffi.Pointer)>>('pactffi_message_given'); + late final _pactffi_message_given = _pactffi_message_givenPtr + .asFunction)>(); + + /// Adds a parameter key and value to a provider state to the Message. If the provider state + /// does not exist, a new one will be created, otherwise the parameter will be merged into the + /// existing one. The parameter value will be parsed as JSON. + /// + /// # Parameters + /// * `description` - The provider state description. It needs to be unique. + /// * `name` - Parameter name. + /// * `value` - Parameter value as JSON. + void pactffi_message_given_with_param( + int message, + ffi.Pointer description, + ffi.Pointer name, + ffi.Pointer value, + ) { + return _pactffi_message_given_with_param( + message, + description, + name, + value, + ); + } + + late final _pactffi_message_given_with_paramPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + MessageHandle, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_message_given_with_param'); + late final _pactffi_message_given_with_param = + _pactffi_message_given_with_paramPtr.asFunction< + void Function(int, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Adds the contents of the Message. + /// + /// Accepts JSON, binary and other payload types. Binary data will be base64 encoded when serialised. + /// + /// Note: For text bodies (plain text, JSON or XML), you can pass in a C string (NULL terminated) + /// and the size of the body is not required (it will be ignored). For binary bodies, you need to + /// specify the number of bytes in the body. + /// + /// * `content_type` - The content type of the body. Defaults to `text/plain`, supports JSON structures with matchers and binary data. + /// * `body` - The body contents as bytes. For text payloads (JSON, XML, etc.), a C string can be used and matching rules can be embedded in the body. + /// * `content_type` - Expected content type (e.g. application/json, application/octet-stream) + /// * `size` - number of bytes in the message body to read. This is not required for text bodies (JSON, XML, etc.). + void pactffi_message_with_contents( + int message_handle, + ffi.Pointer content_type, + ffi.Pointer body, + int size, + ) { + return _pactffi_message_with_contents( + message_handle, + content_type, + body, + size, + ); + } + + late final _pactffi_message_with_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + MessageHandle, + ffi.Pointer, + ffi.Pointer, + ffi.Size)>>('pactffi_message_with_contents'); + late final _pactffi_message_with_contents = + _pactffi_message_with_contentsPtr.asFunction< + void Function( + int, ffi.Pointer, ffi.Pointer, int)>(); + + /// Adds expected metadata to the Message + /// + /// * `key` - metadata key + /// * `value` - metadata value. + void pactffi_message_with_metadata( + int message_handle, + ffi.Pointer key, + ffi.Pointer value, + ) { + return _pactffi_message_with_metadata( + message_handle, + key, + value, + ); + } + + late final _pactffi_message_with_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(MessageHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_message_with_metadata'); + late final _pactffi_message_with_metadata = + _pactffi_message_with_metadataPtr.asFunction< + void Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Adds expected metadata to the Message + /// + /// * `key` - metadata key + /// * `value` - metadata value, supports JSON structures with matchers and generators + /// + /// To include matching rules for the value, include the + /// matching rule JSON format with the value as a single JSON document. I.e. + /// + /// ```c + /// const char* value = "{\"value\": { \"ID\": \"sjhdjkshsdjh\", \"weight\": 100.5 }, \"pact:matcher:type\":\"type\"}"; + /// pactffi_message_with_metadata_v2(handle, "TagData", value); + /// ``` + /// See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + /// + /// # Safety + /// The key and value parameters must be valid pointers to NULL terminated strings. + void pactffi_message_with_metadata_v2( + int message_handle, + ffi.Pointer key, + ffi.Pointer value, + ) { + return _pactffi_message_with_metadata_v2( + message_handle, + key, + value, + ); + } + + late final _pactffi_message_with_metadata_v2Ptr = _lookup< + ffi.NativeFunction< + ffi.Void Function(MessageHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_message_with_metadata_v2'); + late final _pactffi_message_with_metadata_v2 = + _pactffi_message_with_metadata_v2Ptr.asFunction< + void Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Reifies the given message + /// + /// Reification is the process of stripping away any matchers, and returning the original contents. + /// + /// # Safety + /// + /// The returned string needs to be deallocated with the `free_string` function. + /// This function must only ever be called from a foreign language. Calling it from a Rust function + /// that has a Tokio runtime in its call stack can result in a deadlock. + ffi.Pointer pactffi_message_reify( + int message_handle, + ) { + return _pactffi_message_reify( + message_handle, + ); + } + + late final _pactffi_message_reifyPtr = _lookup< + ffi.NativeFunction Function(MessageHandle)>>( + 'pactffi_message_reify'); + late final _pactffi_message_reify = _pactffi_message_reifyPtr + .asFunction Function(int)>(); + + /// External interface to write out the message pact file. This function should + /// be called if all the consumer tests have passed. The directory to write the file to is passed + /// as the second parameter. If a NULL pointer is passed, the current working directory is used. + /// + /// If overwrite is true, the file will be overwritten with the contents of the current pact. + /// Otherwise, it will be merged with any existing pact file. + /// + /// Returns 0 if the pact file was successfully written. Returns a positive code if the file can + /// not be written, or there is no mock server running on that port or the function panics. + /// + /// # Errors + /// + /// Errors are returned as positive values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | 1 | The pact file was not able to be written | + /// | 2 | The message pact for the given handle was not found | + int pactffi_write_message_pact_file( + int pact, + ffi.Pointer directory, + bool overwrite, + ) { + return _pactffi_write_message_pact_file( + pact, + directory, + overwrite, + ); + } + + late final _pactffi_write_message_pact_filePtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(MessagePactHandle, ffi.Pointer, + ffi.Bool)>>('pactffi_write_message_pact_file'); + late final _pactffi_write_message_pact_file = + _pactffi_write_message_pact_filePtr + .asFunction, bool)>(); + + /// Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version + /// + /// * `pact` - Handle to a Pact model + /// * `namespace` - the top level metadat key to set any key values on + /// * `name` - the key to set + /// * `value` - the value to set + void pactffi_with_message_pact_metadata( + int pact, + ffi.Pointer namespace_, + ffi.Pointer name, + ffi.Pointer value, + ) { + return _pactffi_with_message_pact_metadata( + pact, + namespace_, + name, + value, + ); + } + + late final _pactffi_with_message_pact_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + MessagePactHandle, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_with_message_pact_metadata'); + late final _pactffi_with_message_pact_metadata = + _pactffi_with_message_pact_metadataPtr.asFunction< + void Function(int, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// External interface to write out the pact file. This function should + /// be called if all the consumer tests have passed. The directory to write the file to is passed + /// as the second parameter. If a NULL pointer is passed, the current working directory is used. + /// + /// If overwrite is true, the file will be overwritten with the contents of the current pact. + /// Otherwise, it will be merged with any existing pact file. + /// + /// Returns 0 if the pact file was successfully written. Returns a positive code if the file can + /// not be written or the function panics. + /// + /// # Safety + /// + /// The directory parameter must either be NULL or point to a valid NULL terminated string. + /// + /// # Errors + /// + /// Errors are returned as positive values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | 1 | The function panicked. | + /// | 2 | The pact file was not able to be written. | + /// | 3 | The pact for the given handle was not found. | + int pactffi_pact_handle_write_file( + int pact, + ffi.Pointer directory, + bool overwrite, + ) { + return _pactffi_pact_handle_write_file( + pact, + directory, + overwrite, + ); + } + + late final _pactffi_pact_handle_write_filePtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(PactHandle, ffi.Pointer, + ffi.Bool)>>('pactffi_pact_handle_write_file'); + late final _pactffi_pact_handle_write_file = + _pactffi_pact_handle_write_filePtr + .asFunction, bool)>(); + + /// Creates a new V4 asynchronous message and returns a handle to it. + /// + /// * `description` - The message description. It needs to be unique for each Message. + /// + /// Returns a new `MessageHandle`. + /// + /// Note: This function is deprecated in favour of `new_message_interaction` which returns an + /// InteractionHandle that can be used for both HTTP and message interactions. + int pactffi_new_async_message( + int pact, + ffi.Pointer description, + ) { + return _pactffi_new_async_message( + pact, + description, + ); + } + + late final _pactffi_new_async_messagePtr = _lookup< + ffi.NativeFunction< + MessageHandle Function( + PactHandle, ffi.Pointer)>>('pactffi_new_async_message'); + late final _pactffi_new_async_message = _pactffi_new_async_messagePtr + .asFunction)>(); + + /// Delete a Pact handle and free the resources used by it. + /// + /// # Error Handling + /// + /// On failure, this function will return a positive integer value. + /// + /// * `1` - The handle is not valid or does not refer to a valid Pact. Could be that it was previously deleted. + int pactffi_free_pact_handle( + int pact, + ) { + return _pactffi_free_pact_handle( + pact, + ); + } + + late final _pactffi_free_pact_handlePtr = + _lookup>( + 'pactffi_free_pact_handle'); + late final _pactffi_free_pact_handle = + _pactffi_free_pact_handlePtr.asFunction(); + + /// Delete a Pact handle and free the resources used by it. + /// + /// # Error Handling + /// + /// On failure, this function will return a positive integer value. + /// + /// * `1` - The handle is not valid or does not refer to a valid Pact. Could be that it was previously deleted. + int pactffi_free_message_pact_handle( + int pact, + ) { + return _pactffi_free_message_pact_handle( + pact, + ); + } + + late final _pactffi_free_message_pact_handlePtr = + _lookup>( + 'pactffi_free_message_pact_handle'); + late final _pactffi_free_message_pact_handle = + _pactffi_free_message_pact_handlePtr.asFunction(); + + /// External interface to verifier a provider + /// + /// * `args` - the same as the CLI interface, except newline delimited + /// + /// # Errors + /// + /// Errors are returned as non-zero numeric values. + /// + /// | Error | Description | + /// |-------|-------------| + /// | 1 | The verification process failed, see output for errors | + /// | 2 | A null pointer was received | + /// | 3 | The method panicked | + /// | 4 | Invalid arguments were provided to the verification process | + /// + /// # Safety + /// + /// Exported functions are inherently unsafe. Deal. + int pactffi_verify( + ffi.Pointer args, + ) { + return _pactffi_verify( + args, + ); + } + + late final _pactffi_verifyPtr = + _lookup)>>( + 'pactffi_verify'); + late final _pactffi_verify = + _pactffi_verifyPtr.asFunction)>(); + + /// Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when + /// done with the verifier to free all allocated resources. + /// + /// By default, verification results will not be published. To enable publishing, use + /// `pactffi_verifier_set_publish_options` to set the required values and enable it. + /// + /// Deprecated: This function is deprecated. Use `pactffi_verifier_new_for_application` which allows the + /// calling application/framework name and version to be specified. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_verifier_new() { + return _pactffi_verifier_new(); + } + + late final _pactffi_verifier_newPtr = + _lookup Function()>>( + 'pactffi_verifier_new'); + late final _pactffi_verifier_new = _pactffi_verifier_newPtr + .asFunction Function()>(); + + /// Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when + /// done with the verifier to free all allocated resources. + /// + /// By default, verification results will not be published. To enable publishing, use + /// `pactffi_verifier_set_publish_options` to set the required values and enable it. + /// + /// # Safety + /// + /// This function is safe. + /// + /// # Error Handling + /// + /// Returns NULL on error. + ffi.Pointer pactffi_verifier_new_for_application( + ffi.Pointer name, + ffi.Pointer version, + ) { + return _pactffi_verifier_new_for_application( + name, + version, + ); + } + + late final _pactffi_verifier_new_for_applicationPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_new_for_application'); + late final _pactffi_verifier_new_for_application = + _pactffi_verifier_new_for_applicationPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + /// Shutdown the verifier and release all resources + void pactffi_verifier_shutdown( + ffi.Pointer handle, + ) { + return _pactffi_verifier_shutdown( + handle, + ); + } + + late final _pactffi_verifier_shutdownPtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_verifier_shutdown'); + late final _pactffi_verifier_shutdown = _pactffi_verifier_shutdownPtr + .asFunction)>(); + + /// Set the provider details for the Pact verifier. Passing a NULL for any field will + /// use the default value for that field. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_set_provider_info( + ffi.Pointer handle, + ffi.Pointer name, + ffi.Pointer scheme, + ffi.Pointer host, + int port, + ffi.Pointer path, + ) { + return _pactffi_verifier_set_provider_info( + handle, + name, + scheme, + host, + port, + path, + ); + } + + late final _pactffi_verifier_set_provider_infoPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedShort, + ffi.Pointer)>>('pactffi_verifier_set_provider_info'); + late final _pactffi_verifier_set_provider_info = + _pactffi_verifier_set_provider_infoPtr.asFunction< + void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer)>(); + + /// Adds a new transport for the given provider. Passing a NULL for any field will + /// use the default value for that field. + /// + /// For non-plugin based message interactions, set protocol to "message" and set scheme + /// to an empty string or "https" if secure HTTP is required. Communication to the calling + /// application will be over HTTP to the default provider hostname. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_add_provider_transport( + ffi.Pointer handle, + ffi.Pointer protocol, + int port, + ffi.Pointer path, + ffi.Pointer scheme, + ) { + return _pactffi_verifier_add_provider_transport( + handle, + protocol, + port, + path, + scheme, + ); + } + + late final _pactffi_verifier_add_provider_transportPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedShort, + ffi.Pointer, + ffi.Pointer)>>( + 'pactffi_verifier_add_provider_transport'); + late final _pactffi_verifier_add_provider_transport = + _pactffi_verifier_add_provider_transportPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, int, + ffi.Pointer, ffi.Pointer)>(); + + /// Set the filters for the Pact verifier. + /// + /// If `filter_description` is not empty, it needs to be as a regular expression. + /// + /// `filter_no_state` is a boolean value. Set it to greater than zero to turn the option on. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_set_filter_info( + ffi.Pointer handle, + ffi.Pointer filter_description, + ffi.Pointer filter_state, + int filter_no_state, + ) { + return _pactffi_verifier_set_filter_info( + handle, + filter_description, + filter_state, + filter_no_state, + ); + } + + late final _pactffi_verifier_set_filter_infoPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedChar)>>('pactffi_verifier_set_filter_info'); + late final _pactffi_verifier_set_filter_info = + _pactffi_verifier_set_filter_infoPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, int)>(); + + /// Set the provider state URL for the Pact verifier. + /// + /// `teardown` is a boolean value. If teardown state change requests should be made after an + /// interaction is validated (default is false). Set it to greater than zero to turn the + /// option on. + /// `body` is a boolean value. Sets if state change request data should be sent in the body + /// (> 0, true) or as query parameters (== 0, false). Set it to greater than zero to turn the + /// option on. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_set_provider_state( + ffi.Pointer handle, + ffi.Pointer url, + int teardown, + int body, + ) { + return _pactffi_verifier_set_provider_state( + handle, + url, + teardown, + body, + ); + } + + late final _pactffi_verifier_set_provider_statePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedChar, + ffi.UnsignedChar)>>('pactffi_verifier_set_provider_state'); + late final _pactffi_verifier_set_provider_state = + _pactffi_verifier_set_provider_statePtr.asFunction< + void Function( + ffi.Pointer, ffi.Pointer, int, int)>(); + + /// Set the options used by the verifier when calling the provider + /// + /// `disable_ssl_verification` is a boolean value. Set it to greater than zero to turn the option on. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + int pactffi_verifier_set_verification_options( + ffi.Pointer handle, + int disable_ssl_verification, + int request_timeout, + ) { + return _pactffi_verifier_set_verification_options( + handle, + disable_ssl_verification, + request_timeout, + ); + } + + late final _pactffi_verifier_set_verification_optionsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.UnsignedChar, + ffi.UnsignedLong)>>('pactffi_verifier_set_verification_options'); + late final _pactffi_verifier_set_verification_options = + _pactffi_verifier_set_verification_optionsPtr + .asFunction, int, int)>(); + + /// Enables or disables coloured output using ANSI escape codes in the verifier output. By default, + /// coloured output is enabled. + /// + /// `coloured_output` is a boolean value. Set it to greater than zero to turn the option on. + /// + /// # Safety + /// + /// This function is safe as long as the handle pointer points to a valid handle. + int pactffi_verifier_set_coloured_output( + ffi.Pointer handle, + int coloured_output, + ) { + return _pactffi_verifier_set_coloured_output( + handle, + coloured_output, + ); + } + + late final _pactffi_verifier_set_coloured_outputPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.UnsignedChar)>>('pactffi_verifier_set_coloured_output'); + late final _pactffi_verifier_set_coloured_output = + _pactffi_verifier_set_coloured_outputPtr + .asFunction, int)>(); + + /// Enables or disables if no pacts are found to verify results in an error. + /// + /// `is_error` is a boolean value. Set it to greater than zero to enable an error when no pacts + /// are found to verify, and set it to zero to disable this. + /// + /// # Safety + /// + /// This function is safe as long as the handle pointer points to a valid handle. + int pactffi_verifier_set_no_pacts_is_error( + ffi.Pointer handle, + int is_error, + ) { + return _pactffi_verifier_set_no_pacts_is_error( + handle, + is_error, + ); + } + + late final _pactffi_verifier_set_no_pacts_is_errorPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.UnsignedChar)>>('pactffi_verifier_set_no_pacts_is_error'); + late final _pactffi_verifier_set_no_pacts_is_error = + _pactffi_verifier_set_no_pacts_is_errorPtr + .asFunction, int)>(); + + /// Set the options used when publishing verification results to the Pact Broker. By default, + /// verification results will not be published unless this function is called. + /// + /// # Args + /// + /// - `handle` - The pact verifier handle to update + /// - `provider_version` - Version of the provider to publish + /// - `build_url` - URL to the build which ran the verification [OPTIONAL] + /// - `provider_tags` - Collection of tags for the provider [OPTIONAL] + /// - `provider_tags_len` - Number of provider tags supplied [OPTIONAL] + /// - `provider_branch` - Name of the branch used for verification [OPTIONAL] + /// + /// For optional args, a NULL pointer can be used. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + int pactffi_verifier_set_publish_options( + ffi.Pointer handle, + ffi.Pointer provider_version, + ffi.Pointer build_url, + ffi.Pointer> provider_tags, + int provider_tags_len, + ffi.Pointer provider_branch, + ) { + return _pactffi_verifier_set_publish_options( + handle, + provider_version, + build_url, + provider_tags, + provider_tags_len, + provider_branch, + ); + } + + late final _pactffi_verifier_set_publish_optionsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>, + ffi.UnsignedShort, + ffi.Pointer)>>('pactffi_verifier_set_publish_options'); + late final _pactffi_verifier_set_publish_options = + _pactffi_verifier_set_publish_optionsPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>, + int, + ffi.Pointer)>(); + + /// Set the consumer filters for the Pact verifier. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_set_consumer_filters( + ffi.Pointer handle, + ffi.Pointer> consumer_filters, + int consumer_filters_len, + ) { + return _pactffi_verifier_set_consumer_filters( + handle, + consumer_filters, + consumer_filters_len, + ); + } + + late final _pactffi_verifier_set_consumer_filtersPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.UnsignedShort)>>('pactffi_verifier_set_consumer_filters'); + late final _pactffi_verifier_set_consumer_filters = + _pactffi_verifier_set_consumer_filtersPtr.asFunction< + void Function(ffi.Pointer, + ffi.Pointer>, int)>(); + + /// Adds a custom header to be added to the requests made to the provider. + /// + /// # Safety + /// + /// The header name and value must point to a valid NULL terminated string and must contain + /// valid UTF-8. + void pactffi_verifier_add_custom_header( + ffi.Pointer handle, + ffi.Pointer header_name, + ffi.Pointer header_value, + ) { + return _pactffi_verifier_add_custom_header( + handle, + header_name, + header_value, + ); + } + + late final _pactffi_verifier_add_custom_headerPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_add_custom_header'); + late final _pactffi_verifier_add_custom_header = + _pactffi_verifier_add_custom_headerPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + /// Adds a Pact file as a source to verify. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_add_file_source( + ffi.Pointer handle, + ffi.Pointer file, + ) { + return _pactffi_verifier_add_file_source( + handle, + file, + ); + } + + late final _pactffi_verifier_add_file_sourcePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_add_file_source'); + late final _pactffi_verifier_add_file_source = + _pactffi_verifier_add_file_sourcePtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer)>(); + + /// Adds a Pact directory as a source to verify. All pacts from the directory that match the + /// provider name will be verified. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_add_directory_source( + ffi.Pointer handle, + ffi.Pointer directory, + ) { + return _pactffi_verifier_add_directory_source( + handle, + directory, + ); + } + + late final _pactffi_verifier_add_directory_sourcePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_add_directory_source'); + late final _pactffi_verifier_add_directory_source = + _pactffi_verifier_add_directory_sourcePtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer)>(); + + /// Adds a URL as a source to verify. The Pact file will be fetched from the URL. + /// + /// If a username and password is given, then basic authentication will be used when fetching + /// the pact file. If a token is provided, then bearer token authentication will be used. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_url_source( + ffi.Pointer handle, + ffi.Pointer url, + ffi.Pointer username, + ffi.Pointer password, + ffi.Pointer token, + ) { + return _pactffi_verifier_url_source( + handle, + url, + username, + password, + token, + ); + } + + late final _pactffi_verifier_url_sourcePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_url_source'); + late final _pactffi_verifier_url_source = + _pactffi_verifier_url_sourcePtr.asFunction< + void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + /// Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker + /// that match the provider name. + /// + /// If a username and password is given, then basic authentication will be used when fetching + /// the pact file. If a token is provided, then bearer token authentication will be used. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + void pactffi_verifier_broker_source( + ffi.Pointer handle, + ffi.Pointer url, + ffi.Pointer username, + ffi.Pointer password, + ffi.Pointer token, + ) { + return _pactffi_verifier_broker_source( + handle, + url, + username, + password, + token, + ); + } + + late final _pactffi_verifier_broker_sourcePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('pactffi_verifier_broker_source'); + late final _pactffi_verifier_broker_source = + _pactffi_verifier_broker_sourcePtr.asFunction< + void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + /// Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker + /// that match the provider name and the consumer version selectors + /// (See `https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/`). + /// + /// The consumer version selectors must be passed in in JSON format. + /// + /// `enable_pending` is a boolean value. Set it to greater than zero to turn the option on. + /// + /// If the `include_wip_pacts_since` option is provided, it needs to be a date formatted in + /// ISO format (YYYY-MM-DD). + /// + /// If a username and password is given, then basic authentication will be used when fetching + /// the pact file. If a token is provided, then bearer token authentication will be used. + /// + /// This function will return zero unless any of the consumer version selectors are not valid + /// JSON, in which case, it will return -1. + /// + /// # Safety + /// + /// All string fields must contain valid UTF-8. Invalid UTF-8 + /// will be replaced with U+FFFD REPLACEMENT CHARACTER. + int pactffi_verifier_broker_source_with_selectors( + ffi.Pointer handle, + ffi.Pointer url, + ffi.Pointer username, + ffi.Pointer password, + ffi.Pointer token, + int enable_pending, + ffi.Pointer include_wip_pacts_since, + ffi.Pointer> provider_tags, + int provider_tags_len, + ffi.Pointer provider_branch, + ffi.Pointer> consumer_version_selectors, + int consumer_version_selectors_len, + ffi.Pointer> consumer_version_tags, + int consumer_version_tags_len, + ) { + return _pactffi_verifier_broker_source_with_selectors( + handle, + url, + username, + password, + token, + enable_pending, + include_wip_pacts_since, + provider_tags, + provider_tags_len, + provider_branch, + consumer_version_selectors, + consumer_version_selectors_len, + consumer_version_tags, + consumer_version_tags_len, + ); + } + + late final _pactffi_verifier_broker_source_with_selectorsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedChar, + ffi.Pointer, + ffi.Pointer>, + ffi.UnsignedShort, + ffi.Pointer, + ffi.Pointer>, + ffi.UnsignedShort, + ffi.Pointer>, + ffi.UnsignedShort)>>( + 'pactffi_verifier_broker_source_with_selectors'); + late final _pactffi_verifier_broker_source_with_selectors = + _pactffi_verifier_broker_source_with_selectorsPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer, + ffi.Pointer>, + int, + ffi.Pointer, + ffi.Pointer>, + int, + ffi.Pointer>, + int)>(); + + /// Runs the verification. + /// + /// # Error Handling + /// + /// Errors will be reported with a non-zero return value. + int pactffi_verifier_execute( + ffi.Pointer handle, + ) { + return _pactffi_verifier_execute( + handle, + ); + } + + late final _pactffi_verifier_executePtr = _lookup< + ffi.NativeFunction)>>( + 'pactffi_verifier_execute'); + late final _pactffi_verifier_execute = _pactffi_verifier_executePtr + .asFunction)>(); + + /// External interface to retrieve the options and arguments available when calling the CLI interface, + /// returning them as a JSON string. + /// + /// The purpose is to then be able to use in other languages which wrap the FFI library, to implement + /// the same CLI functionality automatically without manual maintenance of arguments, help descriptions + /// etc. + /// + /// # Example structure + /// ```json + /// { + /// "options": [ + /// { + /// "long": "scheme", + /// "help": "Provider URI scheme (defaults to http)", + /// "possible_values": [ + /// "http", + /// "https" + /// ], + /// "default_value": "http" + /// "multiple": false, + /// }, + /// { + /// "long": "file", + /// "short": "f", + /// "help": "Pact file to verify (can be repeated)", + /// "multiple": true + /// }, + /// { + /// "long": "user", + /// "help": "Username to use when fetching pacts from URLS", + /// "multiple": false, + /// "env": "PACT_BROKER_USERNAME" + /// } + /// ], + /// "flags": [ + /// { + /// "long": "disable-ssl-verification", + /// "help": "Disables validation of SSL certificates", + /// "multiple": false + /// } + /// ] + /// } + /// ``` + /// + /// # Safety + /// + /// Exported functions are inherently unsafe. + ffi.Pointer pactffi_verifier_cli_args() { + return _pactffi_verifier_cli_args(); + } + + late final _pactffi_verifier_cli_argsPtr = + _lookup Function()>>( + 'pactffi_verifier_cli_args'); + late final _pactffi_verifier_cli_args = _pactffi_verifier_cli_argsPtr + .asFunction Function()>(); + + /// Extracts the logs for the verification run. This needs the memory buffer log sink to be + /// setup before the verification is executed. The returned string will need to be freed with + /// the `free_string` function call to avoid leaking memory. + /// + /// Will return a NULL pointer if the logs for the verification can not be retrieved. + ffi.Pointer pactffi_verifier_logs( + ffi.Pointer handle, + ) { + return _pactffi_verifier_logs( + handle, + ); + } + + late final _pactffi_verifier_logsPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_verifier_logs'); + late final _pactffi_verifier_logs = _pactffi_verifier_logsPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Extracts the logs for the verification run for the provider name. This needs the memory + /// buffer log sink to be setup before the verification is executed. The returned string will + /// need to be freed with the `free_string` function call to avoid leaking memory. + /// + /// Will return a NULL pointer if the logs for the verification can not be retrieved. + ffi.Pointer pactffi_verifier_logs_for_provider( + ffi.Pointer provider_name, + ) { + return _pactffi_verifier_logs_for_provider( + provider_name, + ); + } + + late final _pactffi_verifier_logs_for_providerPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_verifier_logs_for_provider'); + late final _pactffi_verifier_logs_for_provider = + _pactffi_verifier_logs_for_providerPtr + .asFunction Function(ffi.Pointer)>(); + + /// Extracts the standard output for the verification run. The returned string will need to be + /// freed with the `free_string` function call to avoid leaking memory. + /// + /// * `strip_ansi` - This parameter controls ANSI escape codes. Setting it to a non-zero value + /// will cause the ANSI control codes to be stripped from the output. + /// + /// Will return a NULL pointer if the handle is invalid. + ffi.Pointer pactffi_verifier_output( + ffi.Pointer handle, + int strip_ansi, + ) { + return _pactffi_verifier_output( + handle, + strip_ansi, + ); + } + + late final _pactffi_verifier_outputPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.UnsignedChar)>>('pactffi_verifier_output'); + late final _pactffi_verifier_output = _pactffi_verifier_outputPtr.asFunction< + ffi.Pointer Function(ffi.Pointer, int)>(); + + /// Extracts the verification result as a JSON document. The returned string will need to be + /// freed with the `free_string` function call to avoid leaking memory. + /// + /// Will return a NULL pointer if the handle is invalid. + ffi.Pointer pactffi_verifier_json( + ffi.Pointer handle, + ) { + return _pactffi_verifier_json( + handle, + ); + } + + late final _pactffi_verifier_jsonPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('pactffi_verifier_json'); + late final _pactffi_verifier_json = _pactffi_verifier_jsonPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + /// Add a plugin to be used by the test. The plugin needs to be installed correctly for this + /// function to work. + /// + /// * `plugin_name` is the name of the plugin to load. + /// * `plugin_version` is the version of the plugin to load. It is optional, and can be NULL. + /// + /// Returns zero on success, and a positive integer value on failure. + /// + /// Note that plugins run as separate processes, so will need to be cleaned up afterwards by + /// calling `pactffi_cleanup_plugins` otherwise you will have plugin processes left running. + /// + /// # Safety + /// + /// `plugin_name` must be a valid pointer to a NULL terminated string. `plugin_version` may be null, + /// and if not NULL must also be a valid pointer to a NULL terminated string. Invalid + /// pointers will result in undefined behaviour. + /// + /// # Errors + /// + /// * `1` - A general panic was caught. + /// * `2` - Failed to load the plugin. + /// * `3` - Pact Handle is not valid. + /// + /// When an error errors, LAST_ERROR will contain the error message. + int pactffi_using_plugin( + int pact, + ffi.Pointer plugin_name, + ffi.Pointer plugin_version, + ) { + return _pactffi_using_plugin( + pact, + plugin_name, + plugin_version, + ); + } + + late final _pactffi_using_pluginPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function(PactHandle, ffi.Pointer, + ffi.Pointer)>>('pactffi_using_plugin'); + late final _pactffi_using_plugin = _pactffi_using_pluginPtr.asFunction< + int Function(int, ffi.Pointer, ffi.Pointer)>(); + + /// Decrement the access count on any plugins that are loaded for the Pact. This will shutdown + /// any plugins that are no longer required (access count is zero). + void pactffi_cleanup_plugins( + int pact, + ) { + return _pactffi_cleanup_plugins( + pact, + ); + } + + late final _pactffi_cleanup_pluginsPtr = + _lookup>( + 'pactffi_cleanup_plugins'); + late final _pactffi_cleanup_plugins = + _pactffi_cleanup_pluginsPtr.asFunction(); + + /// Setup the interaction part using a plugin. The contents is a JSON string that will be passed on to + /// the plugin to configure the interaction part. Refer to the plugin documentation on the format + /// of the JSON contents. + /// + /// Returns zero on success, and a positive integer value on failure. + /// + /// * `interaction` - Handle to the interaction to configure. + /// * `part` - The part of the interaction to configure (request or response). It is ignored for messages. + /// * `content_type` - NULL terminated C string of the content type of the part. + /// * `contents` - NULL terminated C string of the JSON contents that gets passed to the plugin. + /// + /// # Safety + /// + /// `content_type` and `contents` must be a valid pointers to NULL terminated strings. Invalid + /// pointers will result in undefined behaviour. + /// + /// # Errors + /// + /// * `1` - A general panic was caught. + /// * `2` - The mock server has already been started. + /// * `3` - The interaction handle is invalid. + /// * `4` - The content type is not valid. + /// * `5` - The contents JSON is not valid JSON. + /// * `6` - The plugin returned an error. + /// + /// When an error errors, LAST_ERROR will contain the error message. + int pactffi_interaction_contents( + int interaction, + int part1, + ffi.Pointer content_type, + ffi.Pointer contents, + ) { + return _pactffi_interaction_contents( + interaction, + part1, + content_type, + contents, + ); + } + + late final _pactffi_interaction_contentsPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function( + InteractionHandle, + ffi.Int32, + ffi.Pointer, + ffi.Pointer)>>('pactffi_interaction_contents'); + late final _pactffi_interaction_contents = + _pactffi_interaction_contentsPtr.asFunction< + int Function( + int, int, ffi.Pointer, ffi.Pointer)>(); + + /// Determines if the string value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get as a NULL terminated string + /// * actual_value - value to match as a NULL terminated string + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer, and the value parameters must be + /// valid pointers to a NULL terminated strings. + ffi.Pointer pactffi_matches_string_value( + ffi.Pointer matching_rule, + ffi.Pointer expected_value, + ffi.Pointer actual_value, + int cascaded, + ) { + return _pactffi_matches_string_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_string_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Uint8)>>('pactffi_matches_string_value'); + late final _pactffi_matches_string_value = + _pactffi_matches_string_valuePtr.asFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); + + /// Determines if the unsigned integer value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get + /// * actual_value - value to match + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer. + ffi.Pointer pactffi_matches_u64_value( + ffi.Pointer matching_rule, + int expected_value, + int actual_value, + int cascaded, + ) { + return _pactffi_matches_u64_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_u64_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Uint64, + ffi.Uint64, ffi.Uint8)>>('pactffi_matches_u64_value'); + late final _pactffi_matches_u64_value = + _pactffi_matches_u64_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, int, int)>(); + + /// Determines if the signed integer value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get + /// * actual_value - value to match + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer. + ffi.Pointer pactffi_matches_i64_value( + ffi.Pointer matching_rule, + int expected_value, + int actual_value, + int cascaded, + ) { + return _pactffi_matches_i64_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_i64_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Int64, + ffi.Int64, ffi.Uint8)>>('pactffi_matches_i64_value'); + late final _pactffi_matches_i64_value = + _pactffi_matches_i64_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, int, int)>(); + + /// Determines if the floating point value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get + /// * actual_value - value to match + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer. + ffi.Pointer pactffi_matches_f64_value( + ffi.Pointer matching_rule, + double expected_value, + double actual_value, + int cascaded, + ) { + return _pactffi_matches_f64_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_f64_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Double, + ffi.Double, ffi.Uint8)>>('pactffi_matches_f64_value'); + late final _pactffi_matches_f64_value = + _pactffi_matches_f64_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, double, double, int)>(); + + /// Determines if the boolean value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get, 0 == false and 1 == true + /// * actual_value - value to match, 0 == false and 1 == true + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer. + ffi.Pointer pactffi_matches_bool_value( + ffi.Pointer matching_rule, + int expected_value, + int actual_value, + int cascaded, + ) { + return _pactffi_matches_bool_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_bool_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Uint8, + ffi.Uint8, ffi.Uint8)>>('pactffi_matches_bool_value'); + late final _pactffi_matches_bool_value = + _pactffi_matches_bool_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, int, int)>(); + + /// Determines if the binary value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get + /// * expected_value_len - length of the expected value bytes + /// * actual_value - value to match + /// * actual_value_len - length of the actual value bytes + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule, expected value and actual value pointers must be a valid pointers. + /// expected_value_len and actual_value_len must contain the number of bytes that the value + /// pointers point to. Passing invalid lengths can lead to undefined behaviour. + ffi.Pointer pactffi_matches_binary_value( + ffi.Pointer matching_rule, + ffi.Pointer expected_value, + int expected_value_len, + ffi.Pointer actual_value, + int actual_value_len, + int cascaded, + ) { + return _pactffi_matches_binary_value( + matching_rule, + expected_value, + expected_value_len, + actual_value, + actual_value_len, + cascaded, + ); + } + + late final _pactffi_matches_binary_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.UintPtr, + ffi.Pointer, + ffi.UintPtr, + ffi.Uint8)>>('pactffi_matches_binary_value'); + late final _pactffi_matches_binary_value = + _pactffi_matches_binary_valuePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer, + int, + int)>(); + + /// Determines if the JSON value matches the given matching rule. If the value matches OK, + /// will return a NULL pointer. If the value does not match, will return a error message as + /// a NULL terminated string. The error message pointer will need to be deleted with the + /// `pactffi_string_delete` function once it is no longer required. + /// + /// * matching_rule - pointer to a matching rule + /// * expected_value - value we expect to get as a NULL terminated string + /// * actual_value - value to match as a NULL terminated string + /// * cascaded - if the matching rule has been cascaded from a parent. 0 == false, 1 == true + /// + /// # Safety + /// + /// The matching rule pointer must be a valid pointer, and the value parameters must be + /// valid pointers to a NULL terminated strings. + ffi.Pointer pactffi_matches_json_value( + ffi.Pointer matching_rule, + ffi.Pointer expected_value, + ffi.Pointer actual_value, + int cascaded, + ) { + return _pactffi_matches_json_value( + matching_rule, + expected_value, + actual_value, + cascaded, + ); + } + + late final _pactffi_matches_json_valuePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Uint8)>>('pactffi_matches_json_value'); + late final _pactffi_matches_json_value = + _pactffi_matches_json_valuePtr.asFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); +} + +class __fsid_t extends ffi.Struct { + @ffi.Array.multi([2]) + external ffi.Array __val; +} + +class div_t extends ffi.Struct { + @ffi.Int() + external int quot; + + @ffi.Int() + external int rem; +} + +class ldiv_t extends ffi.Struct { + @ffi.Long() + external int quot; + + @ffi.Long() + external int rem; +} + +class lldiv_t extends ffi.Struct { + @ffi.LongLong() + external int quot; + + @ffi.LongLong() + external int rem; +} + +class __sigset_t extends ffi.Struct { + @ffi.Array.multi([16]) + external ffi.Array __val; +} + +class timeval extends ffi.Struct { + @__time_t() + external int tv_sec; + + @__suseconds_t() + external int tv_usec; +} + +typedef __time_t = ffi.Long; +typedef __suseconds_t = ffi.Long; + +class timespec extends ffi.Struct { + @__time_t() + external int tv_sec; + + @__syscall_slong_t() + external int tv_nsec; +} + +typedef __syscall_slong_t = ffi.Long; + +class fd_set extends ffi.Struct { + @ffi.Array.multi([16]) + external ffi.Array<__fd_mask> __fds_bits; +} + +typedef __fd_mask = ffi.Long; + +class __atomic_wide_counter extends ffi.Union { + @ffi.UnsignedLongLong() + external int __value64; + + external UnnamedStruct1 __value32; +} + +class UnnamedStruct1 extends ffi.Struct { + @ffi.UnsignedInt() + external int __low; + + @ffi.UnsignedInt() + external int __high; +} + +class __pthread_internal_list extends ffi.Struct { + external ffi.Pointer<__pthread_internal_list> __prev; + + external ffi.Pointer<__pthread_internal_list> __next; +} + +class __pthread_internal_slist extends ffi.Struct { + external ffi.Pointer<__pthread_internal_slist> __next; +} + +class __pthread_mutex_s extends ffi.Struct { + @ffi.Int() + external int __lock; + + @ffi.UnsignedInt() + external int __count; + + @ffi.Int() + external int __owner; + + @ffi.UnsignedInt() + external int __nusers; + + @ffi.Int() + external int __kind; + + @ffi.Short() + external int __spins; + + @ffi.Short() + external int __elision; + + external __pthread_list_t __list; +} + +typedef __pthread_list_t = __pthread_internal_list; + +class __pthread_rwlock_arch_t extends ffi.Struct { + @ffi.UnsignedInt() + external int __readers; + + @ffi.UnsignedInt() + external int __writers; + + @ffi.UnsignedInt() + external int __wrphase_futex; + + @ffi.UnsignedInt() + external int __writers_futex; + + @ffi.UnsignedInt() + external int __pad3; + + @ffi.UnsignedInt() + external int __pad4; + + @ffi.Int() + external int __cur_writer; + + @ffi.Int() + external int __shared; + + @ffi.SignedChar() + external int __rwelision; + + @ffi.Array.multi([7]) + external ffi.Array __pad1; + + @ffi.UnsignedLong() + external int __pad2; + + @ffi.UnsignedInt() + external int __flags; +} + +class __pthread_cond_s extends ffi.Struct { + external __atomic_wide_counter __wseq; + + external __atomic_wide_counter __g1_start; + + @ffi.Array.multi([2]) + external ffi.Array __g_size; + + @ffi.UnsignedInt() + external int __g1_orig_size; + + @ffi.UnsignedInt() + external int __wrefs; + + @ffi.Array.multi([2]) + external ffi.Array __g_signals; + + @ffi.UnsignedInt() + external int __unused_initialized_1; + + @ffi.UnsignedInt() + external int __unused_initialized_2; +} + +class __once_flag extends ffi.Struct { + @ffi.Int() + external int __data; +} + +class pthread_mutexattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class pthread_condattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class pthread_attr_t extends ffi.Union { + @ffi.Array.multi([56]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_mutex_t extends ffi.Union { + external __pthread_mutex_s __data; + + @ffi.Array.multi([40]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_cond_t extends ffi.Union { + external __pthread_cond_s __data; + + @ffi.Array.multi([48]) + external ffi.Array __size; + + @ffi.LongLong() + external int __align; +} + +class pthread_rwlock_t extends ffi.Union { + external __pthread_rwlock_arch_t __data; + + @ffi.Array.multi([56]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_rwlockattr_t extends ffi.Union { + @ffi.Array.multi([8]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_barrier_t extends ffi.Union { + @ffi.Array.multi([32]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_barrierattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class random_data extends ffi.Struct { + external ffi.Pointer fptr; + + external ffi.Pointer rptr; + + external ffi.Pointer state; + + @ffi.Int() + external int rand_type; + + @ffi.Int() + external int rand_deg; + + @ffi.Int() + external int rand_sep; + + external ffi.Pointer end_ptr; +} + +class drand48_data extends ffi.Struct { + @ffi.Array.multi([3]) + external ffi.Array __x; + + @ffi.Array.multi([3]) + external ffi.Array __old_x; + + @ffi.UnsignedShort() + external int __c; + + @ffi.UnsignedShort() + external int __init; + + @ffi.UnsignedLongLong() + external int __a; +} + +typedef __uint32_t = ffi.UnsignedInt; +typedef __compar_fn_t = ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer)>>; + +/// The type of value detected after parsing the expression +abstract class ExpressionValueType { + /// If the type is unknown + static const int ExpressionValueType_Unknown = 0; + + /// String type + static const int ExpressionValueType_String = 1; + + /// Numeric type + static const int ExpressionValueType_Number = 2; + + /// Integer numeric type (no significant figures after the decimal point) + static const int ExpressionValueType_Integer = 3; + + /// Decimal numeric type (at least one significant figure after the decimal point) + static const int ExpressionValueType_Decimal = 4; + + /// Boolean type + static const int ExpressionValueType_Boolean = 5; +} + +/// Enum defining the categories that generators can be applied to +abstract class GeneratorCategory { + /// Request Method + static const int GeneratorCategory_METHOD = 0; + + /// Request Path + static const int GeneratorCategory_PATH = 1; + + /// Request/Response Header + static const int GeneratorCategory_HEADER = 2; + + /// Request Query Parameter + static const int GeneratorCategory_QUERY = 3; + + /// Body + static const int GeneratorCategory_BODY = 4; + + /// Response Status + static const int GeneratorCategory_STATUS = 5; + + /// Message metadata + static const int GeneratorCategory_METADATA = 6; +} + +/// Request or Response enum +abstract class InteractionPart { + /// Request part + static const int InteractionPart_Request = 0; + + /// Response part + static const int InteractionPart_Response = 1; +} + +/// An enum representing the log level to use. +/// +/// This enum is passed to `log_attach_sink`, which defines where to direct +/// log output at the specified level or lower. +abstract class LevelFilter { + static const int LevelFilter_Off = 0; + static const int LevelFilter_Error = 1; + static const int LevelFilter_Warn = 2; + static const int LevelFilter_Info = 3; + static const int LevelFilter_Debug = 4; + static const int LevelFilter_Trace = 5; +} + +/// Enum defining the categories that matching rules can be applied to +abstract class MatchingRuleCategory { + /// Request Method + static const int MatchingRuleCategory_METHOD = 0; + + /// Request Path + static const int MatchingRuleCategory_PATH = 1; + + /// Request/Response Header + static const int MatchingRuleCategory_HEADER = 2; + + /// Request Query Parameter + static const int MatchingRuleCategory_QUERY = 3; + + /// Body + static const int MatchingRuleCategory_BODY = 4; + + /// Response Status + static const int MatchingRuleCategory_STATUS = 5; + + /// Message contents (body) + static const int MatchingRuleCategory_CONTENTS = 6; + + /// Message metadata + static const int MatchingRuleCategory_METADATA = 7; +} + +/// Enum defining the pact specification versions supported by the library +abstract class PactSpecification { + /// Unknown or unsupported specification version + static const int PactSpecification_Unknown = 0; + + /// First version of the pact specification () + static const int PactSpecification_V1 = 1; + + /// Second version of the pact specification () + static const int PactSpecification_V1_1 = 2; + + /// Version two of the pact specification () + static const int PactSpecification_V2 = 3; + + /// Version three of the pact specification () + static const int PactSpecification_V3 = 4; + + /// Version four of the pact specification () + static const int PactSpecification_V4 = 5; +} + +class AsynchronousMessage extends ffi.Opaque {} + +class Consumer extends ffi.Opaque {} + +class Generator extends ffi.Opaque {} + +class GeneratorCategoryIterator extends ffi.Opaque {} + +class HttpRequest extends ffi.Opaque {} + +class HttpResponse extends ffi.Opaque {} + +class MatchingRule extends ffi.Opaque {} + +class MatchingRuleCategoryIterator extends ffi.Opaque {} + +class MatchingRuleDefinitionResult extends ffi.Opaque {} + +class MatchingRuleIterator extends ffi.Opaque {} + +class MatchingRuleResult extends ffi.Opaque {} + +class Message extends ffi.Opaque {} + +class MessageContents extends ffi.Opaque {} + +class MessageMetadataIterator extends ffi.Opaque {} + +class MessagePact extends ffi.Opaque {} + +class MessagePactMessageIterator extends ffi.Opaque {} + +class MessagePactMetadataIterator extends ffi.Opaque {} + +class Mismatch extends ffi.Opaque {} + +class Mismatches extends ffi.Opaque {} + +class MismatchesIterator extends ffi.Opaque {} + +class Pact extends ffi.Opaque {} + +class PactAsyncMessageIterator extends ffi.Opaque {} + +class PactInteraction extends ffi.Opaque {} + +class PactInteractionIterator extends ffi.Opaque {} + +class PactMessageIterator extends ffi.Opaque {} + +class PactSyncHttpIterator extends ffi.Opaque {} + +class PactSyncMessageIterator extends ffi.Opaque {} + +class Provider extends ffi.Opaque {} + +class ProviderState extends ffi.Opaque {} + +class ProviderStateIterator extends ffi.Opaque {} + +class ProviderStateParamIterator extends ffi.Opaque {} + +class SynchronousHttp extends ffi.Opaque {} + +class SynchronousMessage extends ffi.Opaque {} + +class VerifierHandle extends ffi.Opaque {} + +/// A single key-value pair of a path and generator exported to the C-side. +class GeneratorKeyValuePair extends ffi.Struct { + /// The generator path + external ffi.Pointer path; + + /// The generator + external ffi.Pointer generator; +} + +/// A single key-value pair of a path and matching rule exported to the C-side. +class MatchingRuleKeyValuePair extends ffi.Struct { + /// The matching rule path + external ffi.Pointer path; + + /// The matching rule + external ffi.Pointer rule; +} + +/// A single key-value pair exported to the C-side. +class MessageMetadataPair extends ffi.Struct { + /// The metadata key. + external ffi.Pointer key; + + /// The metadata value. + external ffi.Pointer value; +} + +/// A triple, containing the outer key, inner key, and value, exported to the C-side. +class MessagePactMetadataTriple extends ffi.Struct { + /// The outer key of the `MessagePact` metadata. + external ffi.Pointer outer_key; + + /// The inner key of the `MessagePact` metadata. + external ffi.Pointer inner_key; + + /// The value of the `MessagePact` metadata. + external ffi.Pointer value; +} + +/// A single key-value pair exported to the C-side. +class ProviderStateParamPair extends ffi.Struct { + /// The key of the `ProviderState` parameter. + external ffi.Pointer key; + + /// The value of the `ProviderState` parameter. + external ffi.Pointer value; +} + +/// Result of wrapping a string value +abstract class StringResult_Tag { + /// Was generated OK + static const int StringResult_Ok = 0; + + /// There was an error generating the string + static const int StringResult_Failed = 1; +} + +class StringResult extends ffi.Struct { + @ffi.Int32() + external int tag; + + external UnnamedUnion1 unnamed; +} + +class UnnamedUnion1 extends ffi.Union { + external UnnamedStruct2 unnamed; + + external UnnamedStruct3 unnamed1; +} + +class UnnamedStruct2 extends ffi.Struct { + external ffi.Pointer ok; +} + +class UnnamedStruct3 extends ffi.Struct { + external ffi.Pointer failed; +} + +/// Wraps a Pact model struct +typedef PactHandle = ffi.Uint16; + +/// Wraps a Pact model struct +typedef InteractionHandle = ffi.Uint32; + +/// Wraps a Pact model struct +typedef MessagePactHandle = ffi.Uint16; + +/// Wraps a Pact model struct +typedef MessageHandle = ffi.Uint32; + +const int __bool_true_false_are_defined = 1; + +const int true1 = 1; + +const int false1 = 0; + +const int _STDINT_H = 1; + +const int _FEATURES_H = 1; + +const int _DEFAULT_SOURCE = 1; + +const int __GLIBC_USE_ISOC2Y = 1; + +const int __GLIBC_USE_ISOC23 = 1; + +const int __USE_ISOC11 = 1; + +const int __USE_ISOC99 = 1; + +const int __USE_ISOC95 = 1; + +const int _POSIX_SOURCE = 1; + +const int _POSIX_C_SOURCE = 200809; + +const int __USE_POSIX = 1; + +const int __USE_POSIX2 = 1; + +const int __USE_POSIX199309 = 1; + +const int __USE_POSIX199506 = 1; + +const int __USE_XOPEN2K = 1; + +const int __USE_XOPEN2K8 = 1; + +const int _ATFILE_SOURCE = 1; + +const int __WORDSIZE = 64; + +const int __WORDSIZE_TIME64_COMPAT32 = 1; + +const int __SYSCALL_WORDSIZE = 64; + +const int __TIMESIZE = 64; + +const int __USE_TIME_BITS64 = 1; + +const int __USE_MISC = 1; + +const int __USE_ATFILE = 1; + +const int __USE_FORTIFY_LEVEL = 0; + +const int __GLIBC_USE_DEPRECATED_GETS = 0; + +const int __GLIBC_USE_DEPRECATED_SCANF = 0; + +const int __GLIBC_USE_C23_STRTOL = 1; + +const int _STDC_PREDEF_H = 1; + +const int __STDC_IEC_559__ = 1; + +const int __STDC_IEC_60559_BFP__ = 201404; + +const int __STDC_IEC_559_COMPLEX__ = 1; + +const int __STDC_IEC_60559_COMPLEX__ = 201404; + +const int __STDC_ISO_10646__ = 201706; + +const int __GNU_LIBRARY__ = 6; + +const int __GLIBC__ = 2; + +const int __GLIBC_MINOR__ = 41; + +const int _SYS_CDEFS_H = 1; + +const int __THROW = 1; + +const int __THROWNL = 1; + +const int __glibc_c99_flexarr_available = 1; + +const int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI = 0; + +const int __HAVE_GENERIC_SELECTION = 0; + +const int __GLIBC_USE_LIB_EXT2 = 1; + +const int __GLIBC_USE_IEC_60559_BFP_EXT = 1; + +const int __GLIBC_USE_IEC_60559_BFP_EXT_C23 = 1; + +const int __GLIBC_USE_IEC_60559_EXT = 1; + +const int __GLIBC_USE_IEC_60559_FUNCS_EXT = 1; + +const int __GLIBC_USE_IEC_60559_FUNCS_EXT_C23 = 1; + +const int __GLIBC_USE_IEC_60559_TYPES_EXT = 1; + +const int _BITS_TYPES_H = 1; + +const int _BITS_TYPESIZES_H = 1; + +const int __OFF_T_MATCHES_OFF64_T = 1; + +const int __INO_T_MATCHES_INO64_T = 1; + +const int __RLIM_T_MATCHES_RLIM64_T = 1; + +const int __STATFS_MATCHES_STATFS64 = 1; + +const int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 = 1; + +const int __FD_SETSIZE = 1024; + +const int _BITS_TIME64_H = 1; + +const int _BITS_WCHAR_H = 1; + +const int __WCHAR_MAX = 2147483647; + +const int __WCHAR_MIN = -2147483648; + +const int _BITS_STDINT_INTN_H = 1; + +const int _BITS_STDINT_UINTN_H = 1; + +const int _BITS_STDINT_LEAST_H = 1; + +const int INT8_MIN = -128; + +const int INT16_MIN = -32768; + +const int INT32_MIN = -2147483648; + +const int INT64_MIN = -9223372036854775808; + +const int INT8_MAX = 127; + +const int INT16_MAX = 32767; + +const int INT32_MAX = 2147483647; + +const int INT64_MAX = 9223372036854775807; + +const int UINT8_MAX = 255; + +const int UINT16_MAX = 65535; + +const int UINT32_MAX = 4294967295; + +const int UINT64_MAX = -1; + +const int INT_LEAST8_MIN = -128; + +const int INT_LEAST16_MIN = -32768; + +const int INT_LEAST32_MIN = -2147483648; + +const int INT_LEAST64_MIN = -9223372036854775808; + +const int INT_LEAST8_MAX = 127; + +const int INT_LEAST16_MAX = 32767; + +const int INT_LEAST32_MAX = 2147483647; + +const int INT_LEAST64_MAX = 9223372036854775807; + +const int UINT_LEAST8_MAX = 255; + +const int UINT_LEAST16_MAX = 65535; + +const int UINT_LEAST32_MAX = 4294967295; + +const int UINT_LEAST64_MAX = -1; + +const int INT_FAST8_MIN = -128; + +const int INT_FAST16_MIN = -9223372036854775808; + +const int INT_FAST32_MIN = -9223372036854775808; + +const int INT_FAST64_MIN = -9223372036854775808; + +const int INT_FAST8_MAX = 127; + +const int INT_FAST16_MAX = 9223372036854775807; + +const int INT_FAST32_MAX = 9223372036854775807; + +const int INT_FAST64_MAX = 9223372036854775807; + +const int UINT_FAST8_MAX = 255; + +const int UINT_FAST16_MAX = -1; + +const int UINT_FAST32_MAX = -1; + +const int UINT_FAST64_MAX = -1; + +const int INTPTR_MIN = -9223372036854775808; + +const int INTPTR_MAX = 9223372036854775807; + +const int UINTPTR_MAX = -1; + +const int INTMAX_MIN = -9223372036854775808; + +const int INTMAX_MAX = 9223372036854775807; + +const int UINTMAX_MAX = -1; + +const int PTRDIFF_MIN = -9223372036854775808; + +const int PTRDIFF_MAX = 9223372036854775807; + +const int SIG_ATOMIC_MIN = -2147483648; + +const int SIG_ATOMIC_MAX = 2147483647; + +const int SIZE_MAX = -1; + +const int WCHAR_MIN = -2147483648; + +const int WCHAR_MAX = 2147483647; + +const int WINT_MIN = 0; + +const int WINT_MAX = 4294967295; + +const int NULL = 0; + +const int _STDLIB_H = 1; + +const int WNOHANG = 1; + +const int WUNTRACED = 2; + +const int WSTOPPED = 2; + +const int WEXITED = 4; + +const int WCONTINUED = 8; + +const int WNOWAIT = 16777216; + +const int __WNOTHREAD = 536870912; + +const int __WALL = 1073741824; + +const int __WCLONE = 2147483648; + +const int __W_CONTINUED = 65535; + +const int __WCOREFLAG = 128; + +const int __HAVE_FLOAT128 = 1; + +const int __HAVE_DISTINCT_FLOAT128 = 1; + +const int __HAVE_FLOAT64X = 1; + +const int __HAVE_FLOAT64X_LONG_DOUBLE = 1; + +const int __HAVE_FLOAT16 = 0; + +const int __HAVE_FLOAT32 = 1; + +const int __HAVE_FLOAT64 = 1; + +const int __HAVE_FLOAT32X = 1; + +const int __HAVE_FLOAT128X = 0; + +const int __HAVE_DISTINCT_FLOAT16 = 0; + +const int __HAVE_DISTINCT_FLOAT32 = 0; + +const int __HAVE_DISTINCT_FLOAT64 = 0; + +const int __HAVE_DISTINCT_FLOAT32X = 0; + +const int __HAVE_DISTINCT_FLOAT64X = 0; + +const int __HAVE_DISTINCT_FLOAT128X = 0; + +const int __HAVE_FLOAT128_UNLIKE_LDBL = 1; + +const int __HAVE_FLOATN_NOT_TYPEDEF = 0; + +const int __ldiv_t_defined = 1; + +const int __lldiv_t_defined = 1; + +const int RAND_MAX = 2147483647; + +const int EXIT_FAILURE = 1; + +const int EXIT_SUCCESS = 0; + +const int _SYS_TYPES_H = 1; + +const int __clock_t_defined = 1; + +const int __clockid_t_defined = 1; + +const int __time_t_defined = 1; + +const int __timer_t_defined = 1; + +const int __BIT_TYPES_DEFINED__ = 1; + +const int _ENDIAN_H = 1; + +const int _BITS_ENDIAN_H = 1; + +const int __LITTLE_ENDIAN = 1234; + +const int __BIG_ENDIAN = 4321; + +const int __PDP_ENDIAN = 3412; + +const int _BITS_ENDIANNESS_H = 1; + +const int __BYTE_ORDER = 1234; + +const int __FLOAT_WORD_ORDER = 1234; + +const int LITTLE_ENDIAN = 1234; + +const int BIG_ENDIAN = 4321; + +const int PDP_ENDIAN = 3412; + +const int BYTE_ORDER = 1234; + +const int _BITS_BYTESWAP_H = 1; + +const int _BITS_UINTN_IDENTITY_H = 1; + +const int _SYS_SELECT_H = 1; + +const int __sigset_t_defined = 1; + +const int _SIGSET_NWORDS = 16; + +const int __timeval_defined = 1; + +const int _STRUCT_TIMESPEC = 1; + +const int __NFDBITS = 64; + +const int FD_SETSIZE = 1024; + +const int NFDBITS = 64; + +const int _BITS_PTHREADTYPES_COMMON_H = 1; + +const int _THREAD_SHARED_TYPES_H = 1; + +const int _BITS_PTHREADTYPES_ARCH_H = 1; + +const int __SIZEOF_PTHREAD_MUTEX_T = 40; + +const int __SIZEOF_PTHREAD_ATTR_T = 56; + +const int __SIZEOF_PTHREAD_RWLOCK_T = 56; + +const int __SIZEOF_PTHREAD_BARRIER_T = 32; + +const int __SIZEOF_PTHREAD_MUTEXATTR_T = 4; + +const int __SIZEOF_PTHREAD_COND_T = 48; + +const int __SIZEOF_PTHREAD_CONDATTR_T = 4; + +const int __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; + +const int __SIZEOF_PTHREAD_BARRIERATTR_T = 4; + +const int _THREAD_MUTEX_INTERNAL_H = 1; + +const int __PTHREAD_MUTEX_HAVE_PREV = 1; + +const int __PTHREAD_RWLOCK_ELISION_EXTRA = 0; + +const int __have_pthread_attr_t = 1; + +const int _ALLOCA_H = 1; diff --git a/lib/pact_dart.dart b/lib/pact_dart.dart index 93e49c7..cfd8c4f 100644 --- a/lib/pact_dart.dart +++ b/lib/pact_dart.dart @@ -1,6 +1,5 @@ library pact_dart; -export 'src/bindings/types.dart'; export 'src/errors.dart'; export 'src/interaction.dart'; export 'src/matchers.dart'; diff --git a/lib/src/bindings/bindings.dart b/lib/src/bindings/bindings.dart index e63760f..e92a174 100644 --- a/lib/src/bindings/bindings.dart +++ b/lib/src/bindings/bindings.dart @@ -1,183 +1,10 @@ // ignore_for_file: non_constant_identifier_names -import 'dart:ffi'; - -import 'package:ffi/ffi.dart'; -import 'package:pact_dart/src/bindings/signatures.dart'; -import 'package:pact_dart/src/bindings/types.dart'; +import 'package:pact_dart/gen/library.dart'; import 'package:pact_dart/src/ffi/dylib.dart'; -class PactFFIBindings { - late DynamicLibrary pactffi; - - late void Function(Pointer log_env_var) pactffi_init; - - late Pointer Function() pactffi_version; - - late PactHandle Function( - Pointer consumer_name, Pointer provider_name) - pactffi_new_pact; - - late InteractionHandle Function(PactHandle pact, Pointer description) - pactffi_new_interaction; - - late int Function(InteractionHandle interaction, Pointer description) - pactffi_given; - - late int Function(InteractionHandle interaction, Pointer description, - Pointer key, Pointer value) pactffi_given_with_param; - - late int Function(InteractionHandle interaction, Pointer description) - pactffi_upon_receiving; - - late int Function(InteractionHandle interaction, Pointer method, - Pointer path) pactffi_with_request; - - late int Function(InteractionHandle interaction, int status) - pactffi_response_status; - - late int Function(InteractionHandle interaction, int part, - Pointer content_type, Pointer body) pactffi_with_body; - - late int Function(Pointer pact_str, Pointer addr_str, int bool) - pactffi_create_mock_server; - - late int Function(PactHandle pact, Pointer addr_str, int tls) - pactffi_create_mock_server_for_pact; - - late int Function( - int mock_server_port, Pointer directory, int overwrite) - pactffi_write_pact_file; - - late int Function(int mock_server_port) pactffi_mock_server_matched; - - /// External interface to get all the mismatches from a mock server. The port number of the - /// mock server is passed in, and a pointer to a C string with the mismatches in JSON - /// format is returned. - /// - /// https://docs.rs/pact_ffi/0.3.3/pact_ffi/mock_server/fn.pactffi_mock_server_mismatches.html - /// https://docs.rs/pact_ffi/0.3.3/src/pact_ffi/mock_server/mod.rs.html#391-414 - /// - late Pointer Function(int mock_server_port) - pactffi_mock_server_mismatches; - - late int Function(InteractionHandle interaction, int part, Pointer name, - int index, Pointer value) pactffi_with_header; - - late int Function(InteractionHandle interaction, Pointer name, - int index, Pointer value) pactffi_with_query_parameter; - - late int Function(InteractionHandle interaction, Pointer name, - int index, Pointer value) pactffi_with_query_parameter_v2; - - late int Function(int mock_server_port) pactffi_cleanup_mock_server; - - /// Get a description of a mismatch. - /// - /// https://docs.rs/pact_ffi/0.3.3/pact_ffi/fn.pactffi_mismatch_description.html - /// https://docs.rs/pact_ffi/0.3.3/src/pact_ffi/lib.rs.html#265-274 - late Pointer Function(Pointer mismatches) - pactffi_mismatch_description; - - PactFFIBindings() { - pactffi = openLibrary(); - - pactffi_init = pactffi - .lookup>('pactffi_init') - .asFunction(); - - pactffi_version = pactffi - .lookup>('pactffi_version') - .asFunction(); - - pactffi_new_pact = pactffi - .lookup>('pactffi_new_pact') - .asFunction(); - - pactffi_new_interaction = pactffi - .lookup>( - 'pactffi_new_interaction') - .asFunction(); - - pactffi_given = pactffi - .lookup>('pactffi_given') - .asFunction(); - - pactffi_given_with_param = pactffi - .lookup>( - 'pactffi_given_with_param') - .asFunction(); - - pactffi_upon_receiving = pactffi - .lookup>( - 'pactffi_upon_receiving') - .asFunction(); - - pactffi_with_request = pactffi - .lookup>( - 'pactffi_with_request') - .asFunction(); - - pactffi_response_status = pactffi - .lookup>( - 'pactffi_response_status') - .asFunction(); - - pactffi_with_body = pactffi - .lookup>('pactffi_with_body') - .asFunction(); - - pactffi_create_mock_server = pactffi - .lookup>( - 'pactffi_create_mock_server') - .asFunction(); - - pactffi_create_mock_server_for_pact = pactffi - .lookup>( - 'pactffi_create_mock_server_for_pact') - .asFunction(); - - pactffi_write_pact_file = pactffi - .lookup>( - 'pactffi_write_pact_file') - .asFunction(); - - pactffi_mock_server_matched = pactffi - .lookup>( - 'pactffi_mock_server_matched') - .asFunction(); - - pactffi_mock_server_mismatches = pactffi - .lookup>( - 'pactffi_mock_server_mismatches') - .asFunction(); - - pactffi_with_header = pactffi - .lookup>( - 'pactffi_with_header') - .asFunction(); - - pactffi_with_query_parameter = pactffi - .lookup>( - 'pactffi_with_query_parameter') - .asFunction(); - - pactffi_with_query_parameter_v2 = pactffi - .lookup>( - 'pactffi_with_query_parameter_v2') - .asFunction(); - - pactffi_cleanup_mock_server = pactffi - .lookup>( - 'pactffi_cleanup_mock_server') - .asFunction(); - - pactffi_mismatch_description = pactffi - .lookup>( - 'pactffi_mismatch_description') - .asFunction(); - } +NativeLibrary? _cachedBindings; +NativeLibrary get bindings { + var pactffi = openLibrary(); + return _cachedBindings ??= NativeLibrary(pactffi); } - -PactFFIBindings? _cachedBindings; -PactFFIBindings get bindings => _cachedBindings ??= PactFFIBindings(); diff --git a/lib/src/bindings/signatures.dart b/lib/src/bindings/signatures.dart deleted file mode 100644 index e06e2d4..0000000 --- a/lib/src/bindings/signatures.dart +++ /dev/null @@ -1,169 +0,0 @@ -import 'dart:ffi'; - -import 'package:ffi/ffi.dart'; - -import 'types.dart'; - -/// c_char -> Pointer -/// bool -> Int8 -/// i32 -> Int32 -/// size_t -> IntPtr - -// -typedef pactffi_init_native = Void Function(Pointer log_env_var); - -typedef pactffi_version_native = Pointer Function(); - -/// TODO -typedef generate_regex_value_internal_native = Void Function(); - -/// TODO -typedef pactffi_check_regex_native = Void Function(); - -typedef pactffi_cleanup_mock_server_native = Int8 Function( - Int32 mock_server_port); - -typedef pactffi_create_mock_server_native = Int32 Function( - Pointer pact_str, Pointer addr_str, Int8 bool); - -typedef pactffi_create_mock_server_for_pact_native = Int32 Function( - PactHandle pact, Pointer addr_str, Int8 bool); - -typedef pactffi_free_string_native = Void Function(Pointer s); - -/// TODO -typedef pactffi_generate_datetime_string_native = Void Function(); - -/// TODO -typedef pactffi_generate_regex_value_native = Void Function(); - -typedef pactffi_get_tls_ca_certificate_native = Pointer Function(); - -typedef pactffi_given_native = Int8 Function( - InteractionHandle interaction, Pointer description); - -typedef pactffi_given_with_param_native = Int8 Function( - InteractionHandle interaction, - Pointer description, - Pointer name, - Pointer value); - -typedef pactffi_message_expects_to_receive_native = Void Function( - MessageHandle message, Pointer description); - -typedef pactffi_message_given_native = Void Function( - MessageHandle message, Pointer description); - -typedef pactffi_message_given_with_param_native = Void Function( - MessageHandle message, - Pointer description, - Pointer name, - Pointer value); - -typedef pactffi_message_reify_native = Pointer Function( - MessageHandle message); - -typedef pactffi_message_with_contents_native = Void Function( - MessageHandle message, Pointer content_type, Uint8 body, IntPtr size); - -typedef pactffi_message_with_metadata_native = Void Function( - MessageHandle message, Pointer key, Pointer value); - -typedef pactffi_mock_server_logs_native = Pointer Function( - Int32 mock_server_port); - -typedef pactffi_mock_server_matched_native = Int8 Function( - Int32 mock_server_port); - -/// External interface to get all the mismatches from a mock server. The port number of the -/// mock server is passed in, and a pointer to a C string with the mismatches in JSON -/// format is returned. -/// -/// https://docs.rs/pact_ffi/0.3.3/pact_ffi/mock_server/fn.pactffi_mock_server_mismatches.html -/// https://docs.rs/pact_ffi/0.3.3/src/pact_ffi/mock_server/mod.rs.html#391-414 -typedef pactffi_mock_server_mismatches_native = Pointer Function( - Int32 mock_server_port); - -typedef pactffi_new_interaction_native = InteractionHandle Function( - PactHandle pact, Pointer description); - -typedef pactffi_new_message_native = MessageHandle Function( - MessagePactHandle pact, - Pointer description, -); - -typedef pactffi_new_message_pact_native = MessagePactHandle Function( - Pointer consumer_name, Pointer provider_name); - -typedef pactffi_new_pact_native = PactHandle Function( - Pointer consumer_name, Pointer provider_name); - -typedef pactffi_response_status_native = Int8 Function( - InteractionHandle interaction, Int16 status); - -typedef pactffi_upon_receiving_native = Int8 Function( - InteractionHandle interaction, Pointer description); - -typedef pactffi_with_binary_file_native = Int8 Function( - InteractionHandle interaction, - InteractionPart part, - Pointer content_type, - Pointer body, // TODO: body: *const u8, - IntPtr size); - -typedef pactffi_with_body_native = Int8 Function(InteractionHandle interaction, - Int8 part, Pointer content_type, Pointer body); - -typedef pactffi_with_header_native = Int8 Function( - InteractionHandle interaction, - Int8 part, - Pointer name, - IntPtr index, - Pointer value); - -typedef pactffi_with_message_pact_metadata_native = Void Function( - MessagePactHandle pact, - Pointer namespace, - Pointer name, - Pointer value); - -typedef pactffi_with_multipart_file_native = StringResult Function( - InteractionHandle interaction, - InteractionPart part, - Pointer content_type, - Pointer file, - Pointer part_name); - -typedef pactffi_with_pact_metadata_native = Int8 Function(PactHandle pact, - Pointer namespace, Pointer name, Pointer value); - -typedef pactffi_with_query_parameter_native = Int8 Function( - InteractionHandle interaction, - Pointer name, - IntPtr size, - Pointer value); - -typedef pactffi_with_query_parameter_v2_native = Int8 Function( - InteractionHandle interaction, - Pointer name, - IntPtr index, - Pointer value); - -typedef pactffi_with_request_native = Int8 Function( - InteractionHandle interaction, Pointer method, Pointer path); - -typedef pactffi_with_specification_native = Int8 Function( - PactHandle pact, PactSpecification version); - -typedef pactffi_write_message_pact_file_native = Int32 Function( - MessagePactHandle pact, Pointer directory, Int8 overwrite); - -typedef pactffi_write_pact_file_native = Int32 Function( - Int32 mock_server_port, Pointer directory, Int8 overwrite); - -/// Get a description of a mismatch. -/// -/// https://docs.rs/pact_ffi/0.3.3/pact_ffi/fn.pactffi_mismatch_description.html -/// https://docs.rs/pact_ffi/0.3.3/src/pact_ffi/lib.rs.html#265-274 -typedef pactffi_mismatch_description_native = Pointer Function( - Pointer mismatch); diff --git a/lib/src/bindings/types.dart b/lib/src/bindings/types.dart deleted file mode 100644 index c4dd422..0000000 --- a/lib/src/bindings/types.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'dart:ffi'; - -/// https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/handles/struct.PactHandle.html -class PactHandle extends Struct { - external Pointer pact_ref; -} - -/// https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/handles/struct.MessagePactHandle.html -class MessagePactHandle extends Struct { - external Pointer pact_ref; -} - -/// https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/handles/struct.InteractionHandle.html -class InteractionHandle extends Struct { - external Pointer interaction_ref; -} - -/// https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/handles/struct.MessageHandle.html -class MessageHandle extends Struct { - external Pointer interaction_ref; -} - -enum InteractionPart { - Request, - Response, -} - -extension InteractionPartExtensionMap on InteractionPart { - static const values = [0, 1]; - int get value => values[index]; -} - -enum StringResult { - Ok, - Failed, -} - -extension StringResultExtensionMap on StringResult { - static const values = [0, 1]; - int get value => values[index]; -} - -enum PactSpecification { Unkown, V1, V1_1, V2, V3, V4 } diff --git a/lib/src/ffi/extensions.dart b/lib/src/ffi/extensions.dart deleted file mode 100644 index 9f80636..0000000 --- a/lib/src/ffi/extensions.dart +++ /dev/null @@ -1,7 +0,0 @@ -extension ToInt on bool { - int toInt() => this ? 1 : 0; -} - -extension ToBool on int { - bool toBool() => this == 1 ? true : false; -} diff --git a/lib/src/interaction.dart b/lib/src/interaction.dart index 0bb4c58..03c836a 100644 --- a/lib/src/interaction.dart +++ b/lib/src/interaction.dart @@ -3,15 +3,15 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:pact_dart/src/bindings/bindings.dart'; -import 'package:pact_dart/src/bindings/types.dart'; +import 'package:pact_dart/gen/library.dart'; import 'package:pact_dart/src/errors.dart'; import 'package:pact_dart/src/utils/content_type.dart'; class Interaction { - late InteractionHandle interaction; + late int interaction; - Interaction(PactHandle handle, String description) { - final nativeDescription = description.toNativeUtf8(); + Interaction(int handle, String description) { + final nativeDescription = description.toNativeUtf8().cast(); try { interaction = bindings.pactffi_new_interaction(handle, nativeDescription); @@ -25,12 +25,12 @@ class Interaction { throw EmptyParameterError('providerState'); } - final cProviderState = providerState.toNativeUtf8(); + final cProviderState = providerState.toNativeUtf8().cast(); try { if (params != null && params.isNotEmpty) { params.forEach((key, value) { - final cKey = key.toNativeUtf8(); - final cValue = value.toNativeUtf8(); + final cKey = key.toNativeUtf8().cast(); + final cValue = value.toNativeUtf8().cast(); try { bindings.pactffi_given_with_param( @@ -59,7 +59,7 @@ class Interaction { throw EmptyParameterError('description'); } - final cDescription = description.toNativeUtf8(); + final cDescription = description.toNativeUtf8().cast(); try { bindings.pactffi_upon_receiving(interaction, cDescription); } finally { @@ -69,11 +69,11 @@ class Interaction { return this; } - void _withHeaders(InteractionPart part, Map headers) { + void _withHeaders(int part, Map headers) { headers.forEach((key, value) { - final cPart = part.value; - final cKey = key.toNativeUtf8(); - final cValue = value.toNativeUtf8(); + final cPart = part; + final cKey = key.toNativeUtf8().cast(); + final cValue = value.toNativeUtf8().cast(); try { // TODO: `pactffi_with_header` and `pactffi_with_query_parameter` support an index field that @@ -86,19 +86,19 @@ class Interaction { }); } - void _withBody(InteractionPart part, T body, String? contentType) { - Pointer cContentType; + void _withBody(int part, T body, String? contentType) { + Pointer cContentType; if (contentType != null) { - cContentType = contentType.toNativeUtf8(); + cContentType = contentType.toNativeUtf8().cast(); } else { - cContentType = getContentType(body).toNativeUtf8(); + cContentType = getContentType(body).toNativeUtf8().cast(); } - final cBody = jsonEncode(body).toNativeUtf8(); + final cBody = jsonEncode(body).toNativeUtf8().cast(); try { - bindings.pactffi_with_body(interaction, part.value, cContentType, cBody); + bindings.pactffi_with_body(interaction, part, cContentType, cBody); } finally { calloc.free(cContentType); calloc.free(cBody); @@ -107,24 +107,24 @@ class Interaction { void _withQuery(Map query) { query.forEach((key, value) { - final cKey = key.toNativeUtf8(); - Pointer? cValue; + final cKey = key.toNativeUtf8().cast(); + Pointer? cValue; try { if (value is Map) { // Handle matcher map from PactMatchers - cValue = jsonEncode(value).toNativeUtf8(); + cValue = jsonEncode(value).toNativeUtf8().cast(); bindings.pactffi_with_query_parameter_v2( interaction, cKey, 0, cValue); } else if (value is List) { // Handle multiple values as a list without matchers final json = {'value': value}; - cValue = jsonEncode(json).toNativeUtf8(); + cValue = jsonEncode(json).toNativeUtf8().cast(); bindings.pactffi_with_query_parameter_v2( interaction, cKey, 0, cValue); } else { // Simple string value - cValue = value.toString().toNativeUtf8(); + cValue = value.toString().toNativeUtf8().cast(); bindings.pactffi_with_query_parameter_v2( interaction, cKey, 0, cValue); } @@ -158,8 +158,8 @@ class Interaction { throw EmptyParametersError(['method', 'path']); } - final cMethod = method.toNativeUtf8(); - final cPath = path.toNativeUtf8(); + final cMethod = method.toNativeUtf8().cast(); + final cPath = path.toNativeUtf8().cast(); try { bindings.pactffi_with_request(interaction, cMethod, cPath); @@ -169,7 +169,7 @@ class Interaction { } if (headers != null) { - _withHeaders(InteractionPart.Request, headers); + _withHeaders(InteractionPart.InteractionPart_Request, headers); } if (query != null) { @@ -177,7 +177,7 @@ class Interaction { } if (body != null) { - _withBody(InteractionPart.Request, body, contentType); + _withBody(InteractionPart.InteractionPart_Request, body, contentType); } return this; @@ -192,11 +192,11 @@ class Interaction { bindings.pactffi_response_status(interaction, status); if (headers != null) { - _withHeaders(InteractionPart.Response, headers); + _withHeaders(InteractionPart.InteractionPart_Response, headers); } if (body != null) { - _withBody(InteractionPart.Response, body, contentType); + _withBody(InteractionPart.InteractionPart_Response, body, contentType); } return this; diff --git a/lib/src/pact_mock_service.dart b/lib/src/pact_mock_service.dart index 995f63d..b9310d0 100644 --- a/lib/src/pact_mock_service.dart +++ b/lib/src/pact_mock_service.dart @@ -1,9 +1,8 @@ +import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import 'package:pact_dart/src/ffi/extensions.dart'; import 'package:pact_dart/src/errors.dart'; import 'package:pact_dart/src/interaction.dart'; -import 'package:pact_dart/src/bindings/types.dart'; import 'package:pact_dart/src/bindings/bindings.dart'; import 'package:pact_dart/src/bindings/constants.dart'; @@ -13,22 +12,22 @@ class PactMockService { int port = 1235; String host = '127.0.0.1'; - late PactHandle handle; + late int handle; late Interaction currentInteraction; List interactions = []; PactMockService(String consumer, String provider, {String? host, int? port, String logLevelEnv = 'PACT_LOG_LEVEL'}) { - final logLevelEnvAsUtf8 = logLevelEnv.toNativeUtf8(); + final logLevelEnvAsUtf8 = logLevelEnv.toNativeUtf8().cast(); try { bindings.pactffi_init(logLevelEnvAsUtf8); } finally { calloc.free(logLevelEnvAsUtf8); } - final consumerAsUtf8 = consumer.toNativeUtf8(); - final providerAsUtf8 = provider.toNativeUtf8(); + final consumerAsUtf8 = consumer.toNativeUtf8().cast(); + final providerAsUtf8 = provider.toNativeUtf8().cast(); try { handle = bindings.pactffi_new_pact(consumerAsUtf8, providerAsUtf8); @@ -51,11 +50,11 @@ class PactMockService { } bool hasMatchedInteractions() { - return bindings.pactffi_mock_server_matched(port).toBool(); + return bindings.pactffi_mock_server_matched(port); } bool reset() { - return bindings.pactffi_cleanup_mock_server(port).toBool(); + return bindings.pactffi_cleanup_mock_server(port); } /// Creates a new "Interaction" that describes the interaction @@ -80,10 +79,10 @@ class PactMockService { } log.info('Starting mock server on', addr); - final addrUtf8 = addr.toNativeUtf8(); + final addrUtf8 = addr.toNativeUtf8().cast(); try { final portOrStatus = bindings.pactffi_create_mock_server_for_pact( - handle, addrUtf8, secure.toInt()); + handle, addrUtf8, secure); if (portOrStatus != port) { throw PactCreateMockServerError(portOrStatus); @@ -100,15 +99,16 @@ class PactMockService { final hasMatchedInteractions = this.hasMatchedInteractions(); if (!hasMatchedInteractions) { - final mismatches = - bindings.pactffi_mock_server_mismatches(port).toDartString(); + final mismatches = bindings + .pactffi_mock_server_mismatches(port) + .cast() + .toDartString(); throw PactMatchFailure(mismatches); } - final dir = directory.toNativeUtf8(); + final dir = directory.toNativeUtf8().cast(); try { - final result = - bindings.pactffi_write_pact_file(port, dir, overwrite.toInt()); + final result = bindings.pactffi_write_pact_file(port, dir, overwrite); if (result != PactWriteStatusCodes.OK) { throw PactWriteError(result); diff --git a/pubspec.lock b/pubspec.lock index 4987fb4..6d5a5da 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + cli_util: + dependency: transitive + description: + name: cli_util + sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c + url: "https://pub.dev" + source: hosted + version: "0.4.2" collection: dependency: transitive description: @@ -89,14 +97,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" + ffigen: + dependency: "direct dev" + description: + name: ffigen + sha256: "4bbf1fa19723a90578e991b9a95afca43bea856809890a26609618fa29087427" + url: "https://pub.dev" + source: hosted + version: "7.2.11" file: dependency: transitive description: name: file - sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" url: "https://pub.dev" source: hosted - version: "7.0.1" + version: "6.1.4" frontend_server_client: dependency: transitive description: @@ -225,6 +241,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.0" + quiver: + dependency: transitive + description: + name: quiver + sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2 + url: "https://pub.dev" + source: hosted + version: "3.2.2" shelf: dependency: transitive description: @@ -401,5 +425,13 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.3" + yaml_edit: + dependency: transitive + description: + name: yaml_edit + sha256: fb38626579fb345ad00e674e2af3a5c9b0cc4b9bfb8fd7f7ff322c7c9e62aef5 + url: "https://pub.dev" + source: hosted + version: "2.2.2" sdks: dart: ">=3.5.0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 4642787..aeb7749 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,6 +15,13 @@ dependencies: dev_dependencies: test: ^1.17.10 + ffigen: ^7.2.11 executables: install: + +ffigen: + output: 'lib/gen/library.dart' + headers: + entry-points: + - 'pact.h'