Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:ffi
  3. Struct class
Struct
description

Struct classabstractbase

The supertype of all FFI struct types.

FFI struct types should extend this class and declare fields correspondingto the underlying native structure.

Field declarations in aStruct subclass declaration are automaticallygiven a setter and getter implementation which accesses the native struct'sfield in memory.

All field declarations in aStruct subclass declaration must either havetypeint ordouble and be annotated with aNativeType representing thenative type, or must be of typePointer,Array or a subtype ofStructorUnion. For example:

typedef struct { int a; float b; void* c;} my_struct;
final class MyStruct extends Struct {  @Int32()  external int a;  @Float()  external double b;  external Pointer<Void> c;}

The field declarations of aStruct subclassmust be markedexternal. Astruct subclass points directly into a location of native memory (Pointer)or Dart memory (TypedData), and the external field's getter and setterimplementations directly read and write bytes at appropriate offsets fromthat location. This does not allow for non-native fields to also exist.

An instance of a struct subclass cannot be created with a generativeconstructor. Instead, an instance can be created byStructPointer.ref,Struct.create, FFI call return values, FFI callback arguments,StructArray, and accessingStruct fields. To create an instance backedby native memory, useStructPointer.ref. To create an instance backed byDart memory, useStruct.create.

Implemented types
Available extensions

Constructors

Struct()
Construct a reference to thenullptr.

Properties

addressPointer<T>

Available on T, provided by theStructAddress extension

The memory address of the underlying data.
no setter
hashCodeint
The hash code for this object.
no setterinherited
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString()String
A string representation of this object.
inherited

Operators

operator ==(Objectother)bool
The equality operator.
inherited

Static Methods

create<T extendsStruct>([TypedDatatypedData,intoffset])→ T
Creates a struct view of bytes intypedData.
  1. Dart
  2. dart:ffi
  3. Struct class
dart:ffi library

[8]ページ先頭

©2009-2025 Movatter.jp