Flutter Engine
buffer_conversions.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import "flutter/shell/platform/darwin/common/buffer_conversions.h"
6 
7 namespace flutter {
8 
9 std::vector<uint8_t> GetVectorFromNSData(NSData* data) {
10  const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data.bytes);
11  return std::vector<uint8_t>(bytes, bytes + data.length);
12 }
13 
14 NSData* GetNSDataFromVector(const std::vector<uint8_t>& buffer) {
15  return [NSData dataWithBytes:buffer.data() length:buffer.size()];
16 }
17 
18 std::unique_ptr<fml::Mapping> GetMappingFromNSData(NSData* data) {
19  return std::make_unique<fml::DataMapping>(GetVectorFromNSData(data));
20 }
21 
22 NSData* GetNSDataFromMapping(std::unique_ptr<fml::Mapping> mapping) {
23  return [NSData dataWithBytes:mapping->GetMapping() length:mapping->GetSize()];
24 }
25 
26 } // namespace flutter
std::unique_ptr< fml::Mapping > GetMappingFromNSData(NSData *data)
std::vector< uint8_t > GetVectorFromNSData(NSData *data)
size_t length
NSData * GetNSDataFromMapping(std::unique_ptr< fml::Mapping > mapping)
NSData * GetNSDataFromVector(const std::vector< uint8_t > &buffer)