2013-12-28 00:45:40 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include <string>
|
|
|
|
#include "util/serializer.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2013-12-28 02:07:19 +00:00
|
|
|
void serializer_core::write_unsigned(unsigned i) {
|
|
|
|
static_assert(sizeof(i) == 4, "unexpected unsigned size");
|
|
|
|
m_out.put((i >> 24) & 0xff);
|
|
|
|
m_out.put((i >> 16) & 0xff);
|
|
|
|
m_out.put((i >> 8) & 0xff);
|
|
|
|
m_out.put(i & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serializer_core::write_int(int i) {
|
|
|
|
static_assert(sizeof(i) == 4, "unexpected int size");
|
|
|
|
write_unsigned(i);
|
|
|
|
}
|
|
|
|
|
2013-12-28 00:45:40 +00:00
|
|
|
std::string deserializer_core::read_string() {
|
|
|
|
std::string r;
|
|
|
|
while (true) {
|
|
|
|
char c = m_in.get();
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
r += c;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2013-12-28 02:07:19 +00:00
|
|
|
|
|
|
|
unsigned deserializer_core::read_unsigned() {
|
|
|
|
unsigned r;
|
|
|
|
static_assert(sizeof(r) == 4, "unexpected unsigned size");
|
|
|
|
r = static_cast<unsigned>(m_in.get()) << 24;
|
|
|
|
r |= static_cast<unsigned>(m_in.get()) << 16;
|
|
|
|
r |= static_cast<unsigned>(m_in.get()) << 8;
|
|
|
|
r |= static_cast<unsigned>(m_in.get());
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int deserializer_core::read_int() {
|
|
|
|
return read_unsigned();
|
|
|
|
}
|
2013-12-28 00:45:40 +00:00
|
|
|
}
|