Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        private void SetDataInternal(byte[] dataBytes)
        {
            this.dataBytes = dataBytes;

            int headerSize = MarshalUtility.GetStructSize(typeof(NDBHeader));

            if (dataBytes == null || dataBytes.Length < headerSize)
            {
                throw new ArgumentNullException($"The databytes is empty. Name = {Name}");
            }
            header = MarshalUtility.ByteToStruct <NDBHeader>(dataBytes, 0, headerSize);

            fields = new NDBField[header.fieldCount];
            int fieldOffset = 0;
            int byteOffset  = 0;

            for (int i = 0; i < header.fieldCount; ++i)
            {
                NDBField field = NDBByteUtility.ReadField(dataBytes, header.fieldOffset + byteOffset, out int offset);

                fields[i]    = field;
                field.Offset = fieldOffset;
                fieldOffset += NDBFieldUtil.GetFieldOffset(field.FieldType);
                fieldNameToIndexDic.Add(field.Name, i);

                byteOffset += offset;
            }

            for (int i = 0; i < header.lineCount; ++i)
            {
                int id = ByteReader.ReadInt(dataBytes, header.lineOffset + header.lineSize * i, out int offset);
                dataIDToIndexDic.Add(id, i);
            }
        }
Ejemplo n.º 3
0
        public static NDBField ReadField(byte[] bytes, int startIndex, out int offset)
        {
            offset = 0;

            NDBField field = new NDBField();

            fixed(byte *bytePtr = &bytes[startIndex])
            {
                field.FieldType = (NDBFieldType)(*(bytePtr + offset));
                offset         += sizeof(byte);

                int len = *((int *)(bytePtr + offset));

                offset += sizeof(int);

                field.Name = Encoding.UTF8.GetString(bytes, startIndex + offset, len);
                offset    += len;
            }

            return(field);
        }
Ejemplo n.º 4
0
 public static void WriteField(Stream stream, NDBField field)
 {
     stream.WriteByte((byte)field.FieldType);
     ByteWriter.WriteString(stream, field.Name);
 }