internal static string Read256String(ReaderBase reader) { byte length = reader.ReadByte(); byte[] strBytes = reader.ReadBytes(length); return(Encoding.UTF8.GetString(strBytes)); }
internal STransaction(SDatabase d, ReaderBase rdr, bool auto) : base(d) { autoCommit = auto; uid = _uid; readConstraints = SDict <long, bool> .Empty; rdr.db = this; }
protected BTreePage(ReaderBase reader, uint page, BTreeHeader header, ushort[] cellOffsets) { Reader = reader; Page = page; Header = header; CellOffsets = cellOffsets; }
protected void CheckPermission(ReaderBase reader, int id) { var like = reader.GetById(id); if (!IsCreatedByCurrentUser(like)) { throw new HttpResponseException(HttpStatusCode.Forbidden); } }
public Sqlite3Database(Stream file, Sqlite3Settings settings = null) { _settings = settings ?? new Sqlite3Settings(); _reader = new ReaderBase(file); _propertyStore = new Dictionary <string, object>(); Initialize(); InitializeMasterTable(); }
void CreateColumn(ReaderBase rdr) { var sc = (SColumn)rdr._Get(); var db = (STransaction)rdr.db; sc = (SColumn)sc.Prepare(db, ((STable)db.objects[sc.table]).Names(db, SDict <long, long> .Empty)); var cn = db.role[sc.uid]; rdr.db = db.Install(new SColumn(db, sc.table, sc.dataType, sc.constraints), cn, db.curpos); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="page">The initial page</param> /// <param name="dataOffset">The offset to the initial data</param> /// <param name="dataLength">The length of the initial data in the initial page</param> /// <param name="overflowPage">The pointer to the first overflow page</param> /// <param name="fullDataSize">The final length of all data in this stream</param> public SqliteDataStream(ReaderBase reader, uint page, ushort dataOffset, ushort dataLength, uint overflowPage, long fullDataSize) { _reader = reader; _currentPage = page; _dataOffset = dataOffset; _dataLengthRemaining = dataLength; _nextPage = overflowPage; Length = fullDataSize; _fullLengthRemaining = fullDataSize; }
internal static object ReadPrimitive(ReaderBase reader, TypeCode code) { switch (code) { case TypeCode.Boolean: return(reader.ReadBoolean()); case TypeCode.Byte: return(reader.ReadByte()); case TypeCode.Char: return(reader.ReadChar()); case TypeCode.DateTime: return(reader.ReadDateTime()); case TypeCode.Decimal: return(reader.ReadDecimal()); case TypeCode.Double: return(reader.ReadDouble()); case TypeCode.Int16: return(reader.ReadInt16()); case TypeCode.Int32: return(reader.ReadInt32()); case TypeCode.Int64: return(reader.ReadInt64()); case TypeCode.SByte: return(reader.ReadSByte()); case TypeCode.Single: return(reader.ReadSingle()); case TypeCode.String: return(reader.ReadString()); case TypeCode.UInt16: return(reader.ReadUInt16()); case TypeCode.UInt32: return(reader.ReadUInt32()); case TypeCode.UInt64: return(reader.ReadUInt64()); case TypeCode.DBNull: return(DBNull.Value); } return(null); }
// We peek at the table expression to compute the set of columns of the join static SQuery _Join(ReaderBase f) { f.GetInt(); var st = f.buf.pos; var d = SDict <int, (long, string)> .Empty; var c = SDict <int, Serialisable> .Empty; var nms = SDict <string, long> .Empty; var left = f._Get() as SQuery ?? throw new StrongException("Query expected"); var outer = f.GetInt() == 1; var joinType = (JoinType)f.GetInt(); var right = f._Get() as SQuery ?? throw new StrongException("Query expected"); var ab = left.Display.First(); var uses = SDict <long, long> .Empty; if (joinType.HasFlag(JoinType.Named)) { var n = f.GetInt(); for (var i = 0; i < n; i++) { uses += (f.GetLong(), f.GetLong()); } } var k = 0; for (var lb = left.cpos.First(); ab != null && lb != null; ab = ab.Next(), lb = lb.Next()) { var col = lb.Value; var u = ab.Value.Item2; d += (k, u); c += (k, col.Item2); nms += (u.Item2, u.Item1); k++; } ab = right.Display.First(); for (var rb = right.cpos.First(); ab != null && rb != null; ab = ab.Next(), rb = rb.Next()) { var u = ab.Value.Item2; var n = u.Item2; if (joinType == JoinType.Natural && nms.Contains(n)) { continue; } if (uses.Contains(u.Item1)) { continue; } var col = rb.Value; d += (k, u); c += (k, col.Item2); k++; } f.buf.pos = st; return(new SQuery(Types.STableExp, d, c)); }
public object Deserialize(ReaderBase reader, Type expectedType) { try { GraphReader graphReader = new GraphReader(this.TypeBinder, reader, this.SurrogateSelector, this.Context, this.WellKnownContents); return(graphReader.Deserialize(expectedType)); } catch (Exception inner) { throw new SerializationException(inner.Message, inner); } }
public T Deserialize <T>(ReaderBase reader) { try { GraphReader graphReader = new GraphReader(this.TypeBinder, reader, this.SurrogateSelector, this.Context, this.WellKnownContents); return((T)graphReader.Deserialize(typeof(T))); } catch (Exception inner) { throw new SerializationException(inner.Message, inner); } }
public readonly SDict <long, long> uses; // Item1 is for RIGHT, Item2 for LEFT public SJoin(ReaderBase f) : base(Types.STableExp, _Join(f)) { left = f._Get() as SQuery ?? throw new StrongException("Query expected"); outer = f.GetInt() == 1; joinType = (JoinType)f.GetInt(); right = f._Get() as SQuery ?? throw new StrongException("Query expected"); var n = f.GetInt(); var on = SList <SExpression> .Empty; var us = SDict <long, long> .Empty; var tr = (STransaction)f.db; var lns = SDict <string, long> .Empty; for (var b = left.Display.First(); b != null; b = b.Next()) { lns += (b.Value.Item2.Item2, b.Value.Item2.Item1); } var rns = SDict <string, long> .Empty; for (var b = right.Display.First(); b != null; b = b.Next()) { var nm = b.Value.Item2.Item2; if (joinType == JoinType.Natural && lns.Contains(nm)) { us += (b.Value.Item2.Item1, lns[nm]); } rns += (nm, b.Value.Item2.Item1); } if (joinType.HasFlag(JoinType.Named)) { for (var i = 0; i < n; i++) { var nm = tr.uids[f.GetLong()]; if (!(lns.Contains(nm) && rns.Contains(nm))) { throw new StrongException("name " + nm + " not present in Join"); } us += (rns[nm], lns[nm]); } } else if (!joinType.HasFlag(JoinType.Cross)) { for (var i = 0; i < n; i++) { var e = f._Get() as SExpression ?? throw new StrongException("ON exp expected"); on += e; } } ons = on; uses = us; f.context = this; }
internal static BTreePage Parse(ReaderBase reader, uint page) { // Read header reader.SeekPage(page); if (page == 1) { // Skip the first 100 bytes reader.Skip(DatabaseHeader.HeaderSize); } BTreeHeader header = BTreeHeader.Parse(reader); // Read cells ushort[] cellOffsets = new ushort[header.CellCount]; for (ushort i = 0; i < header.CellCount; i++) { cellOffsets[i] = reader.ReadUInt16(); } Array.Sort(cellOffsets); BTreePage res; switch (header.Type) { case BTreeType.InteriorIndexBtreePage: throw new ArgumentOutOfRangeException(); case BTreeType.InteriorTableBtreePage: res = new BTreeInteriorTablePage(reader, page, header, cellOffsets); break; case BTreeType.LeafIndexBtreePage: throw new ArgumentOutOfRangeException(); case BTreeType.LeafTableBtreePage: res = new BTreeLeafTablePage(reader, page, header, cellOffsets); break; default: throw new ArgumentOutOfRangeException(); } res.ParseInternal(); return(res); }
private void OutputError(ReaderBase reader, string errorString) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Errors encountered loading " + errorString + ":"); sb.AppendLine(); foreach (string err in reader.Errors) { sb.AppendLine(err); } Error = sb.ToString(); HadError = true; }
internal GraphReader(TypeBinder binder, ReaderBase reader, ISurrogateSelector selector, StreamingContext context, SerializationContents contents) { this._binder = binder; this._reader = reader; this._readObjects = new Dictionary <ushort, object>(); if (contents == null) { this._readAssemblies = new List <string>(); this._readTypes = new List <string>(); this._stringContents = new List <string>(); } else { this._readAssemblies = new List <string>(contents._AssemblyContents); this._readTypes = new List <string>(contents._TypeContents); this._stringContents = new List <string>(contents._StringContents); } this._selector = selector; this._context = context; }
public static BTreeHeader Parse(ReaderBase reader) { reader.CheckSize(8); BTreeHeader res = new BTreeHeader(); res.Type = (BTreeType)reader.ReadByte(); res.FirstFreeBlock = reader.ReadUInt16(); res.CellCount = reader.ReadUInt16(); res.CellContentBegin = reader.ReadUInt16(); res.CellContentFragmentedFreeBytes = reader.ReadByte(); if (res.Type == BTreeType.InteriorIndexBtreePage || res.Type == BTreeType.InteriorTableBtreePage) { reader.CheckSize(sizeof(uint)); res.RightMostPointer = reader.ReadUInt32(); } return(res); }
internal static DatabaseHeader Parse(ReaderBase reader) { // The header is 100 bytes reader.CheckSize(100); reader.CheckMagicBytes(_expectedHeader); // Read header DatabaseHeader res = new DatabaseHeader(); res.PageSize = reader.ReadUInt16(); res.WriteVersion = (FileWriteVersion)reader.ReadByte(); res.ReadVersion = (FileReadVersion)reader.ReadByte(); res.ReservedSpaceAtEndOfPage = reader.ReadByte(); res.MaximumEmbeddedPayloadFraction = reader.ReadByte(); res.MinimumEmbeddedPayloadFraction = reader.ReadByte(); res.LeafPayloadFraction = reader.ReadByte(); res.ChangeCounter = reader.ReadUInt32(); res.DatabaseSizeInPages = reader.ReadUInt32(); res.FirstFreelistTrunkPage = reader.ReadUInt32(); res.FreeListPages = reader.ReadUInt32(); res.SchemaCookie = reader.ReadUInt32(); res.SchemaFormat = reader.ReadUInt32(); res.DefaultPageCacheSize = reader.ReadUInt32(); res.Value7 = reader.ReadUInt32(); res.TextEncoding = (SqliteEncoding)reader.ReadUInt32(); res.UserVersion = reader.ReadUInt32(); res.IncrementalVacuumMode = reader.ReadUInt32(); res.ApplicationId = reader.ReadUInt32(); reader.Skip(20); res.VersionValidFor = reader.ReadUInt32(); res.Version = reader.ReadUInt32(); // TODO: Warn/err on mismatch with expected values return(res); }
private void OutputError( ReaderBase reader, string errorString ) { StringBuilder sb = new StringBuilder(); sb.AppendLine( "Errors encountered loading " + errorString + ":" ); sb.AppendLine(); foreach( string err in reader.Errors ) sb.AppendLine( err ); Error = sb.ToString(); HadError = true; }
public DraftHybi00DataReader(ReaderBase previousCommandReader) : base(previousCommandReader) { }
public BTreeInteriorTablePage(ReaderBase reader, uint page, BTreeHeader header, ushort[] cellOffsets) : base(reader, page, header, cellOffsets) { }
public IEnumerable <Sqlite3Row> EnumerateRows() { IEnumerable <BTreeCellData> cells = BTreeTools.WalkTableBTree(RootPage); List <ColumnDataMeta> metaInfos = new List <ColumnDataMeta>(); foreach (BTreeCellData cell in cells) { metaInfos.Clear(); // Create a new stream to cover any fragmentation that might occur // The stream is started in the current cells "resident" data, and will overflow to any other pages as needed using (SqliteDataStream dataStream = new SqliteDataStream(_reader, cell.Page, (ushort)(cell.CellOffset + cell.Cell.CellHeaderSize), cell.Cell.DataSizeInCell, cell.Cell.FirstOverflowPage, cell.Cell.DataSize)) { ReaderBase reader = new ReaderBase(dataStream, _reader); long headerSize = reader.ReadVarInt(out _); while (reader.Position < headerSize) { long columnInfo = reader.ReadVarInt(out _); ColumnDataMeta meta = new ColumnDataMeta(); if (columnInfo == 0) { meta.Type = SqliteDataType.Null; } else if (columnInfo == 1) { meta.Type = SqliteDataType.Integer; meta.Length = 1; } else if (columnInfo == 2) { meta.Type = SqliteDataType.Integer; meta.Length = 2; } else if (columnInfo == 3) { meta.Type = SqliteDataType.Integer; meta.Length = 3; } else if (columnInfo == 4) { meta.Type = SqliteDataType.Integer; meta.Length = 4; } else if (columnInfo == 5) { meta.Type = SqliteDataType.Integer; meta.Length = 6; } else if (columnInfo == 6) { meta.Type = SqliteDataType.Integer; meta.Length = 8; } else if (columnInfo == 7) { meta.Type = SqliteDataType.Float; meta.Length = 8; } else if (columnInfo == 8) { meta.Type = SqliteDataType.Boolean0; } else if (columnInfo == 9) { meta.Type = SqliteDataType.Boolean1; } else if (columnInfo == 10 || columnInfo == 11) { throw new ArgumentOutOfRangeException(); } else if ((columnInfo & 0x01) == 0x00) { // Even number meta.Type = SqliteDataType.Blob; meta.Length = (uint)((columnInfo - 12) / 2); } else { // Odd number meta.Type = SqliteDataType.Text; meta.Length = (uint)((columnInfo - 13) / 2); } metaInfos.Add(meta); } object[] rowData = new object[metaInfos.Count]; for (int i = 0; i < metaInfos.Count; i++) { ColumnDataMeta meta = metaInfos[i]; switch (meta.Type) { case SqliteDataType.Null: rowData[i] = null; break; case SqliteDataType.Integer: // TODO: Do we handle negatives correctly? rowData[i] = reader.ReadInteger((byte)meta.Length); break; case SqliteDataType.Float: rowData[i] = BitConverter.Int64BitsToDouble(reader.ReadInteger((byte)meta.Length)); break; case SqliteDataType.Boolean0: rowData[i] = false; break; case SqliteDataType.Boolean1: rowData[i] = true; break; case SqliteDataType.Blob: rowData[i] = reader.Read((int)meta.Length); break; case SqliteDataType.Text: rowData[i] = reader.ReadString(meta.Length); break; default: throw new ArgumentOutOfRangeException(); } } yield return(new Sqlite3Row(this, cell.Cell.RowId, rowData)); } } }
public object Deserialize(Stream serializationStream, Type expectedType) { return(this.Deserialize(ReaderBase.StreamReader(serializationStream), expectedType)); }
void CreateIndex(ReaderBase rdr) { var db = (STransaction)rdr.db; rdr.db = db.Install((SIndex)SIndex.Get(rdr).Prepare(db, SDict <long, long> .Empty), db.curpos); }
private bool LoadData(ReaderBase reader, IEnumerable <Mod> mods, string subDir, string errorString, string ext, bool falseOnNoDirectory) { Dictionary <string, string> files = new Dictionary <string, string>(); DirectoryInfo dir; // Oldest First. Discover if vanilla should be loaded. bool loadVanilla = mods.All(m => !m.Replaces.Contains(subDir)); if (loadVanilla) { dir = new DirectoryInfo(Path.Combine(InstallDir.FullName, subDir).Replace('\\', '/')); // Hack so it works when the eu4 converter isn't present. if (!dir.Exists && falseOnNoDirectory) { return(false); } if (!dir.Exists) { return(true); } m_log.Log("Loading files from " + dir.FullName, Logger.LogType.Data); FileInfo[] list = dir.GetFiles(ext); foreach (FileInfo f in list) { files[f.Name] = f.FullName; } } // If using mods, load files. string dirTemp; foreach (Mod m in mods) { dirTemp = m.ModPathType == ModReader.Folder.CKDir ? InstallDir.FullName : MyDocsDir.FullName; dirTemp = Path.Combine(dirTemp, m.Path); dirTemp = Path.Combine(dirTemp, subDir).Replace('\\', '/'); if (!Directory.Exists(dirTemp)) { continue; } dir = new DirectoryInfo(dirTemp); m_log.Log("Loading files from " + dir.FullName, Logger.LogType.Data); FileInfo[] list = dir.GetFiles(ext); foreach (FileInfo f in list) { files[f.Name] = f.FullName; } } foreach (var file in files) { m_log.Log("Reading File: " + file.Value, Logger.LogType.Data); reader.Parse(file.Value); } if (reader.Errors.Count > 0) { OutputError(reader, errorString); return(false); } return(true); }
public T Deserialize <T>(Stream serializationStream) { return((T)this.Deserialize(ReaderBase.StreamReader(serializationStream), typeof(T))); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(ReaderBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_ReceiveEvent, serviceImpl.ReceiveEvent) .AddMethod(__Method_ReceiveCommand, serviceImpl.ReceiveCommand).Build()); }
private bool LoadData( ReaderBase reader, IEnumerable<Mod> mods, string subDir, string errorString, string ext, bool falseOnNoDirectory ) { Dictionary<string, string> files = new Dictionary<string, string>(); DirectoryInfo dir; // Oldest First. Discover if vanilla should be loaded. bool loadVanilla = mods.All( m => !m.Replaces.Contains( subDir ) ); if( loadVanilla ) { dir = new DirectoryInfo( Path.Combine( InstallDir.FullName, subDir ).Replace( '\\', '/' ) ); // Hack so it works when the eu4 converter isn't present. if( !dir.Exists && falseOnNoDirectory ) return false; if( !dir.Exists ) return true; m_log.Log( "Loading files from " + dir.FullName, Logger.LogType.Data ); FileInfo[] list = dir.GetFiles( ext ); foreach( FileInfo f in list ) files[f.Name] = f.FullName; } // If using mods, load files. string dirTemp; foreach( Mod m in mods ) { dirTemp = m.ModPathType == ModReader.Folder.CKDir ? InstallDir.FullName : MyDocsDir.FullName; dirTemp = Path.Combine( dirTemp, m.Path ); dirTemp = Path.Combine( dirTemp, subDir ).Replace( '\\', '/' ); if( !Directory.Exists( dirTemp ) ) continue; dir = new DirectoryInfo( dirTemp ); m_log.Log( "Loading files from " + dir.FullName, Logger.LogType.Data ); FileInfo[] list = dir.GetFiles( ext ); foreach( FileInfo f in list ) files[f.Name] = f.FullName; } foreach( var file in files ) { m_log.Log( "Reading File: " + file.Value, Logger.LogType.Data ); reader.Parse( file.Value ); } if( reader.Errors.Count > 0 ) { OutputError( reader, errorString ); return false; } return true; }
public object Deserialize(Stream serializationStream) { return(this.Deserialize(ReaderBase.StreamReader(serializationStream), null)); }
internal Sqlite3Table(ReaderBase reader, BTreePage rootPage, Sqlite3SchemaRow table) { SchemaDefinition = table; _reader = reader; RootPage = rootPage; }
internal GraphReader(TypeBinder binder, ReaderBase reader, ISurrogateSelector selector, StreamingContext context) : this(binder, reader, selector, context, null) { }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, ReaderBase serviceImpl) { serviceBinder.AddMethod(__Method_ReceiveEvent, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::ActorPlayground.Remote.MessageEnvelope, global::ActorPlayground.Remote.Unit>(serviceImpl.ReceiveEvent)); serviceBinder.AddMethod(__Method_ReceiveCommand, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::ActorPlayground.Remote.MessageEnvelope, global::ActorPlayground.Remote.MessageEnvelope>(serviceImpl.ReceiveCommand)); }
internal GraphReader(TypeBinder binder, ReaderBase reader, ISurrogateSelector selector, SerializationContents contents) : this(binder, reader, selector, SerializationStaticHelpers.StreamingContext, contents) { }
public TSpecific Deserialize(ReaderBase reader) { return((TSpecific)this._realSerializer.Deserialize(reader, this._specificType)); }