Exemplo n.º 1
0
 public void TestB()
 {
     ObjectPacker packer = new ObjectPacker ();
     TestB_Class obj0 = TestB_Class.Create ();
     TestB_Class obj1 = packer.Unpack<TestB_Class> (packer.Pack (obj0));
     obj0.Check (obj1);
 }
Exemplo n.º 2
0
    private void receiveStatus(byte[] data)
    {
        ObjectPacker unpack = new ObjectPacker();

        Data.StatusInfo info = unpack.Unpack <Data.StatusInfo>(data);
        updateMember(info);
    }
Exemplo n.º 3
0
    // <summary>
    // 指定フォルダーを指定プラットフォームのAssetBundleを生成する </summary>
    public static void Build(string outPath, string resPath, BuildTarget target)
    {
        if (Directory.Exists (outPath) == false) {
                        Directory.CreateDirectory (outPath);
                }

                string[] files;
                Object[] assets;
                CreateTargetFileList (Application.dataPath, resPath, out files, out assets);

                {	// FileListのload test.
                        bool msgPackValidflag = false;
                        foreach (Object obj in assets) {
                                if (obj.name == strOutputFileList) {
                                        TextAsset msgBin = obj as TextAsset;
                                        ObjectPacker packerd = new ObjectPacker ();
                                        SerializeData.FileList flistd = packerd.Unpack<SerializeData.FileList> (msgBin.bytes);
                                        if (flistd.version == fileVersion) {
                                                msgPackValidflag = true;
                                                break;
                                        }
                                }
                        }
                        if (msgPackValidflag == false) {
                                Debug.Log ("ERROR:msgPack valid");
                                return;
                        }
                }
                Debug.Log (outPath + "/" + resPath + kExtensionAssetBundle);
                BuildAssetBundleOptions opt = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
                BuildPipeline.BuildAssetBundleExplicitAssetNames (assets, files, outPath + "/" + resPath + kExtensionAssetBundle, opt, target);
    }
Exemplo n.º 4
0
 public void TestA()
 {
     ObjectPacker packer = new ObjectPacker ();
     TestA_Class obj0 = new TestA_Class ();
     TestA_Class obj1 = packer.Unpack<TestA_Class> (packer.Pack (obj0));
     obj0.Check (obj1);
 }
Exemplo n.º 5
0
    private void receiveChat(byte[] data)
    {
        ObjectPacker unpack = new ObjectPacker();

        Data.ChatInfo info = unpack.Unpack <Data.ChatInfo>(data);
        windowChat.SetMessage(info, userId);
    }
Exemplo n.º 6
0
        // <summary>
        // 読み込み中に別スレッドから呼ばれるFileListのMsgpackの展開処理 </summary>
        private void UnpackFileList(object obj)
        {
            byte[]       bytes   = (byte[])obj;
            ObjectPacker packerd = new ObjectPacker();

            fileList = packerd.Unpack <SerializeData.FileList> (bytes);
        }
Exemplo n.º 7
0
        public void TestB()
        {
            ObjectPacker packer = new ObjectPacker();
            TestB_Class  obj0   = TestB_Class.Create();
            TestB_Class  obj1   = packer.Unpack <TestB_Class> (packer.Pack(obj0));

            obj0.Check(obj1);
        }
Exemplo n.º 8
0
        public void TestA()
        {
            ObjectPacker packer = new ObjectPacker();
            TestA_Class  obj0   = new TestA_Class();
            TestA_Class  obj1   = packer.Unpack <TestA_Class> (packer.Pack(obj0));

            obj0.Check(obj1);
        }
Exemplo n.º 9
0
    private void receiveMemberInfo(byte[] data)
    {
        ObjectPacker unpack = new ObjectPacker();

        Data.StatusInfo[] infos = unpack.Unpack <Data.StatusInfo[]>(data);

        foreach (Data.StatusInfo info in infos)
        {
            updateMember(info);
        }
    }
Exemplo n.º 10
0
        public void TestEnum()
        {
            ObjectPacker packer = new ObjectPacker();

            EnumTester et = new EnumTester();
            byte[] binary = packer.Pack(et);

            EnumTester et2 = packer.Unpack<EnumTester>(binary);

            Assert.AreEqual(et.e1, et2.e1);
            Assert.AreEqual(et.e2, et2.e2);
            Assert.AreEqual(et.e3, et2.e3);
        }
