Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
StdDeserializer.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_STDDESERIALIZER
19#define INCLUDED_STDDESERIALIZER
20
21#include "IDeserializer.h"
22
23#include <string>
24#include <vector>
25
27{
29public:
30 CStdDeserializer(const ScriptInterface& scriptInterface, std::istream& stream);
31 virtual ~CStdDeserializer();
32
33 virtual void ScriptVal(const char* name, JS::MutableHandleValue out);
34 virtual void ScriptObjectAssign(const char* name, JS::HandleValue objVal);
35 virtual void ScriptString(const char* name, JS::MutableHandleString out);
36
37 virtual std::istream& GetStream();
38 virtual void RequireBytesInStream(size_t numBytes);
39
40 static void Trace(JSTracer *trc, void *data);
41
42 void TraceMember(JSTracer *trc);
43
44protected:
45 virtual void Get(const char* name, u8* data, size_t len);
46
47private:
48 JS::Value ReadScriptVal(const char* name, JS::HandleObject preexistingObject);
49 void ReadStringLatin1(const char* name, std::vector<JS::Latin1Char>& str);
50 void ReadStringUTF16(const char* name, std::u16string& str);
51
52 virtual void AddScriptBackref(JS::HandleObject obj);
53 virtual void GetScriptBackref(size_t tag, JS::MutableHandleObject ret);
54 std::vector<JS::Heap<JSObject*> > m_ScriptBackrefs;
55
57
58 std::istream& m_Stream;
59};
60
61#endif // INCLUDED_STDDESERIALIZER
Definition: StdDeserializer.h:27
std::istream & m_Stream
Definition: StdDeserializer.h:58
virtual void GetScriptBackref(size_t tag, JS::MutableHandleObject ret)
Definition: StdDeserializer.cpp:112
virtual void Get(const char *name, u8 *data, size_t len)
Definition: StdDeserializer.cpp:59
virtual void RequireBytesInStream(size_t numBytes)
Throws an exception if the stream definitely cannot provide the required number of bytes.
Definition: StdDeserializer.cpp:93
JS::Value ReadScriptVal(const char *name, JS::HandleObject preexistingObject)
Definition: StdDeserializer.cpp:120
void TraceMember(JSTracer *trc)
Definition: StdDeserializer.cpp:53
virtual std::istream & GetStream()
Returns a stream which can be used to deserialize data directly.
Definition: StdDeserializer.cpp:88
void ReadStringUTF16(const char *name, std::u16string &str)
Definition: StdDeserializer.cpp:447
virtual ~CStdDeserializer()
Definition: StdDeserializer.cpp:43
virtual void AddScriptBackref(JS::HandleObject obj)
Definition: StdDeserializer.cpp:107
const ScriptInterface & m_ScriptInterface
Definition: StdDeserializer.h:56
void ReadStringLatin1(const char *name, std::vector< JS::Latin1Char > &str)
Definition: StdDeserializer.cpp:438
virtual void ScriptString(const char *name, JS::MutableHandleString out)
Deserialize a JSString.
Definition: StdDeserializer.cpp:456
CStdDeserializer(const ScriptInterface &scriptInterface, std::istream &stream)
Definition: StdDeserializer.cpp:35
virtual void ScriptObjectAssign(const char *name, JS::HandleValue objVal)
Deserialize an object and assign its properties to objVal (Essentially equivalent to Object....
Definition: StdDeserializer.cpp:491
static void Trace(JSTracer *trc, void *data)
Definition: StdDeserializer.cpp:48
NONCOPYABLE(CStdDeserializer)
std::vector< JS::Heap< JSObject * > > m_ScriptBackrefs
Definition: StdDeserializer.h:54
virtual void ScriptVal(const char *name, JS::MutableHandleValue out)
Deserialize a JS::Value, replacing 'out'.
Definition: StdDeserializer.cpp:486
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:35
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
uint8_t u8
Definition: types.h:37
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:407