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#include "flutter/shell/platform/darwin/common/buffer_conversions.h" 6 7namespace flutter { 8 9std::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 14NSData* GetNSDataFromVector(const std::vector<uint8_t>& buffer) { 15 return [NSData dataWithBytes:buffer.data() length:buffer.size()]; 16} 17 18std::unique_ptr<fml::Mapping> GetMappingFromNSData(NSData* data) { 19 return std::make_unique<fml::DataMapping>(GetVectorFromNSData(data)); 20} 21 22NSData* GetNSDataFromMapping(std::unique_ptr<fml::Mapping> mapping) { 23 return [NSData dataWithBytes:mapping->GetMapping() length:mapping->GetSize()]; 24} 25 26} // namespace flutter 27