1 // Copyright 2019 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNWIRE_WIREDESERIALIZEALLOCATOR_H_
16 #define DAWNWIRE_WIREDESERIALIZEALLOCATOR_H_
17 
18 #include "dawn_wire/WireCmd_autogen.h"
19 
20 #include <vector>
21 
22 namespace dawn_wire {
23     // A really really simple implementation of the DeserializeAllocator. It's main feature
24     // is that it has some inline storage so as to avoid allocations for the majority of
25     // commands.
26     class WireDeserializeAllocator : public DeserializeAllocator {
27       public:
28         WireDeserializeAllocator();
29         virtual ~WireDeserializeAllocator();
30 
31         void* GetSpace(size_t size) override;
32 
33         void Reset();
34 
35       private:
36         size_t mRemainingSize = 0;
37         char* mCurrentBuffer = nullptr;
38         char mStaticBuffer[2048];
39         std::vector<char*> mAllocations;
40     };
41 }  // namespace dawn_wire
42 
43 #endif  // DAWNWIRE_WIREDESERIALIZEALLOCATOR_H_
44