Flutter Engine
tonic::DartByteData Class Reference

#include <dart_byte_data.h>

Public Member Functions

 DartByteData (Dart_Handle list)
 
 DartByteData (DartByteData &&other)
 
 DartByteData ()
 
 ~DartByteData ()
 
const void * data () const
 
void * data ()
 
size_t length_in_bytes () const
 
Dart_Handle dart_handle () const
 
std::vector< char > Copy () const
 
void Release () const
 
 operator bool () const
 

Static Public Member Functions

static Dart_Handle Create (const void *data, size_t length)
 

Detailed Description

Definition at line 15 of file dart_byte_data.h.

Constructor & Destructor Documentation

◆ DartByteData() [1/3]

tonic::DartByteData::DartByteData ( Dart_Handle  list)
explicit

Definition at line 57 of file dart_byte_data.cc.

References tonic::LogIfError(), tonic::ToDart(), TONIC_DCHECK, and type.

58  : data_(nullptr), length_in_bytes_(0), dart_handle_(list) {
59  if (Dart_IsNull(list))
60  return;
61 
62  Dart_TypedData_Type type;
63  Dart_TypedDataAcquireData(list, &type, &data_, &length_in_bytes_);
64  TONIC_DCHECK(!LogIfError(list));
65  if (type != Dart_TypedData_kByteData)
66  Dart_ThrowException(ToDart("Non-genuine ByteData passed to engine."));
67 }
KeyCallType type
#define TONIC_DCHECK
Definition: macros.h:32
Dart_Handle ToDart(const T &object)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ DartByteData() [2/3]

tonic::DartByteData::DartByteData ( DartByteData &&  other)

Definition at line 69 of file dart_byte_data.cc.

70  : data_(other.data_),
71  length_in_bytes_(other.length_in_bytes_),
72  dart_handle_(other.dart_handle_) {
73  other.data_ = nullptr;
74  other.dart_handle_ = nullptr;
75 }

◆ DartByteData() [3/3]

tonic::DartByteData::DartByteData ( )

Definition at line 39 of file dart_byte_data.cc.

References data(), length, and type.

Referenced by tonic::DartConverter< DartByteData >::FromArguments(), and operator bool().

40  : data_(nullptr), length_in_bytes_(0), dart_handle_(nullptr) {}

◆ ~DartByteData()

tonic::DartByteData::~DartByteData ( )

Definition at line 77 of file dart_byte_data.cc.

References Release().

77  {
78  Release();
79 }
void Release() const

Member Function Documentation

◆ Copy()

std::vector< char > tonic::DartByteData::Copy ( ) const

Definition at line 81 of file dart_byte_data.cc.

Referenced by dart_handle().

81  {
82  const char* ptr = static_cast<const char*>(data_);
83  return std::vector<char>(ptr, ptr + length_in_bytes_);
84 }

◆ Create()

Dart_Handle tonic::DartByteData::Create ( const void *  data,
size_t  length 
)
static

Definition at line 25 of file dart_byte_data.cc.

References data(), and TONIC_DCHECK.

Referenced by flutter::PlatformMessageResponseDart::Complete(), flutter::Window::DispatchKeyDataPacket(), and flutter::Window::DispatchPointerDataPacket().

25  {
26  if (length < kExternalSizeThreshold) {
27  auto handle = DartByteData{data, length}.dart_handle();
28  // The destructor should release the typed data.
29  return handle;
30  } else {
31  void* buf = ::malloc(length);
32  TONIC_DCHECK(buf);
33  ::memcpy(buf, data, length);
34  return Dart_NewExternalTypedDataWithFinalizer(
35  Dart_TypedData_kByteData, buf, length, buf, length, FreeFinalizer);
36  }
37 }
const void * data() const
#define TONIC_DCHECK
Definition: macros.h:32
size_t length

◆ dart_handle()

Dart_Handle tonic::DartByteData::dart_handle ( ) const
inline

Definition at line 27 of file dart_byte_data.h.

References Copy(), and Release().

Referenced by tonic::DartConverter< DartByteData >::SetReturnValue().

27 { return dart_handle_; }

◆ data() [1/2]

◆ data() [2/2]

void* tonic::DartByteData::data ( )
inline

Definition at line 25 of file dart_byte_data.h.

25 { return data_; }

◆ length_in_bytes()

◆ operator bool()

tonic::DartByteData::operator bool ( ) const
inlineexplicit

Definition at line 32 of file dart_byte_data.h.

References DartByteData().

32 { return data_ != nullptr; }

◆ Release()

void tonic::DartByteData::Release ( ) const

Definition at line 86 of file dart_byte_data.cc.

Referenced by zircon::dart::System::ChannelWrite(), zircon::dart::System::ChannelWriteEtc(), dart_handle(), zircon::dart::System::SocketWrite(), zircon::dart::System::VmoWrite(), and ~DartByteData().

86  {
87  if (data_) {
88  Dart_TypedDataReleaseData(dart_handle_);
89  data_ = nullptr;
90  }
91 }

The documentation for this class was generated from the following files: