1 | // Copyright 2017 the V8 project 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 | #ifndef V8_WASM_WASM_SERIALIZATION_H_ |
6 | #define V8_WASM_WASM_SERIALIZATION_H_ |
7 | |
8 | #include "src/wasm/wasm-objects.h" |
9 | |
10 | namespace v8 { |
11 | namespace internal { |
12 | namespace wasm { |
13 | |
14 | // Support for serializing WebAssembly {NativeModule} objects. This class takes |
15 | // a snapshot of the module state at instantiation, and other code that modifies |
16 | // the module after that won't affect the serialized result. |
17 | class V8_EXPORT_PRIVATE WasmSerializer { |
18 | public: |
19 | explicit WasmSerializer(NativeModule* native_module); |
20 | |
21 | // Measure the required buffer size needed for serialization. |
22 | size_t GetSerializedNativeModuleSize() const; |
23 | |
24 | // Serialize the {NativeModule} into the provided {buffer}. Returns true on |
25 | // success and false if the given buffer it too small for serialization. |
26 | bool SerializeNativeModule(Vector<byte> buffer) const; |
27 | |
28 | private: |
29 | NativeModule* native_module_; |
30 | std::vector<WasmCode*> code_table_; |
31 | }; |
32 | |
33 | // Support for deserializing WebAssembly {NativeModule} objects. |
34 | // Checks the version header of the data against the current version. |
35 | bool IsSupportedVersion(Vector<const byte> data); |
36 | |
37 | // Deserializes the given data to create a Wasm module object. |
38 | MaybeHandle<WasmModuleObject> DeserializeNativeModule( |
39 | Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes); |
40 | |
41 | } // namespace wasm |
42 | } // namespace internal |
43 | } // namespace v8 |
44 | |
45 | #endif // V8_WASM_WASM_SERIALIZATION_H_ |
46 | |