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 59 of file dart_byte_data.cc.

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

60  : data_(nullptr), length_in_bytes_(0), dart_handle_(list) {
61  if (Dart_IsNull(list))
62  return;
63 
64  Dart_TypedData_Type type;
65  Dart_TypedDataAcquireData(list, &type, &data_, &length_in_bytes_);
66  TONIC_DCHECK(!LogIfError(list));
67  if (type != Dart_TypedData_kByteData)
68  Dart_ThrowException(ToDart("Non-genuine ByteData passed to engine."));
69 }
#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 71 of file dart_byte_data.cc.

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

◆ DartByteData() [3/3]

tonic::DartByteData::DartByteData ( )

Definition at line 41 of file dart_byte_data.cc.

References data(), and length.

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

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

◆ ~DartByteData()

tonic::DartByteData::~DartByteData ( )

Definition at line 79 of file dart_byte_data.cc.

References Release().

79  {
80  Release();
81 }
void Release() const

Member Function Documentation

◆ Copy()

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

Definition at line 83 of file dart_byte_data.cc.

Referenced by dart_handle().

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

◆ Create()

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

Definition at line 27 of file dart_byte_data.cc.

References data(), and TONIC_DCHECK.

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

27  {
28  if (length < kExternalSizeThreshold) {
29  auto handle = DartByteData{data, length}.dart_handle();
30  // The destructor should release the typed data.
31  return handle;
32  } else {
33  void* buf = ::malloc(length);
34  TONIC_DCHECK(buf);
35  ::memcpy(buf, data, length);
36  return Dart_NewExternalTypedDataWithFinalizer(
37  Dart_TypedData_kByteData, buf, length, buf, length, FreeFinalizer);
38  }
39 }
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()

size_t tonic::DartByteData::length_in_bytes ( ) const
inline

◆ 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 88 of file dart_byte_data.cc.

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

88  {
89  if (data_) {
90  Dart_TypedDataReleaseData(dart_handle_);
91  data_ = nullptr;
92  }
93 }

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