Exemplo n.º 11
0
    // <summary>
    // 対象フォルダー以下のオブジェクトからファイルリストを生成する </summary>
    static void CreateTargetFileList(string currentDirectory, string targetDirectory, out string[] lists, out Object[] assets)
    {
        string resourcesDirectory     = currentDirectory + "/" + strResource;
        string compareTargetDirectory = resourcesDirectory + "/" + targetDirectory;
        string binaryFileListName     = compareTargetDirectory + "/" + strOutputFileList + strBinaryFile;

        {                                //  mazuha BinaryFile wo Exist saseru
            byte[] dummy = new byte[16]; // dummy
            File.WriteAllBytes(binaryFileListName, dummy);
        }
        string[] resFileNames         = Directory.GetFiles(resourcesDirectory, "*.*", SearchOption.AllDirectories);
        string[] pickedListNames      = new string[resFileNames.Length];
        int      pickedListNamesCount = 0;

        // すべての生成された文字列の \\ を / に変換しておく
        compareTargetDirectory = compareTargetDirectory.Replace("\\", "/");
        resourcesDirectory     = resourcesDirectory.Replace("\\", "/");
        foreach (string name in resFileNames)
        {
            string temp = name.Replace("\\", "/");
            if ((IsExclusion(temp) == false) &&
                (temp.Contains(compareTargetDirectory) == true) &&
                (temp.Contains(strMetaFile) == false))
            {
                temp = temp.Replace(resourcesDirectory + "/", "");
                temp = temp.Substring(0, temp.LastIndexOf("."));
                pickedListNames [pickedListNamesCount] = temp;
                ++pickedListNamesCount;
            }
        }

        assets = new Object[pickedListNamesCount];
        lists  = new string[pickedListNamesCount];
        SerializeData.FileList fileList = new SerializeData.FileList();
        for (int i = 0; i < pickedListNamesCount; ++i)
        {
            lists [i]  = pickedListNames [i];
            assets [i] = Resources.Load(lists [i]);
            fileList.obj.Add(new Pair <string, string> (lists [i], assets [i].GetType().FullName));
        }
        {                               // File.Lst Binary Overwrite
            fileList.id      = fileID;
            fileList.version = fileVersion;
            ObjectPacker packer = new ObjectPacker();
            byte[]       bytes  = packer.Pack(fileList);
            File.WriteAllBytes(binaryFileListName, bytes);
            AssetDatabase.Refresh();                                            // refresh
        }
    }
Exemplo n.º 12
0
        private void save(int id, string path)
        {
            ObjectPacker packer = new ObjectPacker();

            byte[] pack = packer.Pack(new List <int> {
                id
            });

            using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
                using (BinaryWriter bw = new BinaryWriter(fs))
                {
                    bw.Write(pack.Length);
                    bw.Write(pack);
                }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Invoked when a new frame is recieved from the client
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="frame"></param>
        void OnDataReceived(WebSocket socket, string frame)
        {
            // Decode the frame
            IDictionary <string, object> data = ObjectPacker.UnpackRaw(frame);

            if (data == null)
            {
                return;
            }
            // Is it a message ?
            if (ContainsKeys(data, MessageTopic, MessagePayload))
            {
                ProcessMessage(data);
            }
            else if (ContainsKeys(data, FunctionSequence, FunctionName, FunctionParameters))
            {
                ProcessRpcCall(data);
            }
        }
Exemplo n.º 14
0
        private int load(string path)
        {
            byte[] ivBytes = null;

            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        int length = br.ReadInt32();
                        ivBytes = br.ReadBytes(length);
                    }

                ObjectPacker packer = new ObjectPacker();
                return(packer.Unpack <List <int> >(ivBytes)[0]);
            }
            catch (FileNotFoundException)
            {
                save(0, path);
            }
            return(0);
        }
Exemplo n.º 15
0
    // <summary>
    // 指定フォルダーを指定プラットフォームのAssetBundleを生成する </summary>
    public static void Build(string outPath, string resPath, BuildTarget target)
    {
        if (Directory.Exists(outPath) == false)
        {
            Directory.CreateDirectory(outPath);
        }

        string[] files;
        Object[] assets;
        CreateTargetFileList(Application.dataPath, resPath, out files, out assets);

        {                               // FileListのload test.
            bool msgPackValidflag = false;
            foreach (Object obj in assets)
            {
                if (obj.name == strOutputFileList)
                {
                    TextAsset              msgBin  = obj as TextAsset;
                    ObjectPacker           packerd = new ObjectPacker();
                    SerializeData.FileList flistd  = packerd.Unpack <SerializeData.FileList> (msgBin.bytes);
                    if (flistd.version == fileVersion)
                    {
                        msgPackValidflag = true;
                        break;
                    }
                }
            }
            if (msgPackValidflag == false)
            {
                Debug.Log("ERROR:msgPack valid");
                return;
            }
        }
        Debug.Log(outPath + "/" + resPath + kExtensionAssetBundle);
        BuildAssetBundleOptions opt = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;

        BuildPipeline.BuildAssetBundleExplicitAssetNames(assets, files, outPath + "/" + resPath + kExtensionAssetBundle, opt, target);
    }
