Exemplo n.º 1
0
 public Row(Schema a_Schema)
 {
     m_Schema = a_Schema;
 }
Exemplo n.º 2
0
        void LoadSchema()
        {
            if (m_Schema == null)
            {
                m_Schema = new Schema();
                m_Schema.ClassName = m_FileName;

                int identity = m_Reader.ReadInt32();
                if (m_Identity != identity)
                {
                    return;
                }
                //read record number
                m_recordsNumber = m_Reader.ReadInt32();

                //read column number
                int columnNumber = m_Reader.ReadInt32();

                //create field define and fill field name.
                for (int i = 0; i < columnNumber; ++i)
                {
                    FieldDefine define = new FieldDefine();
                    define.FieldName = m_Reader.ReadString();
                    define.Index = i;
                    m_Schema.AddDefine(define);
                }

                //read field type.
                for (int i = 0; i < columnNumber; ++i)
                {
                    FieldDefine define = m_Schema.GetDefine(i);
                    define.FieldType = (FIELD_TYPE)m_Reader.ReadInt32();
                }
            }
        }
Exemplo n.º 3
0
        bool WriteSchema(Schema a_schema, int a_recordsNumber)
        {
            if (!InitWriter())
            {
                return false;
            }

            //Write int ----- Identity
            m_Writer.Write(m_Identity);

            //Write int ----- RecordsNumber
            m_Writer.Write(a_recordsNumber);

            //Write int ----- columnsNumber
            m_Writer.Write(a_schema.Count);

            //Write string * columnsNumber ----- FieldName
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write(a_schema.GetDefine(i).FieldName);
            }

            //Write int * columnsNumber ------ FieldType
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write((int)a_schema.GetDefine(i).FieldType);
            }

            return true;
        }
Exemplo n.º 4
0
        public bool Write(Schema schema, Row[] rows)
        {
            bool res = false;
            res = WriteSchema(schema, rows.Length);
            if (!res)
            {
                //Debug.Log("Write Error");
                return false;
            }
            res = WriteData(rows, schema);

            if (res)
            {
                m_stream.Close();
                m_stream = null;
                m_Writer.Close();
                m_Writer = null;
            }
            return res;
        }
Exemplo n.º 5
0
        bool WriteData(Row[] a_rows, Schema a_schema)
        {
            if (!InitWriter())
            {
                return false;
            }

            foreach (Row row in a_rows)
            {
                for (int i = 0; i < a_schema.Count; ++i)
                {
                    FieldDefine define = a_schema.GetDefine(i);
                    switch (define.FieldType)
                    {
                        case FIELD_TYPE.T_INT:
                            m_Writer.Write((int)row.GetField(i).m_Value);
                            break;
                        case FIELD_TYPE.T_FLOAT:
                            m_Writer.Write((float)row.GetField(i).m_Value);
                            break;
                        case FIELD_TYPE.T_STRING:
                            m_Writer.Write(row.GetField(i).m_Value.ToString());
                            break;
                        case FIELD_TYPE.T_INVALID:
                            //Debug.LogError("Wrong Field Type.");
                            break;
                        default:
                            break;
                    }
                }
            }
            return true;
        }