Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.oxd.sh/llms.txt

Use this file to discover all available pages before exploring further.

Setup

Dart calls the C library directly via dart:ffi. Add the ffi package for memory helpers:
# pubspec.yaml
dependencies:
  ffi: ^2.1.0
Place native libraries per platform:
  • Android: android/app/src/main/jniLibs/{abi}/liboxaccel.so
  • iOS: Link liboxaccel.a in Xcode (static) or add via CocoaPods
  • Linux/macOS/Windows: Place next to executable or in system library path

Usage

import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
import 'package:ffi/ffi.dart';

// C struct layouts
final class OxAccelConfig extends Struct {
  external Pointer<Utf8> api_key;
  external Pointer<Utf8> relay_host;
  @Uint16() external int relay_port;
  @Bool()   external bool enable_fec;
  @Bool()   external bool enable_compression;
  @Bool()   external bool enable_multipath;
}

final class AccelStats extends Struct {
  @Uint64() external int packets_sent;
  @Uint64() external int packets_recv;
  @Uint64() external int bytes_sent;
  @Uint64() external int bytes_recv;
}

// Load library
DynamicLibrary _loadLib() {
  if (Platform.isAndroid) return DynamicLibrary.open('liboxaccel.so');
  if (Platform.isIOS)     return DynamicLibrary.process(); // statically linked
  if (Platform.isLinux)   return DynamicLibrary.open('liboxaccel.so');
  if (Platform.isMacOS)   return DynamicLibrary.open('liboxaccel.dylib');
  if (Platform.isWindows) return DynamicLibrary.open('oxaccel.dll');
  throw UnsupportedError('Unsupported platform');
}

final _lib = _loadLib();

// Bind functions
final _create = _lib.lookupFunction<
    Pointer<Void> Function(Pointer<OxAccelConfig>),
    Pointer<Void> Function(Pointer<OxAccelConfig>)>('ox_accel_create');
final _connect = _lib.lookupFunction<
    Int32 Function(Pointer<Void>),
    int Function(Pointer<Void>)>('ox_accel_connect');
final _send = _lib.lookupFunction<
    Int32 Function(Pointer<Void>, Pointer<Uint8>, IntPtr),
    int Function(Pointer<Void>, Pointer<Uint8>, int)>('ox_accel_send');
final _recv = _lib.lookupFunction<
    Int32 Function(Pointer<Void>, Pointer<Uint8>, IntPtr, Pointer<IntPtr>),
    int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<IntPtr>)>('ox_accel_recv');
final _stats = _lib.lookupFunction<
    Int32 Function(Pointer<Void>, Pointer<AccelStats>),
    int Function(Pointer<Void>, Pointer<AccelStats>)>('ox_accel_stats');
final _destroy = _lib.lookupFunction<
    Void Function(Pointer<Void>),
    void Function(Pointer<Void>)>('ox_accel_destroy');
final _version = _lib.lookupFunction<
    Pointer<Utf8> Function(),
    Pointer<Utf8> Function()>('ox_accel_version');

void main() {
  print('Oxidize Accel SDK v${_version().toDartString()}');

  final cfg = calloc<OxAccelConfig>();
  cfg.ref.api_key    = 'your-api-key'.toNativeUtf8();
  cfg.ref.relay_host = 'relay.oxd.sh'.toNativeUtf8();
  cfg.ref.relay_port = 51820;
  cfg.ref.enable_fec = true;
  cfg.ref.enable_multipath = true;

  final ctx = _create(cfg);
  calloc.free(cfg.ref.api_key);
  calloc.free(cfg.ref.relay_host);
  calloc.free(cfg);

  if (ctx == nullptr) throw Exception('Failed to create context');

  try {
    var err = _connect(ctx);
    if (err != 0) throw Exception('Connect failed: $err');

    // Send
    final payload = Uint8List.fromList('hello world'.codeUnits);
    final nativeBuf = calloc<Uint8>(payload.length);
    nativeBuf.asTypedList(payload.length).setAll(0, payload);
    err = _send(ctx, nativeBuf, payload.length);
    calloc.free(nativeBuf);

    // Recv
    final recvBuf = calloc<Uint8>(65536);
    final received = calloc<IntPtr>();
    err = _recv(ctx, recvBuf, 65536, received);
    if (err == 0) print('Received ${received.value} bytes');
    calloc.free(recvBuf);
    calloc.free(received);

    // Stats
    final st = calloc<AccelStats>();
    _stats(ctx, st);
    print('Sent: ${st.ref.packets_sent} pkts / ${st.ref.bytes_sent} bytes');
    calloc.free(st);
  } finally {
    _destroy(ctx);
  }
}

Flutter plugin structure

For a Flutter plugin that bundles Accel:
# pubspec.yaml
flutter:
  plugin:
    platforms:
      android:
        ffiPlugin: true
      ios:
        ffiPlugin: true
      linux:
        ffiPlugin: true
      macos:
        ffiPlugin: true
      windows:
        ffiPlugin: true
With ffiPlugin: true, Flutter auto-discovers the native library. Place it at:
  • android/src/main/jniLibs/{abi}/liboxaccel.so
  • ios/Frameworks/liboxaccel.a
  • linux/liboxaccel.so, macos/liboxaccel.dylib, windows/oxaccel.dll
On iOS, DynamicLibrary.process() loads statically linked symbols. Add liboxaccel.a to your Xcode target’s link libraries and use -force_load if symbols aren’t found.