Exemplo n.º 16
0
        public byte[] GetDataToSend(int bufferSize, bool legacySupport)
        {
            if (_data != null && _data.Length > 0)
            {
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }
            if (!IsFileData)
            {
                return(null);
            }

            if (!FileDataHeaderSent && !legacySupport)
            {
                _data = ObjectPacker.Pack(FileData);
                PacketHeader.AddHeader(ref _data);
                FileDataHeaderSent = true;
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }

            var part = FileData.GetNextPart(bufferSize);

            if (part != null)
            {
                if (!legacySupport)
                {
                    _data = ObjectPacker.Pack(part);
                    PacketHeader.AddHeader(ref _data);
                }
                else
                {
                    _data = part.Data;
                }
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }
            return(null);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get the configuration for the instance
        ///
        /// This version of the method loads directly from a named file (the file must
        /// still be in the 'configs' folder.
        /// </summary>
        /// <param name="forInstance"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public IDictionary <string, object> GetConfigurationFromFile(Guid forInstance, string filename)
        {
            IUserObject instance;
            IConfigurationDescription description;

            if (!GetObjectInformation(forInstance, out instance, out description))
            {
                return(null);
            }
            // Load the configuration values from the file (if it exists)
            IDictionary <string, object> values = null;

            if (m_configDirectory.FileExists(filename))
            {
                Stream json = m_configDirectory.CreateFile(filename, FileAccessMode.Read, CreationOptions.OpenIfExists);
                values = ObjectPacker.UnpackRaw(json);
                json.Dispose();
            }
            else
            {
                values = new Dictionary <string, object>();
            }
            return(description.Verify(values));
        }
Exemplo n.º 18
0
    // <summary>
    // 対象フォルダー以下のオブジェクトからファイルリストを生成する </summary>
    static void CreateTargetFileList(string currentDirectory, string targetDirectory, out string[] lists, out Object[] assets)
    {
        string resourcesDirectory = currentDirectory + "/" + strResource;
                string compareTargetDirectory = resourcesDirectory + "/" + targetDirectory;
                string binaryFileListName = compareTargetDirectory + "/" + strOutputFileList + strBinaryFile;

                {	//  mazuha BinaryFile wo Exist saseru
                        byte[] dummy = new byte[16];	// dummy
                        File.WriteAllBytes (binaryFileListName, dummy);
                }
                string[] resFileNames = Directory.GetFiles (resourcesDirectory, "*.*", SearchOption.AllDirectories);
                string[] pickedListNames = new string[resFileNames.Length];
                int pickedListNamesCount = 0;
                // すべての生成された文字列の \\ を / に変換しておく
                compareTargetDirectory = compareTargetDirectory.Replace ("\\", "/");
                resourcesDirectory = resourcesDirectory.Replace ("\\", "/");
                foreach (string name in resFileNames) {
                        string temp = name.Replace ("\\", "/");
                        if ((IsExclusion (temp) == false)
                         && (temp.Contains (compareTargetDirectory) == true)
                         && (temp.Contains (strMetaFile) == false)) {
                                temp = temp.Replace (resourcesDirectory + "/", "");
                                temp = temp.Substring (0, temp.LastIndexOf ("."));
                                pickedListNames [pickedListNamesCount] = temp;
                                ++pickedListNamesCount;
                        }
                }

                assets = new Object[pickedListNamesCount];
                lists = new string[pickedListNamesCount];
                SerializeData.FileList fileList = new SerializeData.FileList ();
                for (int i = 0; i < pickedListNamesCount; ++i) {
                        lists [i] = pickedListNames [i];
                        assets [i] = Resources.Load (lists [i]);
                        fileList.obj.Add (new Pair<string,string> (lists [i], assets [i].GetType ().FullName));
                }
                {	// File.Lst Binary Overwrite
                        fileList.id = fileID;
                        fileList.version = fileVersion;
                        ObjectPacker packer = new ObjectPacker ();
                        byte[] bytes = packer.Pack (fileList);
                        File.WriteAllBytes (binaryFileListName, bytes);
                        AssetDatabase.Refresh ();	// refresh
                }
    }
Exemplo n.º 19
0
 public MsgPackSerializer()
 {
     _packer = new ObjectPacker();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Processes incoming data and attempts to recreate the objects that were sent.
        /// Then raises the ReceiveProgress and/or DataArrival events.
        /// Runs in it's own thread to allow receiving to continue unhindered.
        /// </summary>
        private void ProcessIncoming()
        {
            ReceivedPacket packet = null;

            while (true)
            {
                // First lets get the incoming packet we are dealing with
                packet = null;
                lock (ReceivedPackets.SyncRoot)
                {
                    if (ReceivedPackets.Count < 1)
                    {
                        IsProcessingIncomingData = false;
                        return;
                    }
                    packet = ReceivedPackets.PopFront();
                }

                if (Parent.LegacySupport)
                {
                    // Legacy support is enabled, so just alert that it arrived
                    lock (((ICollection)ReceivedBuffer).SyncRoot)
                        ReceivedBuffer.Enqueue(packet.Data);
                    Parent.OnDataArrival(Parent, new DataArrivalEventArgs(packet.Data.LongLength, packet.RemoteEndPoint));
                    continue;
                }

                // Let's get the header
                byte[] data             = packet.Data;
                bool   throwLegacyError = false;
                while (!Header.Completed && (packet.Data != null & packet.Data.Length > 0))
                {
                    if (!Header.ProcessHeader(ref data, ref ProcessingByteBuffer))
                    {
                        throwLegacyError = true;
                        break;
                    }
                    if (data == null || data.Length < 1)
                    {
                        break;
                    }
                }

                // Check for header error
                if (throwLegacyError || (!Header.Completed && ProcessingByteBuffer.Count > 10))
                {
                    Parent.OnErrorReceived(Parent, ErrorReceivedEventArgs.Create(new WinsockException("Unable to determine the size of the incoming packet. You may need to turn on Legacy Support.")));
                    Close();
                    break;
                }

                if (data != null)
                {
                    int receivedSize = data.Length;
                    if (Header.Completed && ProcessingByteBuffer.Count + data.Length >= Header.Size)
                    {
                        // We have the full object that was sent
                        data = ProcessingByteBuffer.Combine(data);
                        ProcessingByteBuffer.Clear();

                        byte[] objectData = null;
                        if (data.Length > Header.Size)
                        {
                            // There is extra data here - get only what we need
                            // then push the rest back on the queue
                            objectData  = ArrayMethods.Shrink(ref data, Header.Size);
                            packet.Data = data;
                            lock (ReceivedPackets.SyncRoot)
                                ReceivedPackets.PushFront(packet);
                        }
                        else
                        {
                            objectData = data;
                        }

                        // Try converting the bytes back to the object.
                        var receivedObject = ObjectPacker.Unpack(objectData);
                        var receivedType   = receivedObject.GetType();
                        if (receivedType == typeof(FileData) || receivedType == typeof(FileDataPart))
                        {
                            // Looks like we are dealing with an incoming file
                            // Handle the data and get a reference to the incoming file
                            FileData file = null;
                            try
                            {
                                file = (receivedType == typeof(FileData)) ?
                                       HandleIncomingFile((FileData)receivedObject) :
                                       HandleIncomingFile((FileDataPart)receivedObject);
                            }
                            catch (Exception ex)
                            {
                                Parent.OnErrorReceived(Parent, ex.AsEventArgs());
                                Close();
                                break;
                            }

                            // This part of the file is done, so we can
                            // reset the header for the next object
                            Header.Reset();
                            if (file != null)
                            {
                                // We've got the file, raise the events
                                // and remove our in progress reference to the file
                                Parent.OnReceiveProgress(Parent, new ReceiveProgressEventArgs(file.LastReceivedSize, file.ReceivedBytes, file.FileSize, packet.RemoteEndPoint));
                                if (file.ReceiveCompleted)
                                {
                                    IncomingFiles.Remove(file.Guid);
                                    lock (((ICollection)ReceivedBuffer).SyncRoot)
                                        ReceivedBuffer.Enqueue(file);
                                    Parent.OnDataArrival(Parent, new DataArrivalEventArgs(file.FileSize, packet.RemoteEndPoint));
                                }
                            }
                        }
                        else
                        {
                            // Incoming object was not a file (could be a byte[])
                            // Store it in the queue and raise the events
                            lock (((ICollection)ReceivedBuffer).SyncRoot)
                                ReceivedBuffer.Enqueue(receivedObject);

                            Parent.OnReceiveProgress(Parent, new ReceiveProgressEventArgs(receivedSize, objectData.Length, Header.Size, packet.RemoteEndPoint));
                            Header.Reset();
                            Parent.OnDataArrival(Parent, new DataArrivalEventArgs(objectData.Length, packet.RemoteEndPoint));
                        }
                    }
                    else
                    {
                        // Either the header wasn't completed, or we haven't got
                        // all of the object yet, either way we need more data
                        // store what we've got into a temporary buffer
                        ProcessingByteBuffer.Add(data);
                        Parent.OnReceiveProgress(Parent, new ReceiveProgressEventArgs(receivedSize, ProcessingByteBuffer.Count, Header.Size, packet.RemoteEndPoint));
                    }
                }
            }

            // Exit the processing thread, and allow another one to be created
            lock (ReceivedPackets.SyncRoot)
                IsProcessingIncomingData = false;
        }
Exemplo n.º 21
0
 public void Setup()
 {
     packer = new ObjectPacker();
 }