瀏覽代碼

added signature prefix to hxsl serialized data

ncannasse 6 年之前
父節點
當前提交
2c76b3b038
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      hxsl/Serializer.hx

+ 7 - 0
hxsl/Serializer.hx

@@ -415,9 +415,13 @@ class Serializer {
 			expr : readExpr(),
 		};
 	}
+	
+	static var SIGN = 0x8B741D; // will be encoded to HXSL
 
 	public function unserialize( data : String ) : ShaderData {
 		input = new haxe.io.BytesInput(haxe.crypto.Base64.decode(data,false));
+		if( input.readByte() != (SIGN & 0xFF) || input.readByte() != (SIGN >> 8) & 0xFF || input.readByte() != (SIGN >> 16) & 0xFF )
+			throw "Invalid HXSL data";
 		varMap = new Map();
 		types = [];
 		return {
@@ -432,6 +436,9 @@ class Serializer {
 		idMap = new Map();
 		typeIdMap = new Map();
 		out = new haxe.io.BytesBuffer();
+		out.addByte(SIGN & 0xFF);
+		out.addByte((SIGN >> 8) & 0xFF);
+		out.addByte((SIGN >> 16) & 0xFF);
 		writeString(s.name);
 		writeArr(s.vars, writeVar);
 		writeArr(s.funs, writeFun);