static byte[] ToBinary(ExpressionBlock expr) { using (var writer = PersistWriter.Create()) { writer.Write(expr); return(writer.ToArray()); } }
public PersistWriter Writer(string name) { var path = Path.Combine(_basepath, name + "." + VariableExtension); var bw = new BinaryWriter(File.Open(path, FileMode.Create)); return(PersistWriter.Create(bw)); }
// shorthand to serialise a heading public static byte[] ToBinary(DataHeading heading) { using (var writer = PersistWriter.Create()) { writer.Write(heading); return(writer.ToArray()); } }
// shorthand to serialise a value of known type // must include type to know column order public static byte[] ToBinary(TypedValue value) { using (var writer = PersistWriter.Create()) { writer.WriteValue(value); return(writer.ToArray()); } }
// Store typed value on memory stream, return byte array public byte[] Store(TypedValue value) { using (var writer = new BinaryWriter(new MemoryStream())) { var w = PersistWriter.Create(writer); w.Store(value); return((writer.BaseStream as MemoryStream).ToArray()); } }
// Store typed value on file stream public void Store(string name, TypedValue value) { var path = Path.Combine(_basepath, name + "." + VariableExtension); Logger.WriteLine(3, "Storing {0} {1}", name, value); try { using (var writer = new BinaryWriter(File.Open(path, FileMode.Create))) { var w = PersistWriter.Create(writer); w.Store(value); } } catch (Exception ex) { throw ProgramError.Fatal("Storage", "cannot store '{0}' : {1}", name, ex.Message); } }
// persist a catalog entry public byte[] ToBinary() { using (var writer = PersistWriter.Create()) { writer.Write(Name); writer.Write((byte)Kind); writer.Write((byte)Flags); writer.Write(DataType); if (IsDatabase) { writer.WriteValue(RelationValue.Create(DataTableLocal.Create(Value.Heading))); } else if (Kind != EntryKinds.Type) { writer.WriteValue(Value); } return(writer.ToArray()); } }
public static PersistWriter Create() { return(PersistWriter.Create(new BinaryWriter(new MemoryStream()))); }