internal SphericalHarmonicCoefficientsGridDefinition(BufferedBinaryReader reader) : base(reader) { J = reader.ReadSingle(); K = reader.ReadSingle(); M = reader.ReadSingle(); Method = reader.ReadUInt8(); Mode = reader.ReadUInt8(); }
internal GridPointDataSimplePacking(BufferedBinaryReader reader) { ReferenceValue = reader.ReadSingle(); BinaryScaleFactor = reader.ReadInt16(); DecimalScaleFactor = reader.ReadInt16(); NumberOfBits = reader.ReadUInt8(); OriginalFieldValuesType = (OriginalFieldValuesType)reader.ReadUInt8(); }
private static object ReadValue(BufferedBinaryReader reader, SystemTypeCode type) { switch (type) { case SystemTypeCode.Boolean: return(reader.ReadBoolean()); case SystemTypeCode.Int8: return(reader.ReadInt8()); case SystemTypeCode.UInt8: return(reader.ReadUInt8()); case SystemTypeCode.Int16: return(reader.ReadInt16()); case SystemTypeCode.UInt16: return(reader.ReadUInt16()); case SystemTypeCode.Int32: return(reader.ReadInt32()); case SystemTypeCode.UInt32: return(reader.ReadUInt32()); case SystemTypeCode.Int64: return(reader.ReadInt64()); case SystemTypeCode.UInt64: return(reader.ReadUInt64()); case SystemTypeCode.Single: return(reader.ReadSingle()); case SystemTypeCode.Double: return(reader.ReadDouble()); case SystemTypeCode.Decimal: throw new NotImplementedException(); case SystemTypeCode.DateTime: throw new NotImplementedException(); case SystemTypeCode.Char: return(reader.ReadChar()); case SystemTypeCode.String: return(reader.ReadCountedUtf8()); case SystemTypeCode.Enum: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException(); } }
private static object ReadValue(ElementType type, BufferedBinaryReader reader) { switch (type) { case ElementType.Boolean: return(reader.ReadBoolean()); case ElementType.Char: return(reader.ReadChar()); case ElementType.Int8: return(reader.ReadSByte()); case ElementType.UInt8: return(reader.ReadByte()); case ElementType.Int16: return(reader.ReadInt16()); case ElementType.UInt16: return(reader.ReadUInt16()); case ElementType.Int32: return(reader.ReadInt32()); case ElementType.UInt32: return(reader.ReadUInt32()); case ElementType.Int64: return(reader.ReadInt64()); case ElementType.UInt64: return(reader.ReadUInt64()); case ElementType.Single: return(reader.ReadSingle()); case ElementType.Double: return(reader.ReadDouble()); case ElementType.String: return(Encoding.Unicode.GetString(reader.ToArray())); case ElementType.Class: return(null); default: return(reader.ToArray()); } }
internal GridPointDataComplexPacking(BufferedBinaryReader reader) : base(reader) { GroupSplittingMethod = (GroupSplittingMethod)reader.ReadUInt8(); MissingValueManagement = (ComplexPackingMissingValueManagement)reader.ReadUInt8(); PrimaryMissingValue = reader.ReadSingle(); SecondaryMissingValue = reader.ReadSingle(); NumberOfGroups = reader.ReadUInt32(); ReferenceGroupWidths = reader.ReadUInt8(); BitsGroupWidths = reader.ReadUInt8(); // according to documentation subtract referenceGroupWidths BitsGroupWidths = BitsGroupWidths - ReferenceGroupWidths; ReferenceGroupLength = reader.ReadUInt32(); LengthIncrement = reader.ReadUInt8(); LastGroupLength = reader.ReadUInt32(); BitsScaledGroupLength = reader.ReadUInt8(); }
internal RotatedLatLonGridDefinition(BufferedBinaryReader reader) : base(reader) { SpLat = reader.ReadInt32() * 1e-6f; SpLon = reader.ReadUInt32() * 1e-6f; Rotationangle = reader.ReadSingle(); }
private object ReadValue(BufferedBinaryReader reader, IType type) { var st = type.SystemType(); if (st != null) { switch (st.Code) { case SystemTypeCode.Boolean: return reader.ReadBoolean(); case SystemTypeCode.Int8: return reader.ReadInt8(); case SystemTypeCode.UInt8: return reader.ReadUInt8(); case SystemTypeCode.Int16: return reader.ReadInt16(); case SystemTypeCode.UInt16: return reader.ReadUInt16(); case SystemTypeCode.Int32: return reader.ReadInt32(); case SystemTypeCode.UInt32: return reader.ReadUInt32(); case SystemTypeCode.Int64: return reader.ReadInt64(); case SystemTypeCode.UInt64: return reader.ReadUInt64(); case SystemTypeCode.Single: return reader.ReadSingle(); case SystemTypeCode.Double: return reader.ReadDouble(); case SystemTypeCode.Char: return reader.ReadChar(); case SystemTypeCode.String: return reader.ReadCountedUtf8(); case SystemTypeCode.Object: //boxed value type var e = (ElementType)reader.ReadInt8(); return ReadValue(reader, e); case SystemTypeCode.Type: return ReadType(reader); } } if (type.TypeKind == TypeKind.Enum) { return ReadValue(reader, type.ValueType); } if (type.IsArray) { int numElem = reader.ReadInt32(); Array arr = null; for (int i = 0; i < numElem; ++i) { var val = ReadValue(reader, type.ElementType); if (arr == null) arr = Array.CreateInstance(val.GetType(), numElem); arr.SetValue(val, i); } return arr; } return null; }
private object ReadValue(BufferedBinaryReader reader, ElementType e) { switch (e) { case ElementType.Boolean: return reader.ReadBoolean(); case ElementType.Char: return reader.ReadChar(); case ElementType.Int8: return reader.ReadSByte(); case ElementType.UInt8: return reader.ReadByte(); case ElementType.Int16: return reader.ReadInt16(); case ElementType.UInt16: return reader.ReadUInt16(); case ElementType.Int32: return reader.ReadInt32(); case ElementType.UInt32: return reader.ReadUInt32(); case ElementType.Int64: return reader.ReadInt64(); case ElementType.UInt64: return reader.ReadUInt64(); case ElementType.Single: return reader.ReadSingle(); case ElementType.Double: return reader.ReadDouble(); case ElementType.String: return reader.ReadCountedUtf8(); case ElementType.Object: case ElementType.CustomArgsBoxedObject: { var elem = (ElementType)reader.ReadInt8(); return ReadValue(reader, elem); } case ElementType.CustomArgsEnum: { string enumTypeName = reader.ReadCountedUtf8(); var enumType = FindType(enumTypeName); if (enumType == null) { //TODO: throw new BadMetadataException(); } return ReadValue(reader, enumType); } case ElementType.CustomArgsType: return ReadType(reader); case ElementType.ArraySz: { var arrElemType = (ElementType)reader.ReadInt8(); return ReadArray(reader, arrElemType); } default: throw new ArgumentOutOfRangeException(); } }
internal StretchedRotatedSphericalHarmonicCoefficientsGridDefinition(BufferedBinaryReader reader) : base(reader) { PoleLat = reader.ReadInt32() * 1e-6f; PoleLon = reader.ReadUInt32() * 1e-6f; Factor = reader.ReadSingle(); }
/// <summary> /// Загрузка базы данных в память /// </summary> /// <returns></returns> public void Load() { string filePath = Path.Combine(_environment.ContentRootPath, _dbFileName); BinGeoModel binModel; using (FileStream stream = new FileStream(filePath, FileMode.Open)) { Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); using (BufferedBinaryReader bufferedReader = new BufferedBinaryReader(stream, 65536)) { stopwatch.Start(); bufferedReader.FillBuffer(); int version = bufferedReader.ReadInt32(); byte[] nameBytes = bufferedReader.Read(0, 32); ulong timestamp = bufferedReader.ReadUInt64(); int records = bufferedReader.ReadInt32(); uint offsetRanges = bufferedReader.ReadUInt32(); uint offsetCities = bufferedReader.ReadUInt32(); uint offsetLocations = bufferedReader.ReadUInt32(); binModel = new BinGeoModel(version, nameBytes, timestamp, records, offsetRanges, offsetCities, offsetLocations); int currentIndex = 0; binModel.IpRangeCollection = new BinIpRange[binModel.RecordsCount]; while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount) { for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IpRangeBytesCount; currentIndex++) { binModel.IpRangeCollection[currentIndex] = new BinIpRange() { IpFrom = bufferedReader.ReadUInt32(), IpTo = bufferedReader.ReadUInt32(), LocationIndex = bufferedReader.ReadUInt32() }; } } currentIndex = 0; binModel.LocationCollection = new BinLocation[binModel.RecordsCount]; while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount) { for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= LocationBytesCount; currentIndex++) { byte[] country = bufferedReader.Read(0, 8); byte[] region = bufferedReader.Read(0, 12); byte[] postal = bufferedReader.Read(0, 12); byte[] city = bufferedReader.Read(0, 24); byte[] organization = bufferedReader.Read(0, 32); float latitude = bufferedReader.ReadSingle(); float longitude = bufferedReader.ReadSingle(); binModel.LocationCollection[currentIndex] = new BinLocation(country, region, postal, city, organization, latitude, longitude); } } currentIndex = 0; binModel.Indexes = new uint[binModel.RecordsCount]; while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount) { for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IndexBytesCount; currentIndex++) { binModel.Indexes[currentIndex] = bufferedReader.ReadUInt32(); } } stopwatch.Stop(); DatabaseLoadedTimeMs = stopwatch.ElapsedMilliseconds; _logger.LogInformation($"Database loading time: {stopwatch.ElapsedMilliseconds} ms"); } // Отображение объектов сущностей двоичной базы в объекты бизнес сущностей GeoModel = _mapper.Map <GeoModel>(binModel); } }
private static Instruction ReadInstruction(IMethod method, IMethodContext context, BufferedBinaryReader reader, long startPosition) { var instr = new Instruction { Offset = (int)(reader.Position - startPosition), OpCode = OpCodes.Nop }; byte op = reader.ReadUInt8(); OpCode?opCode; if (op != CIL.MultiBytePrefix) { opCode = CIL.GetShortOpCode(op); } else { op = reader.ReadUInt8(); opCode = CIL.GetLongOpCode(op); } if (!opCode.HasValue) { throw new BadImageFormatException(string.Format("The format of instruction with code {0} is invalid", op)); } instr.OpCode = opCode.Value; //Read operand switch (instr.OpCode.OperandType) { case OperandType.InlineI: instr.Value = reader.ReadInt32(); break; case OperandType.ShortInlineI: instr.Value = (int)reader.ReadSByte(); break; case OperandType.InlineI8: instr.Value = reader.ReadInt64(); break; case OperandType.InlineR: instr.Value = reader.ReadDouble(); break; case OperandType.ShortInlineR: instr.Value = reader.ReadSingle(); break; case OperandType.InlineBrTarget: { int offset = reader.ReadInt32(); instr.Value = (int)(offset + reader.Position - startPosition); } break; case OperandType.ShortInlineBrTarget: { int offset = reader.ReadSByte(); instr.Value = (int)(offset + reader.Position - startPosition); } break; case OperandType.InlineSwitch: { int casesCount = reader.ReadInt32(); var switchBranches = new int[casesCount]; for (int k = 0; k < casesCount; k++) { switchBranches[k] = reader.ReadInt32(); } int shift = (int)(reader.Position - startPosition); for (int k = 0; k < casesCount; k++) { switchBranches[k] += shift; } instr.Value = switchBranches; } break; case OperandType.InlineVar: instr.Value = (int)reader.ReadUInt16(); break; case OperandType.ShortInlineVar: instr.Value = reader.ReadByte(); break; case OperandType.InlineString: { int token = reader.ReadInt32(); instr.Value = context.ResolveMetadataToken(method, token); } break; case OperandType.InlineField: case OperandType.InlineMethod: case OperandType.InlineSig: case OperandType.InlineTok: case OperandType.InlineType: { int token = reader.ReadInt32(); instr.MetadataToken = token; object val = context.ResolveMetadataToken(method, token); if (val is ITypeMember) { } if (val == null) { #if DEBUG if (DebugHooks.BreakInvalidMetadataToken) { Debugger.Break(); val = context.ResolveMetadataToken(method, token); } #endif throw new BadTokenException(token); } instr.Value = val; } break; case OperandType.InlineNone: // no operand break; case OperandType.InlinePhi: throw new BadImageFormatException(@"Obsolete. The InlinePhi operand is reserved and should not be used!"); } return(instr); }