예제 #1
0
        private unsafe void ReadFields()
        {
            fields = new NDBField[header.fieldCount];
            fieldNameToIndexDic.Clear();

            fixed(byte *bytePtr = &datas[header.fieldOffset])
            {
                int fieldOffset = 0;
                int byteOffset  = 0;

                for (int i = 0; i < header.fieldCount; ++i)
                {
                    NDBField field = new NDBField();
                    fields[i] = field;

                    NDBFieldType fieldType = (NDBFieldType)(*(bytePtr + byteOffset));
                    byteOffset += sizeof(byte);

                    int fieldNameLen = *((int *)(bytePtr + byteOffset));
                    byteOffset += sizeof(int);

                    string fieldName = Encoding.UTF8.GetString(datas, header.fieldOffset + byteOffset, fieldNameLen);
                    byteOffset += fieldNameLen;

                    field.Type   = fieldType;
                    field.Name   = fieldName;
                    field.Offset = fieldOffset;

                    fieldOffset += NDBFieldUtil.GetFieldOffset(fieldType);
                }
            }
        }
예제 #2
0
        private static NDBFieldType GetNDBFieldType(Field field)
        {
            FieldType fieldType = field.FieldType;

            if (fieldType == FieldType.List)
            {
                ListField    listField    = (ListField)field;
                FieldType    valueType    = listField.ValueType;
                NDBFieldType ndbFieldType = GetNDBFieldType(valueType);
                return((NDBFieldType)(ndbFieldType + 100));
            }
            else
            {
                return(GetNDBFieldType(fieldType));
            }
        }
예제 #3
0
        private static byte[] GetFieldBytes(List <Field> fields, out int dataSize)
        {
            dataSize = 0;

            MemoryStream stream = new MemoryStream();

            foreach (var field in fields)
            {
                NDBFieldType ndbFieldType = GetNDBFieldType(field);
                dataSize += NDBConst.GetFieldSize(ndbFieldType);
                string fieldNameValue = field.Name;

                byte[] fieldTypeBytes    = BitConverter.GetBytes((int)ndbFieldType);
                byte[] fieldNameBytes    = Encoding.UTF8.GetBytes(fieldNameValue);
                byte[] fieldNameLenBytes = BitConverter.GetBytes(fieldNameBytes.Length);

                stream.Write(fieldTypeBytes, 0, fieldTypeBytes.Length);
                stream.Write(fieldNameLenBytes, 0, fieldNameLenBytes.Length);
                stream.Write(fieldNameBytes, 0, fieldNameBytes.Length);
            }
            return(stream.ToArray());
        }
예제 #4
0
 public static int GetFieldSize(NDBFieldType fieldType)
 {
     if (fieldType == NDBFieldType.Null)
     {
         return(0);
     }
     else if (fieldType == NDBFieldType.Bool)
     {
         return(sizeof(bool));
     }
     else if (fieldType == NDBFieldType.Float)
     {
         return(sizeof(float));
     }
     else if (fieldType == NDBFieldType.Long)
     {
         return(sizeof(long));
     }
     else
     {
         return(sizeof(int));
     }
 }
예제 #5
0
 public static int GetFieldOffset(NDBFieldType fieldType)
 {
     if (fieldType == NDBFieldType.Bool)
     {
         return(sizeof(bool));
     }
     else if (fieldType == NDBFieldType.Int || fieldType == NDBFieldType.String || fieldType == NDBFieldType.Text)
     {
         return(sizeof(int));
     }
     else if (fieldType == NDBFieldType.Long)
     {
         return(sizeof(long));
     }
     else if (fieldType == NDBFieldType.Float)
     {
         return(sizeof(float));
     }
     else
     {
         return(0);
     }
 }