Пример #1
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);
            }
        }
Пример #2
0
        private unsafe void SetDataInternal(byte[] dataBytes)
        {
            datas = dataBytes;

            int headerSize = Marshal.SizeOf(typeof(NDBHeader));

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