Example #1
0
    public void ConvertMessageEvent(string path)
    {
        List <string> lineList = this.getLineList(path);

        FlatBuffers.FlatBufferBuilder fbb = new FlatBuffers.FlatBufferBuilder(1);
        FlatBuffers.Offset <MessageEventTable.Data>[] data = new FlatBuffers.Offset <MessageEventTable.Data> [lineList.Count];
        int count = 0;

        foreach (string line in lineList)
        {
            string[] values    = line.Split(',');
            int      id        = int.Parse(values[0]);
            int      checkId   = int.Parse(values[1]);
            int      messageId = int.Parse(values[2]);
            int      selectId  = int.Parse(values[3]);
            int      flag      = int.Parse(values[4]);
            int      addTime   = int.Parse(values[5]);
            data[count] = MessageEventTable.Data.CreateData(fbb, id, checkId, messageId, selectId, flag, addTime);
            ++count;
        }
        FlatBuffers.VectorOffset infoVec = MessageEventTable.DataList.CreateDatasVector(fbb, data);
        FlatBuffers.Offset <MessageEventTable.DataList> reslut = MessageEventTable.DataList.CreateDataList(fbb, infoVec);
        MessageEventTable.DataList.FinishDataListBuffer(fbb, reslut);
        using (System.IO.FileStream fs = new System.IO.FileStream("message-event-table.bin", System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                bw.Write(fbb.SizedByteArray());
            }
        }
    }
Example #2
0
    public void ConvertTekiInfo(string path)
    {
        List <string> lineList = this.getLineList(path);

        FlatBuffers.FlatBufferBuilder             fbb  = new FlatBuffers.FlatBufferBuilder(1);
        FlatBuffers.Offset <TekiInfoTable.Data>[] data = new FlatBuffers.Offset <TekiInfoTable.Data> [lineList.Count];
        int count = 0;

        foreach (string line in lineList)
        {
            string[]            values         = line.Split(',');
            int                 id             = int.Parse(values[0]);
            TekiDefine.MoveType moveType       = (TekiDefine.MoveType)Enum.Parse(typeof(TekiDefine.MoveType), values[1]);
            int                 messageEventId = int.Parse(values[2]);
            data[count] = TekiInfoTable.Data.CreateData(fbb, id, moveType, messageEventId);
            ++count;
        }
        FlatBuffers.VectorOffset infoVec = TekiInfoTable.DataList.CreateDatasVector(fbb, data);
        FlatBuffers.Offset <TekiInfoTable.DataList> reslut = TekiInfoTable.DataList.CreateDataList(fbb, infoVec);
        TekiInfoTable.DataList.FinishDataListBuffer(fbb, reslut);
        using (System.IO.FileStream fs = new System.IO.FileStream("teki-info-table.bin", System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                bw.Write(fbb.SizedByteArray());
            }
        }
    }
Example #3
0
    public void ConvertMessageAnswer(string path)
    {
        List <string> lineList = this.getLineList(path);

        FlatBuffers.FlatBufferBuilder fbb = new FlatBuffers.FlatBufferBuilder(1);
        FlatBuffers.Offset <MessageAnswerTable.Data>[] data = new FlatBuffers.Offset <MessageAnswerTable.Data> [lineList.Count];
        int count = 0;

        foreach (string line in lineList)
        {
            string[] values     = line.Split(',');
            int      id         = int.Parse(values[0]);
            int      selectId   = int.Parse(values[1]);
            int[]    answerList = new int[values.Length - 1];
            for (int i = 2; i < values.Length; ++i)
            {
                string message = values[i].Replace("\\n", "\n");;
                answerList[i - 2] = int.Parse(values[i]);
            }
            data[count] = MessageAnswerTable.Data.CreateData(fbb, id, selectId, MessageAnswerTable.Data.CreateAnswerVector(fbb, answerList));
            ++count;
        }
        FlatBuffers.VectorOffset infoVec = MessageAnswerTable.DataList.CreateDatasVector(fbb, data);
        FlatBuffers.Offset <MessageAnswerTable.DataList> reslut = MessageAnswerTable.DataList.CreateDataList(fbb, infoVec);
        MessageAnswerTable.DataList.FinishDataListBuffer(fbb, reslut);
        using (System.IO.FileStream fs = new System.IO.FileStream("message-answer-table.bin", System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                bw.Write(fbb.SizedByteArray());
            }
        }
    }
