blob: fbca95276ed5f83bc1e80943c29ea59520008713 [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library FfiTest;
import 'dart:ffi' as ffi;
/// Sample struct for dart:ffi library.
class Coordinate extends ffi.Pointer<ffi.Void> {
double x;
double y;
Coordinate next;
/// generated by @ffi.struct annotation
external static int sizeOf();
Coordinate offsetBy(int offsetInBytes) =>
Coordinate elementAt(int index) => offsetBy(sizeOf() * index);
static Coordinate allocate({int count: 1}) =>
ffi.allocate<ffi.Uint8>(count: count * sizeOf()).cast();
/// Allocate a new [Coordinate] in C memory and populate its fields.
factory Coordinate(double x, double y, Coordinate next) {
Coordinate result = Coordinate.allocate()
..x = x
..y = y = next;
return result;