浏览代码

修改错误理解的部分,准备逆向 tlv 部分

akemimadoka 7 年之前
父节点
当前提交
97f899a984
共有 6 个文件被更改,包括 51 次插入24 次删除
  1. 2 2
      YumeBot/Jce.cpp
  2. 15 11
      YumeBot/Jce.h
  3. 8 8
      YumeBot/JceStructDef.h
  4. 19 0
      YumeBot/Tlv.h
  5. 2 1
      YumeBot/YumeBot.vcxproj
  6. 5 2
      YumeBot/YumeBot.vcxproj.filters

+ 2 - 2
YumeBot/Jce.cpp

@@ -34,7 +34,7 @@ JceOutputStream::~JceOutputStream()
 {
 }
 
-#define TLV_CODE(name, code) \
+#define JCE_STRUCT(name, code) \
 	name::~name()\
 	{\
 	}\
@@ -49,4 +49,4 @@ JceOutputStream::~JceOutputStream()
 		return JceCode::name;\
 	}
 
-#include "TlvCodeDef.h"
+#include "JceStructDef.h"

+ 15 - 11
YumeBot/Jce.h

@@ -851,8 +851,9 @@ namespace YumeBot::Jce
 
 	enum class JceCode
 	{
-#define TLV_CODE(name, code) name = code,
-#include "TlvCodeDef.h"
+#define JCE_STRUCT(name, code) name = code,
+#include "JceStructDef.h"
+
 	};
 
 	struct NoOp
@@ -929,7 +930,7 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 			return tag;\
 		}
 
-#define TLV_CODE(name, code) \
+#define JCE_STRUCT(name, code) \
 	class name\
 		: public NatsuLib::natRefObjImpl<name, JceStruct>\
 	{\
@@ -939,10 +940,11 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 		std::string_view GetJceStructName() const noexcept override;\
 		JceCode GetJceStructType() const noexcept override;
 
-#define END_TLV_CODE(name) \
+#define END_JCE_STRUCT(name) \
 	};
 
-#include "TlvCodeDef.h"
+#include "JceStructDef.h"
+
 
 #define NO_OP Detail::None
 
@@ -959,7 +961,7 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 		}\
 	}
 
-#define TLV_CODE(name, code) \
+#define JCE_STRUCT(name, code) \
 	template <>\
 	struct JceDeserializer<name>\
 	{\
@@ -967,27 +969,29 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 		{\
 			auto ret = NatsuLib::make_ref<name>();
 
-#define END_TLV_CODE(name) \
+#define END_JCE_STRUCT(name) \
 			return ret;\
 		}\
 	};
 
-#include "TlvCodeDef.h"
+#include "JceStructDef.h"
+
 
 #define FIELD(name, tag, type, ...) stream.Write(tag, value->Get##name());
 
-#define TLV_CODE(name, code) \
+#define JCE_STRUCT(name, code) \
 	template <>\
 	struct JceSerializer<name>\
 	{\
 		static void Serialize(JceOutputStream& stream, NatsuLib::natRefPointer<name> const& value)\
 		{
 
-#define END_TLV_CODE(name) \
+#define END_JCE_STRUCT(name) \
 		}\
 	};
 
-#include "TlvCodeDef.h"
+#include "JceStructDef.h"
+
 
 //static_assert(Utility::ConcatTrait<Utility::RemoveCvRef, Utility::BindTrait<std::is_same, Detail::NoneType>::Result>::Result<Detail::NoneType&&>::value);
 //static_assert(Utility::ConcatTrait<Utility::BindTrait<std::is_same, Detail::NoneType>::Result, std::negation>::Result<bool>::value);

+ 8 - 8
YumeBot/TlvCodeDef.h → YumeBot/JceStructDef.h

@@ -1,9 +1,9 @@
-#ifndef TLV_CODE
-#define TLV_CODE(name, code)
+#ifndef JCE_STRUCT
+#define JCE_STRUCT(name, code)
 #endif
 
-#ifndef END_TLV_CODE
-#define END_TLV_CODE(name)
+#ifndef END_JCE_STRUCT
+#define END_JCE_STRUCT(name)
 #endif
 
 #ifndef NO_OP
@@ -74,12 +74,12 @@
 #define SIMPLE_LIST(name, tag, ...) FIELD(name, tag, SimpleList, __VA_ARGS__)
 #endif
 
-TLV_CODE(TlvTest, 0)
+JCE_STRUCT(JceTest, 0)
 	INT(TestInt, 0)
 	FLOAT(TestFloat, 1, IS_OPTIONAL(1.0f))
 	MAP(TestMap, 2, TEMPLATE_ARGUMENT(std::int32_t, float))
 	LIST(TestList, 3, TEMPLATE_ARGUMENT(double), IS_OPTIONAL((FieldType{ 1.0, 2.0, 3.0 })))
-END_TLV_CODE(TlvTest)
+END_JCE_STRUCT(JceTest)
 
 #undef SIMPLE_LIST
 #undef ZERO_TAG
@@ -103,5 +103,5 @@ END_TLV_CODE(TlvTest)
 #undef NO_OP
 #undef ATTRIBUTE_SET
 
-#undef END_TLV_CODE
-#undef TLV_CODE
+#undef END_JCE_STRUCT
+#undef JCE_STRUCT

+ 19 - 0
YumeBot/Tlv.h

@@ -0,0 +1,19 @@
+#pragma once
+#include <natBinary.h>
+
+namespace YumeBot::Tlv
+{
+	class TlvBuilder
+	{
+	public:
+		explicit TlvBuilder(NatsuLib::natRefPointer<NatsuLib::natBinaryWriter> writer)
+			: m_Writer{ std::move(writer) }
+		{
+		}
+
+
+
+	private:
+		NatsuLib::natRefPointer<NatsuLib::natBinaryWriter> m_Writer;
+	};
+}

+ 2 - 1
YumeBot/YumeBot.vcxproj

@@ -21,8 +21,9 @@
   <ItemGroup>
     <ClInclude Include="Cryptography.h" />
     <ClInclude Include="Jce.h" />
+    <ClInclude Include="Tlv.h" />
     <ClInclude Include="YumeBot.h" />
-    <ClInclude Include="TlvCodeDef.h" />
+    <ClInclude Include="JceStructDef.h" />
     <ClInclude Include="Utility.h" />
   </ItemGroup>
   <ItemGroup>

+ 5 - 2
YumeBot/YumeBot.vcxproj.filters

@@ -24,10 +24,13 @@
     <ClInclude Include="Jce.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="TlvCodeDef.h">
+    <ClInclude Include="YumeBot.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="YumeBot.h">
+    <ClInclude Include="Tlv.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="JceStructDef.h">
       <Filter>头文件</Filter>
     </ClInclude>
   </ItemGroup>