Example #4
0
        /// <summary>
        /// Create VectorOffset from List
        /// </summary>
        /// <typeparam name="T">IFBSerializable</typeparam>
        /// <typeparam name="S">FlatbufferType</typeparam>
        /// <param name="builder"></param>
        /// <param name="list"></param>
        /// <param name="fbCreateList"></param>
        /// <returns></returns>
        public static FlatBuffers.VectorOffset?CreateList <T, S>(FlatBuffers.FlatBufferBuilder builder
                                                                 , List <T> list, Func <FlatBufferBuilder, Offset <S>[], VectorOffset> fbCreateList)
        where S : struct, FlatBuffers.IFlatbufferObject where T : IFBSerializable
        {
            if (list == null)
            {
                return(null);
            }

            if (FlatbufferSerializer.obj2FSMapping.TryGetValue(list, out int bufPos))
            {
                // the list was already serialized so we need to use this VectorOffset in order to keep the reference
                var result = new FlatBuffers.VectorOffset(bufPos);
                return(result);
            }
            else
            {
                if (typeof(IFBSerializable).IsAssignableFrom(typeof(T)))
                {
                    var tempArray = new FlatBuffers.Offset <S> [list.Count];
                    for (int i = 0; i < list.Count; i++)
                    {
                        var listElemOffset = FlatbufferSerializer.GetOrCreateSerialize(builder, (IFBSerializable)list[i]);
                        if (listElemOffset != null)
                        {
                            tempArray[i] = new FlatBuffers.Offset <S>((int)listElemOffset);
                        }
                    }
                    var result = fbCreateList(builder, tempArray);
                    FlatbufferSerializer.obj2FSMapping[list] = result.Value;
                    return(result);
                }
                return(null);
            }
        }
Example #5
0
    public void ConvertEvent(string dst, string path)
    {
        List <string> lineList = this.getLineList(path);

        FlatBuffers.FlatBufferBuilder          fbb  = new FlatBuffers.FlatBufferBuilder(1);
        FlatBuffers.Offset <EventTable.Data>[] data = new FlatBuffers.Offset <EventTable.Data> [lineList.Count];
        int count = 0;

        foreach (string line in lineList)
        {
            string[] values  = line.Split(',');
            int      id      = int.Parse(values[0]);
            int      bitNum  = values.Length - 1;
            int      byteNum = ((bitNum - 1) / 8) + 1;
            byte[]   flag    = new byte[byteNum];
            int      byteNo  = -1;
            for (int i = 0; i < byteNum; ++i)
            {
                flag[i] = 0;
            }
            for (int i = 0; i < bitNum; ++i)
            {
                if ((i % 8) == 0)
                {
                    ++byteNo;
                }
                flag[byteNo] |= (byte)(int.Parse(values[1 + i]) << (i % 8));
            }
            data[count] = EventTable.Data.CreateData(fbb, id, EventTable.Data.CreateFlagVector(fbb, flag));
            ++count;
        }
        FlatBuffers.VectorOffset infoVec = EventTable.DataList.CreateDatasVector(fbb, data);
        FlatBuffers.Offset <EventTable.DataList> reslut = EventTable.DataList.CreateDataList(fbb, infoVec);
        EventTable.DataList.FinishDataListBuffer(fbb, reslut);
        using (System.IO.FileStream fs = new System.IO.FileStream(dst, System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                bw.Write(fbb.SizedByteArray());
            }
        }
    }
Example #6
0
    public void ConvertMessage(string path)
    {
        List <string> lineList = this.getLineList(path);

        FlatBuffers.FlatBufferBuilder            fbb  = new FlatBuffers.FlatBufferBuilder(1);
        FlatBuffers.Offset <MessageTable.Data>[] data = new FlatBuffers.Offset <MessageTable.Data> [lineList.Count];
        int count = 0;

        foreach (string line in lineList)
        {
            string[]      works  = line.Split(',');
            List <string> values = new List <string>();
            int           id     = int.Parse(works[0]);
            for (int i = 1; i < works.Length; ++i)
            {
                if (string.IsNullOrEmpty(works[i]))
                {
                    break;
                }
                values.Add(works[i]);
            }
            FlatBuffers.StringOffset[] messageList = new FlatBuffers.StringOffset[values.Count];
            for (int i = 0; i < values.Count; ++i)
            {
                string message = values[i].Replace("\\n", "\n");;
                messageList[i] = fbb.CreateString(message);
            }
            data[count] = MessageTable.Data.CreateData(fbb, id, MessageTable.Data.CreateMessageVector(fbb, messageList));
            ++count;
        }
        FlatBuffers.VectorOffset infoVec = MessageTable.DataList.CreateDatasVector(fbb, data);
        FlatBuffers.Offset <MessageTable.DataList> reslut = MessageTable.DataList.CreateDataList(fbb, infoVec);
        MessageTable.DataList.FinishDataListBuffer(fbb, reslut);
        using (System.IO.FileStream fs = new System.IO.FileStream("message-table.bin", System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                bw.Write(fbb.SizedByteArray());
            }
        }
    }
Example #7
0
        public static FlatBuffers.VectorOffset?CreateList <T>(FlatBuffers.FlatBufferBuilder builder
                                                              , List <T> list, Func <FlatBufferBuilder, T[], VectorOffset> fbCreateList)
        {
            if (list == null || typeof(T).IsPrimitive)
            {
                return(null);
            }

            if (FlatbufferSerializer.obj2FSMapping.TryGetValue(list, out int bufPos))
            {
                // the list was already serialized so we need to use this VectorOffset in order to keep the reference
                var result = new FlatBuffers.VectorOffset(bufPos);
                return(result);
            }
            else
            {
                var tempArray = list.ToArray();
                // call the createFunction with the array
                var result = fbCreateList(builder, tempArray);
                FlatbufferSerializer.obj2FSMapping[list] = result.Value;
                return(result);
            }
        }