Prefab framework
This commit is contained in:
parent
c9a663c03c
commit
86b851eff6
25
main.cpp
25
main.cpp
@ -29,31 +29,6 @@
|
|||||||
using namespace metacall;
|
using namespace metacall;
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Serialization
|
|
||||||
//
|
|
||||||
|
|
||||||
namespace metacall {
|
|
||||||
|
|
||||||
|
|
||||||
bool serialize(Serializer* serializer, const char str[]) {
|
|
||||||
serializer->writeRaw(str, strlen(str) + 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool deserialize(Deserializer* deserializer, const char ** str) {
|
|
||||||
*str = reinterpret_cast<const char*>(deserializer->readRaw(1));
|
|
||||||
if (*str == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deserializer->readRaw(strlen(*str)) != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local functions
|
// Local functions
|
||||||
//
|
//
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "metacall.hpp"
|
#include "metacall.hpp"
|
||||||
|
#include "mc_binding.hpp"
|
||||||
|
|
||||||
namespace metacall {
|
namespace metacall {
|
||||||
|
|
||||||
|
84
mc_prefab.cpp
Normal file
84
mc_prefab.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2011 Alex Yatskov
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person
|
||||||
|
// obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without
|
||||||
|
// restriction, including without limitation the rights to use,
|
||||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the
|
||||||
|
// Software is furnished to do so, subject to the following
|
||||||
|
// conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "metacall.hpp"
|
||||||
|
#include "mc_prefab.hpp"
|
||||||
|
|
||||||
|
namespace metacall {
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Local functions
|
||||||
|
//
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static int genStrLen(const T str[]) {
|
||||||
|
int length = 0;
|
||||||
|
while (str[length] != 0) {
|
||||||
|
++length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static bool serializeStr(Serializer* serializer, const T str[]) {
|
||||||
|
serializer->writeRaw(str, sizeof(T) * (genStrLen(str) + 1));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static bool deserializeStr(Deserializer* deserializer, const T ** str) {
|
||||||
|
*str = reinterpret_cast<const T*>(deserializer->readRaw(1));
|
||||||
|
if (*str == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return deserializer->readRaw(genStrLen(*str)) != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Shared functions
|
||||||
|
//
|
||||||
|
|
||||||
|
bool serialize(Serializer* serializer, const char str[]) {
|
||||||
|
return serializeStr(serializer, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deserialize(Deserializer* deserializer, const char ** str) {
|
||||||
|
return deserializeStr(deserializer, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool serialize(Serializer* serializer, const wchar_t str[]) {
|
||||||
|
return serializeStr(serializer, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deserialize(Deserializer* deserializer, const wchar_t ** str) {
|
||||||
|
return deserializeStr(deserializer, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
37
mc_prefab.hpp
Normal file
37
mc_prefab.hpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2011 Alex Yatskov
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person
|
||||||
|
// obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without
|
||||||
|
// restriction, including without limitation the rights to use,
|
||||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the
|
||||||
|
// Software is furnished to do so, subject to the following
|
||||||
|
// conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace metacall {
|
||||||
|
|
||||||
|
|
||||||
|
bool serialize(Serializer* serializer, const char str[]);
|
||||||
|
bool deserialize(Deserializer* deserializer, const char ** str);
|
||||||
|
bool serialize(Serializer* serializer, const wchar_t str[]);
|
||||||
|
bool deserialize(Deserializer* deserializer, const wchar_t ** str);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -38,7 +38,7 @@ Token::Token(const char value[]) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::Token(const unsigned value) :
|
Token::Token(unsigned value) :
|
||||||
m_value(value)
|
m_value(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -62,3 +62,4 @@
|
|||||||
#include "mc_protocol-inl.hpp"
|
#include "mc_protocol-inl.hpp"
|
||||||
#include "mc_client.hpp"
|
#include "mc_client.hpp"
|
||||||
#include "mc_server.hpp"
|
#include "mc_server.hpp"
|
||||||
|
#include "mc_prefab.hpp"
|
||||||
|
@ -11,7 +11,8 @@ SOURCES += main.cpp \
|
|||||||
mc_protocol.cpp \
|
mc_protocol.cpp \
|
||||||
mc_client.cpp \
|
mc_client.cpp \
|
||||||
mc_buffer.cpp \
|
mc_buffer.cpp \
|
||||||
mc_binding.cpp
|
mc_binding.cpp \
|
||||||
|
mc_prefab.cpp
|
||||||
|
|
||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
metacall.py \
|
metacall.py \
|
||||||
@ -35,5 +36,6 @@ HEADERS += \
|
|||||||
mc_client.hpp \
|
mc_client.hpp \
|
||||||
mc_buffer.hpp \
|
mc_buffer.hpp \
|
||||||
mc_binding.hpp \
|
mc_binding.hpp \
|
||||||
mc_binding-inl.hpp
|
mc_binding-inl.hpp \
|
||||||
|
mc_prefab.hpp
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user