1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkFlattenableSerialization.h" 9 10 #include "SkData.h" 11 #include "SkValidatingReadBuffer.h" 12 #include "SkOrderedWriteBuffer.h" 13 14 SkData* SkValidatingSerializeFlattenable(SkFlattenable* flattenable) { 15 SkOrderedWriteBuffer writer(1024); 16 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); 17 writer.writeFlattenable(flattenable); 18 uint32_t size = writer.bytesWritten(); 19 void* data = sk_malloc_throw(size); 20 writer.writeToMemory(data); 21 return SkData::NewFromMalloc(data, size); 22 } 23 24 SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size, 25 SkFlattenable::Type type) { 26 SkValidatingReadBuffer buffer(data, size); 27 return buffer.readFlattenable(type); 28 } 29