18#ifndef INCLUDED_BINARYSERIALIZER
19#define INCLUDED_BINARYSERIALIZER
51 if (ch == traits_type::eof())
52 return traits_type::not_eof(ch);
63 std::ptrdiff_t n = pptr() - pbase();
72 std::streamsize
xsputn(
const char* s, std::streamsize n)
89 void ScriptString(
const char* name, JS::HandleString
string);
92 static void Trace(JSTracer* trc,
void* data);
97 using ObjectTagMap = JS::GCHashMap<JS::Heap<JSObject*>,
u32, js::MovableCellHasher<JSObject*>, js::SystemAllocPolicy>;
119 template <
typename A>
171 m_Impl.Put(name, (
const u8*)&v,
sizeof(int32_t));
176 m_Impl.Put(name, (
const u8*)&value,
sizeof(
float));
181 m_Impl.Put(name, (
const u8*)&value,
sizeof(
double));
187 m_Impl.Put(name, (
const u8*)&v,
sizeof(int32_t));
190 virtual void PutBool(
const char* name,
bool value)
192 NumberU8(name, value ? 1 : 0, 0, 1);
195 virtual void PutString(
const char* name,
const std::string& value)
199 m_Impl.Put(name, (
u8*)value.data(), value.length());
207 virtual void PutRaw(
const char* name,
const u8* data,
size_t len)
209 m_Impl.Put(name, data, len);
#define to_le16(x)
Definition: byte_order.h:77
#define to_le32(x)
Definition: byte_order.h:78
PutScriptVal implementation details.
Definition: BinarySerializer.h:84
void ScriptString(const char *name, JS::HandleString string)
Definition: BinarySerializer.cpp:433
~CBinarySerializerScriptImpl()
Definition: BinarySerializer.cpp:67
void HandleScriptVal(JS::HandleValue val)
Definition: BinarySerializer.cpp:73
const ScriptInterface & m_ScriptInterface
Definition: BinarySerializer.h:94
u32 GetScriptBackrefTag(JS::HandleObject obj)
Definition: BinarySerializer.cpp:471
ObjectTagMap m_ScriptBackrefTags
Definition: BinarySerializer.h:98
static void Trace(JSTracer *trc, void *data)
Definition: BinarySerializer.cpp:465
JS::GCHashMap< JS::Heap< JSObject * >, u32, js::MovableCellHasher< JSObject * >, js::SystemAllocPolicy > ObjectTagMap
Definition: BinarySerializer.h:97
u32 m_ScriptBackrefsNext
Definition: BinarySerializer.h:99
ISerializer & m_Serializer
Definition: BinarySerializer.h:95
CBinarySerializerScriptImpl(const ScriptInterface &scriptInterface, ISerializer &serializer)
Definition: BinarySerializer.cpp:60
Serialize to a binary stream.
Definition: BinarySerializer.h:109
std::unique_ptr< CBinarySerializerScriptImpl > m_ScriptImpl
Definition: BinarySerializer.h:221
virtual void PutScriptVal(const char *name, JS::MutableHandleValue value)
Definition: BinarySerializer.h:202
T m_Impl
Definition: BinarySerializer.h:218
virtual void PutNumber(const char *name, float value)
Definition: BinarySerializer.h:174
virtual void PutNumber(const char *name, int8_t value)
Definition: BinarySerializer.h:145
std::ostream m_RawStream
Definition: BinarySerializer.h:224
virtual void PutNumber(const char *name, int16_t value)
Definition: BinarySerializer.h:156
NONCOPYABLE(CBinarySerializer)
CSerializerStreamBuf< T > m_RawStreamBuf
Definition: BinarySerializer.h:223
virtual void PutNumber(const char *name, fixed value)
Definition: BinarySerializer.h:184
virtual void PutNumber(const char *name, uint16_t value)
Definition: BinarySerializer.h:150
virtual void PutRaw(const char *name, const u8 *data, size_t len)
Definition: BinarySerializer.h:207
virtual void PutNumber(const char *name, uint8_t value)
Definition: BinarySerializer.h:140
virtual void PutNumber(const char *name, uint32_t value)
Definition: BinarySerializer.h:162
virtual void PutString(const char *name, const std::string &value)
Definition: BinarySerializer.h:195
virtual std::ostream & GetStream()
Returns a stream which can be used to serialize data directly.
Definition: BinarySerializer.h:212
CBinarySerializer(const ScriptInterface &scriptInterface, A &a)
Definition: BinarySerializer.h:120
virtual void PutNumber(const char *name, double value)
Definition: BinarySerializer.h:179
virtual void PutBool(const char *name, bool value)
Definition: BinarySerializer.h:190
CBinarySerializer(const ScriptInterface &scriptInterface)
Definition: BinarySerializer.h:112
virtual void PutNumber(const char *name, int32_t value)
Definition: BinarySerializer.h:168
A simple fixed-point number class.
Definition: Fixed.h:120
T GetInternalValue() const
Definition: Fixed.h:135
Wrapper for redirecting ostream writes to CBinarySerializer's impl.
Definition: BinarySerializer.h:35
NONCOPYABLE(CSerializerStreamBuf)
int sync()
Definition: BinarySerializer.h:61
char m_Buffer[2048]
Definition: BinarySerializer.h:38
int overflow(int ch)
Definition: BinarySerializer.h:49
CSerializerStreamBuf(T &impl)
Definition: BinarySerializer.h:40
std::streamsize xsputn(const char *s, std::streamsize n)
Definition: BinarySerializer.h:72
T & m_SerializerImpl
Definition: BinarySerializer.h:37
Serialization interface; see serialization overview.
Definition: ISerializer.h:121
void NumberU8(const char *name, uint8_t value, uint8_t lower, uint8_t upper)
Serialize a number, which must be lower <= value <= upper.
Definition: ISerializer.cpp:28
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
#define ARRAY_SIZE(name)
Definition: code_annotation.h:350
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:277
#define T(string_literal)
Definition: secure_crt.cpp:77
int32_t i32
Definition: types.h:34
uint8_t u8
Definition: types.h:37
uint16_t u16
Definition: types.h:38
int16_t i16
Definition: types.h:33
uint32_t u32
Definition: types.h:39
unsigned short uint16_t
Definition: wposix_types.h:52
unsigned int uint32_t
Definition: wposix_types.h:53
short int16_t
Definition: wposix_types.h:38
unsigned char uint8_t
Definition: wposix_types.h:51
signed char int8_t
Definition: wposix_types.h:37