Exemplo n.º 1
0
	bool GameObjectComponent::Serialize(DataStream* pStream)
	{
		const Version& v = GetVersion();
		pStream->WriteInt32(v.AsUInt32());

		return OnSerialize(pStream);
	}
Exemplo n.º 2
0
void Node::Serialize(IOPacket& packet) {
    packet.Stream(mId, "uuid");
    packet.Stream(mName, "name", mName);
    packet.Stream(mPosition, "position");
    packet.Stream(mScale, "scale", Ogre::Vector3(1,1,1));
    packet.Stream(mRotation, "rotation");
    packet.Stream(mIsEnabled, "enabled");
    OnSerialize(packet);

    // Components
    uint32_t count = packet.BeginList(mComponents.size(), "components");

    if(packet.GetDirection() == IOPacket::SERIALIZE) {
        // serialize
        for(auto iter = mComponents.begin(); iter != mComponents.end(); ++iter) {
            packet.BeginObject();
            iter->second->Serialize(packet);
            packet.EndObject();
        }
    } else {
        for(uint32_t i = 0; i < count; ++i) {
            packet.BeginObject();
            std::string type;
            packet.Stream(type, "type", std::string(""));
            Component* c = Serializer::CreateComponent(type);
            c->Serialize(packet);
            AddComponent(c);
            packet.EndObject();
        }
    }
    packet.EndList();

    // Children
    count = packet.BeginList(mChildren.size(), "children");

    if(packet.GetDirection() == IOPacket::SERIALIZE) {
        for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
            packet.BeginObject();
            iter->second->Serialize(packet);
            packet.EndObject();
        }
    } else {
        for(uint32_t i = 0; i < count; ++i) {
            packet.BeginObject();
            Node* n = new Node;
            n->Serialize(packet);
            AddChildNode(n);
            packet.EndObject();
        }
    }
    packet.EndList();
}
Exemplo n.º 3
0
void IComplexDatum::Serialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	Serialize
//
//	Serialize the datum

	{
	DWORD dwFlags = OnGetSerializeFlags();

	switch (iFormat)
		{
		case CDatum::formatAEONScript:
		case CDatum::formatAEONLocal:
			{
			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				{
				Stream.Write("[", 1);
				Stream.Write(GetTypename());
				Stream.Write(":", 1);
				}

			//	If this is object is serializable as a struct, then we do that.

			if (dwFlags & FLAG_SERIALIZE_AS_STRUCT)
				{
				CComplexStruct *pStruct = new CComplexStruct;

				OnSerialize(iFormat, pStruct);

				CDatum dDatum(pStruct);
				dDatum.Serialize(iFormat, Stream);
				}

			//	Otherwise, serialize as base64 encoding

			else
				{
				CBase64Encoder Encoder(&Stream);
				OnSerialize(iFormat, Encoder);
				Encoder.Close();
				}

			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				Stream.Write("]", 1);
			break;
			}

		case CDatum::formatJSON:
			{
			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				{
				Stream.Write("[\"AEON2011:", 11);
				Stream.Write(GetTypename());
				Stream.Write(":v1\", \"", 7);
				}

			//	LATER: Handle serialization/deserialization of struct-based objects

			CBase64Encoder Encoder(&Stream);
			OnSerialize(iFormat, Encoder);
			Encoder.Close();

			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				Stream.Write("\"]", 2);
			break;
			}

		default:
			ASSERT(false);
		}
	}