public byte[] Serialize() { var _SerializationWriter = new SerializationWriter(); _SerializationWriter.WriteString(ThrowedException); return _SerializationWriter.ToArray(); }
public byte[] Serialize() { var _SerializationWriter = new SerializationWriter(); _SerializationWriter.WriteUInt32(NumberOfQueueEntries); return _SerializationWriter.ToArray(); }
public static void Serialize(SerializationWriter writer, Color color) { BitVector32 flags = new BitVector32(); if (color.IsKnownColor) flags[ColorIsKnown] = true; else if (color.IsNamedColor) flags[ColorHasName] = true; else if (!color.IsEmpty) { flags[ColorHasValue] = true; flags[ColorHasRed] = color.R != 0; flags[ColorHasGreen] = color.G != 0; flags[ColorHasBlue] = color.B != 0; flags[ColorHasAlpha] = color.A != 0; } writer.WriteOptimized(flags); if (color.IsKnownColor) writer.WriteOptimized((int) color.ToKnownColor()); else if (color.IsNamedColor) writer.WriteOptimized(color.Name); else if (!color.IsEmpty) { byte component; if ( (component = color.R) != 0) writer.Write(component); if ( (component = color.G) != 0) writer.Write(component); if ( (component = color.B) != 0) writer.Write(component); if ( (component = color.A) != 0) writer.Write(component); } }
public byte[] Serialize() { var _SerializationWriter = new SerializationWriter(); _SerializationWriter.WriteString(Message); return _SerializationWriter.ToArray(); }
public Byte[] Serialize() { var _SerializationWriter = new SerializationWriter(); _SerializationWriter.WriteString(ObjectLocation); _SerializationWriter.WriteByte(NewDefaultRule); return _SerializationWriter.ToArray(); }
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { using (SerializationWriter writer = new SerializationWriter()) { writer.Write(_name); writer.WriteObject(_dataType); writer.WriteObject(_value); info.AddValue("d", writer.ToArray()); } }
public void Serialize(SerializationWriter writer, object value) { Type type = value.GetType(); if (type == typeof(Color)) Serialize(writer, (Color) value); else { throw new InvalidOperationException(string.Format("{0} does not support Type: {1}", GetType(), type)); } }
public byte[] Serialize() { SerializationWriter writer = new SerializationWriter(); writer.WriteObject(AccountName); writer.WriteObject(DeviceID); writer.WriteObject(Timestamp); writer.WriteObject(Latitude); writer.WriteObject(Longitude); writer.WriteObject(AccuracyInMeters); return writer.ToArray(); }
public void TestNull() { using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { sw.Write<object>(null); sw.Write<int[]>(null); sw.Write<List<int>>(null); sw.Write<Dictionary<int, string>>(null); sw.Write<TestSerializable>(null); } }
public void TestUTF16Chars() { using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding())) using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding())) { for (int i = 0; i < 55296; i++) sw.Write((char)i); sw.Flush(); ms.Position = 0; for (int i = 0; i < 55296; i++) Assert.AreEqual((char)i, sr.Read<char>()); } }
public static void Serialize(SerializationWriter writer, StateBag stateBag) { List <DictionaryEntry> dirtyEntries = new List <DictionaryEntry>(); List <DictionaryEntry> cleanEntries = new List <DictionaryEntry>(); BitVector32 flags = new BitVector32(); flags[StateBagIsIgnoreCase] = (bool)StateBagIgnoreCaseField.GetValue(stateBag); foreach (DictionaryEntry entry in stateBag) { StateItem stateItem = (StateItem)entry.Value; if (stateItem.IsDirty) { dirtyEntries.Add(entry); } else { cleanEntries.Add(entry); } } flags[StateBagHasDirtyEntries] = dirtyEntries.Count != 0; flags[StateBagHasCleanEntries] = cleanEntries.Count != 0; writer.WriteOptimized(flags); if (dirtyEntries.Count != 0) { writer.WriteOptimized(dirtyEntries.Count); foreach (DictionaryEntry entry in dirtyEntries) { writer.WriteOptimized((string)entry.Key); writer.WriteObject((entry.Value as StateItem).Value); } } if (cleanEntries.Count != 0) { writer.WriteOptimized(cleanEntries.Count); foreach (DictionaryEntry entry in cleanEntries) { writer.WriteOptimized((string)entry.Key); writer.WriteObject((entry.Value as StateItem).Value); } } }
public void WriteCommandToStream(SerializationWriter writer) { /* * string text = string.Concat(new string[] * { * ":", * this.class24_0.method_0(), * " JOIN :", * this.string_0, * "\n" * }); * string text2 = this.class24_0.method_1(); * string a; * if (text2.Length > 0 && (a = text2) != null) * { * if (!(a == "+")) * { * if (a == "@") * { * string text3 = text; * text = string.Concat(new string[] * { * text3, * ":[email protected] MODE ", * this.string_0, * " +o ", * this.class24_0.string_1, * "\n" * }); * } * } * else * { * string text4 = text; * text = string.Concat(new string[] * { * text4, * ":[email protected] MODE ", * this.string_0, * " +v ", * this.class24_0.string_1, * "\n" * }); * } * } * osuBinaryWriter0.method_3(text);*/ }
public void WriteToStream(SerializationWriter sw) { sw.Write((short)matchId); sw.Write(inProgress); sw.Write((byte)matchType); sw.Write((uint)activeMods); sw.Write(gameName); sw.Write(!SendPassword && gamePassword != null ? string.Empty : gamePassword); sw.Write(beatmapName); sw.Write(beatmapId); sw.Write(beatmapChecksum); for (int i = 0; i < MAX_PLAYERS; i++) { sw.Write((byte)slotStatus[i]); } for (int i = 0; i < MAX_PLAYERS; i++) { sw.Write((byte)slotTeam[i]); } for (int i = 0; i < MAX_PLAYERS; i++) { if ((slotStatus[i] & SlotStatus.HasPlayer) > 0) { sw.Write(slotId[i]); } } sw.Write(hostId); sw.Write((byte)playMode); sw.Write((byte)matchScoringType); sw.Write((byte)matchTeamType); sw.Write((byte)specialModes); if ((specialModes & MultiSpecialModes.FreeMod) > 0) { for (int i = 0; i < MAX_PLAYERS; i++) { sw.Write((int)slotMods[i]); } } sw.Write(Seed); }
public virtual void Save(SerializationWriter SW) { SW.WriteStartElement("Translator"); SW.WriteVersion(0); SW.Write("Name", Name); SW.Write("Culture", Culture); SW.Write("Length", Translates.Length); for (int i = 0; i < Translates.Length; i++) { if (Translates[i] != null) { SW.Write("Key", Translates[i].Key); SW.Write("Text", Translates[i].Text); } } SW.WriteEndElement(); }
public void Serialize(SerializationWriter writer) { IEvaluable[] evalscopy = new IEvaluable[evaluables.Count]; evaluables.CopyTo(evalscopy, 0); List <IAgent> agents = new List <IAgent>(); foreach (IEvaluable eval in evalscopy) { if (eval is IAgent) { agents.Add((IAgent)eval); } } writer.WriteList <IAgent>(agents); }
public static async Task <byte[]> LoginReplyAsync(LoginReplies reply) { var packet = new Packet { Type = PacketType.ServerLoginReply }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write((int)reply); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); var pWriter = new PacketWriter(); await pWriter.Write(packet); return(pWriter.ToBytes()); }
public void WriteToStream(SerializationWriter w) { w.Write(PlayerId); w.Write(PlayerName); w.Write(UtcOffset); w.Write(CountryByte); int rankPart = (byte)PlayerRank & 0b0001_1111; int modePart = ((byte)GameMode << 5) & 0b1110_0000; w.Write((byte)(rankPart | modePart)); w.Write(Longitude); w.Write(Latitude); w.Write(GlobalRank); w.Write(LastUpdate); }
public static async Task <byte[]> NotificationAsync(string notification) { var packet = new Packet { Type = PacketType.ServerNotification }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write(notification); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); var pWriter = new PacketWriter(); await pWriter.Write(packet); return(pWriter.ToBytes()); }
public void ReadWriteReplay() { Replay db; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UnitTestProject.Data.Replays.20210316.osr")) db = Replay.Read(stream); using var ms = new MemoryStream(); using var sw = new SerializationWriter(ms); db.WriteToStream(sw); ms.Position = 0; var read = Replay.Read(ms); db.Should().BeEquivalentTo(read); }
public static async Task ChatChannelAvailable(this Presence p, string name, string topic, short userCount) { var packet = new Packet { Type = PacketType.ServerChatChannelAvailable }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write(name); writer.Write(topic); writer.Write(userCount); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); p.PacketEnqueue(packet); }
private bool save() { lock (saveLock) { Interlocked.Increment(ref lastSave); try { // This is NOT thread-safe!! using (var sw = new SerializationWriter(storage.GetStream(database_name, FileAccess.Write))) { sw.Write(database_version); sw.Write(Collections.Count); foreach (var c in Collections) { sw.Write(c.Name.Value); sw.Write(c.Beatmaps.Count); foreach (var b in c.Beatmaps) { sw.Write(b.MD5Hash); } } } if (saveFailures < 10) { saveFailures = 0; } return(true); } catch (Exception e) { // Since this code is not thread-safe, we may run into random exceptions (such as collection enumeration or out of range indexing). // Failures are thus only alerted if they exceed a threshold (once) to indicate "actual" errors having occurred. if (++saveFailures == 10) { Logger.Error(e, "Failed to save collection database!"); } } return(false); } }
public static async Task <byte[]> BanchoRestart(int timeout) { var packet = new Packet { Type = PacketType.ServerRestart }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write(timeout); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); var pWriter = new PacketWriter(); await pWriter.Write(packet); return(pWriter.ToBytes()); }
public void WriteToStream(SerializationWriter writer) { writer.Write(int_1); writer.Write(byte_0); writer.Write(ushort_1); writer.Write(ushort_0); writer.Write(ushort_2); writer.Write(ushort_3); writer.Write(ushort_4); writer.Write(ushort_5); writer.Write(int_2); writer.Write(ushort_7); writer.Write(ushort_6); writer.Write(bool_1); writer.Write((byte)(bool_0 ? int_0 : 254)); writer.Write(int_3); }
public override void Save(SerializationWriter Writer) { base.Save(Writer); this.village.entity.Save(Writer); Writer.Write(amount); Writer.Write(faction.Name); Writer.Write(historytales.Count); foreach (JournalVillageNote tale in historytales) { Writer.Write(tale.secretid); } Writer.Write(tales.Count); foreach (string tale in tales) { Writer.Write(tale); } }
public static void Serialize(SerializationWriter writer, Unit unit) { BitVector32 state = new BitVector32(); if (unit.IsEmpty) { writer.WriteOptimized(state); return; } state[UnitType] = (int)unit.Type; int integerValue = (int)Math.Round(unit.Value); bool writeAsDouble = unit.Type != System.Web.UI.WebControls.UnitType.Pixel && Math.Abs(unit.Value - integerValue) > Epsilon; if (writeAsDouble) { state[UnitIsDoubleValue] = true; writer.WriteOptimized(state); writer.Write(unit.Value); } else if (integerValue == 0) { state[UnitIsZeroValue] = 1; writer.WriteOptimized(state); } else { int complementedValue = integerValue > 0 ? integerValue : -(integerValue + 1); if (complementedValue > SerializationWriter.HighestOptimizable16BitValue) { writer.WriteOptimized(state); writer.Write((short)integerValue); } else { state[UnitIsOptimizedValue] = 1; state[UnitIsNegativeValue] = integerValue > 0 ? 0 : 1; writer.WriteOptimized(state); writer.WriteOptimized(complementedValue); } } }
public static async Task MatchInvite(this Presence p, Presence sender, string message) { var packet = new Packet { Type = PacketType.ServerMultiInvite }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write(sender.Username); writer.Write(message); writer.Write(p.Username); writer.Write(sender.Id); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); p.PacketEnqueue(packet); }
public static async Task ChatMessage(this Presence p, string sender, string message, string target, int id) { var packet = new Packet { Type = PacketType.ServerChatMessage }; await using var writer = new SerializationWriter(new MemoryStream()); writer.Write(sender); writer.Write(message); writer.Write(target); writer.Write(id); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); p.PacketEnqueue(packet); }
public void GetObjectData(SerializationInfo info, StreamingContext context) { var writer = SerializationWriter.GetWriter(); writer.WriteString(AccountId); writer.Write(Balance); writer.Write(ClearedBalance); writer.Write(Closed); writer.Write(Deleted); writer.WriteString(Name); writer.WriteString(Note); writer.Write(OnBudget); writer.WriteString(TransferPayeeId); writer.Write((byte)Type); writer.Write(UnclearedBalance); writer.AddToInfo(info); }
public void TestUTF16String() { using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding())) using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding())) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 55296; i++) sb.Append((char)i); string res = sb.ToString(); sw.Write(res); sw.Flush(); ms.Position = 0; Assert.AreEqual(res, sr.Read<string>()); } }
public void Save(SerializationWriter writer) { if (ReadResource()) { writer.Write(0);//parameter writer.Write(_idx.Count); foreach (var aKV in _idx) { writer.WriteObject(aKV.Key); writer.Write(aKV.Value.Id); } FinishReadResource(); return; } throw new CollisionException(this); }
public static async Task ChatChannelAvailable(this Presence p, string name, string topic, short userCount, SerializationWriter writer) { var packet = new Packet { Type = PacketType.ServerChatChannelAvailable }; writer.Write(name); writer.Write(topic); writer.Write(userCount); packet.Data = ((MemoryStream)writer.BaseStream).ToArray(); writer.BaseStream.SetLength(0); writer.BaseStream.Position = 0; p.PacketEnqueue(packet); }
public static void EncodeCollectionDatabase(string path, CollectionDatabase db) { using (SerializationWriter writer = new SerializationWriter(new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))) { writer.Write(db.OsuVersion); writer.Write(db.CollectionCount); foreach (var collection in db.Collections) { writer.Write(collection.Name); writer.Write(collection.Count); foreach (var hash in collection.MD5Hashes) { writer.Write(hash); } } } }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { #if FAST_SERIALIZATION using (SerializationWriter writer = new SerializationWriter()) { foreach (FilterColumn col in _filterColumns) { col.Parent = this; } writer.Write(UniqueId); writer.Write(_alias); writer.Write(_createStoredProcedure); writer.Write(_customWhere); writer.Write(_enabled); //writer.WriteObject(_exposedUserOptions); writer.WriteObject(_filterColumns); writer.Write(_isReturnTypeCollection); writer.Write(_isUserDefined); writer.Write(_name); writer.WriteObject(_orderByColumns); //writer.WriteObject(_parent); writer.Write(_useCustomWhere); writer.WriteObject(_userOptions); info.AddValue("d", writer.ToArray()); } info.AddValue("UserOptions", this._userOptions); #else info.AddValue("SerializationVersion", SerializationVersion); info.AddValue("Alias", _alias); info.AddValue("CreateStoredProcedure", _createStoredProcedure); info.AddValue("CustomWhere", _customWhere); info.AddValue("Enabled", _enabled); info.AddValue("FilterColumns", _filterColumns); info.AddValue("IsReturnTypeCollection", _isReturnTypeCollection); info.AddValue("IsUserDefined", _isUserDefined); info.AddValue("Name", _name); info.AddValue("OrderByColumns", _orderByColumns); info.AddValue("Parent", _parent); info.AddValue("UserCustomWhere", _useCustomWhere); info.AddValue("UserOptions", _userOptions); info.AddValue("Description", _description); #endif }
/// <summary> /// Saves the service /// </summary> /// <param name="serviceName">Service name.</param> /// <param name="service">Service.</param> /// <param name="path">Path.</param> /// <returns>The filename of the persisted service.</returns> private static String SaveService(string serviceName, IService service, string path) { var serviceFileName = path + Constants.ServiceSaveString + serviceName; using (var serviceFile = File.Create(serviceFileName, Constants.BufferSize, FileOptions.SequentialScan)) { var serviceWriter = new SerializationWriter(serviceFile); serviceWriter.Write(serviceName); serviceWriter.Write(service.PluginName); service.Save(serviceWriter); serviceWriter.UpdateHeader(); serviceWriter.Flush(); serviceFile.Flush(); } return(Path.GetFileName(serviceFileName)); }
public void WriteToStream(Stream s) { SerializationWriter sw = new SerializationWriter(s); //sw.Write(checksum); sw.Write(time); sw.Write(id); sw.Write(count300); sw.Write(count100); sw.Write(count50); sw.Write(countGeki); sw.Write(countKatu); sw.Write(countMiss); sw.Write(totalScore); sw.Write(maxCombo); sw.Write(currentCombo); sw.Write(perfect); sw.Write((byte)(pass ? currentHp : 254)); }
/// <summary> /// Saves the index. /// </summary> /// <returns> The filename of the persisted index. </returns> /// <param name='indexName'> Index name. </param> /// <param name='index'> Index. </param> /// <param name='path'> Path. </param> private static String SaveIndex(string indexName, IIndex index, string path) { var indexFileName = path + Constants.IndexSaveString + indexName; using (var indexFile = File.Create(indexFileName, Constants.BufferSize, FileOptions.SequentialScan)) { var indexWriter = new SerializationWriter(indexFile); indexWriter.Write(indexName); indexWriter.Write(index.PluginName); index.Save(indexWriter); indexWriter.UpdateHeader(); indexWriter.Flush(); indexFile.Flush(); } return(Path.GetFileName(indexFileName)); }
public void WriteToStream(SerializationWriter w) { w.Write(Artist); if (_version >= OsuVersions.FirstOsz2) { w.Write(ArtistUnicode); } w.Write(Title); if (_version >= OsuVersions.FirstOsz2) { w.Write(TitleUnicode); } w.Write(Creator); w.Write(Version); w.Write(AudioFileName); w.Write(BeatmapChecksum); w.Write(BeatmapFileName); w.Write((byte)RankedStatus); w.Write(CountHitCircles); w.Write(CountSliders); w.Write(CountSpinners); w.Write(LastModifiedTime); if (_version >= OsuVersions.FloatDifficultyValues) { w.Write(ApproachRate); w.Write(CircleSize); w.Write(HPDrainRate); w.Write(OveralDifficulty); } else { w.Write(ApproachRate); w.Write(CircleSize); w.Write(HPDrainRate); w.Write(OveralDifficulty); } w.Write(SliderVelocity); if (_version >= OsuVersions.FloatDifficultyValues) {
public override void GetObjectData(SerializationInfo info, StreamingContext context) { #if FAST_SERIALIZATION using (SerializationWriter writer = new SerializationWriter()) { writer.Write(UniqueId); writer.Write(_alias); writer.Write(_enabled); //writer.Write(_exposedUserOptions); writer.Write(Filter.UniqueId); //writer.Write(_foreignColumns); writer.Write(ScriptBase.GetUniqueIds(ForeignColumns)); writer.Write(ForeignRelationship.UniqueId); writer.Write(ForeignScriptObject.UniqueId); writer.Write(_isBase); writer.Write(_isUserDefined); writer.Write(_name); //writer.WriteObject(_parent); //writer.Write(_primaryColumns); writer.Write(ScriptBase.GetUniqueIds(PrimaryColumns)); //writer.WriteObject(_primaryScriptObject); writer.WriteObject(_userOptions); info.AddValue("d", writer.ToArray()); } #else info.AddValue("SerializationVersion", SerializationVersion); info.AddValue("Alias", _alias); info.AddValue("Enabled", _enabled); //info.AddValue("ExposedUserOptions", _exposedUserOptions); info.AddValue("Filter", _filter); info.AddValue("ForeignColumns", _foreignColumns); info.AddValue("ForeignRelationship", _foreignRelationship); info.AddValue("ForeignScriptObject", _foreignScriptObject); info.AddValue("IsBase", _isBase); info.AddValue("IsUserDefined", _isUserDefined); info.AddValue("Name", _name); info.AddValue("Parent", _parent); info.AddValue("PrimaryColumns", _primaryColumns); info.AddValue("PrimaryScriptObject", _primaryScriptObject); info.AddValue("UserOptions", _userOptions); info.AddValue("Description", _description); #endif }
public void WriteToStream(SerializationWriter writer) { writer.Write((short)matchId); writer.Write(inProgress); writer.Write((byte)matchType); writer.Write((uint)activeMods); writer.Write(gameName); writer.Write((SendPassword || gamePassword == null) ? gamePassword : string.Empty); writer.Write(beatmapName); writer.Write(beatmapId); writer.Write(beatmapChecksum); for (var i = 0; i < MaxRoomPlayers; i++) { writer.Write((byte)slotStatus[i]); } for (var j = 0; j < MaxRoomPlayers; j++) { writer.Write((byte)slotTeam[j]); } for (var k = 0; k < MaxRoomPlayers; k++) { if ((slotStatus[k] & SlotStatus.Occupied) > 0) { writer.Write(slotId[k]); } } writer.Write(hostId); writer.Write((byte)playMode); writer.Write((byte)matchScoringType); writer.Write((byte)matchTeamType); writer.Write((byte)specialModes); if ((specialModes & MultiSpecialModes.FreeMod) > MultiSpecialModes.None) { for (var l = 0; l < MaxRoomPlayers; l++) { writer.Write((int)slotMods[l]); } } writer.Write(Seed); }
public void TestBytes() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { byte[] values = new byte[Config.MULTI_TEST_COUNT]; rand.NextBytes(values); for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) sw.Write(values[i]); sw.Flush(); ms.Position = 0; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) Assert.AreEqual(values[i], sr.Read<byte>()); } }
public override RequestStatus GetHistoryOrdersCompressed(int?accountId, DateTime?startDate, out byte[] buffer) { buffer = null; List <MarketOrder> ordlist; var status = GetHistoryOrders(accountId, startDate, out ordlist); if (ordlist == null || ordlist.Count == 0) { return(status); } using (var writer = new SerializationWriter()) { writer.Write(orders); writer.Flush(); buffer = writer.ToArray(); } return(status); }
public void WriteToStream(SerializationWriter writer) { writer.Write(Source.ToString()); writer.Write(Message); var value = Target; if (Target != null) { if (Target.StartsWith("#mp_")) { value = "#multiplayer"; } else if (Target.StartsWith("#spect_")) { value = "#spectator"; } } writer.Write(value); writer.Write(SenderId); }
public void TestBasicDictionary() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { Dictionary<int, float> dict = new Dictionary<int, float>(Config.MULTI_TEST_COUNT); for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) dict[rand.Next(int.MinValue, int.MaxValue)] = (float)rand.NextDouble(); sw.Write(dict); sw.Flush(); ms.Position = 0; Dictionary<int, float> ret = sr.Read<Dictionary<int, float>>(); foreach (KeyValuePair<int, float> kvp in dict) Assert.AreEqual(kvp.Value, ret[kvp.Key]); } }
public void TestBasicArray() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { int[] array = new int[Config.MULTI_TEST_COUNT]; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) array[i] = rand.Next(int.MinValue, int.MaxValue); sw.Write(array); sw.Flush(); ms.Position = 0; int[] ret = sr.Read<int[]>(); for (int i = 0; i < ret.Length; i++) Assert.AreEqual(array[i], ret[i]); } }
public void TestBasicList() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { List<int> list = new List<int>(Config.MULTI_TEST_COUNT); for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) list.Add(rand.Next(int.MinValue, int.MaxValue)); sw.Write(list); sw.Flush(); ms.Position = 0; List<int> ret = sr.Read<List<int>>(); for (int i = 0; i < list.Count; i++) Assert.AreEqual(list[i], ret[i]); } }
public byte[] Serialize() { SerializationWriter writer = new SerializationWriter(); writer.WriteObject(ServerName); writer.WriteObject(Name); if (Type == ObjectTypes.Actor) writer.WriteObject((byte)0); else if (Type == ObjectTypes.Sensor) writer.WriteObject((byte)1); else if (Type == ObjectTypes.Unknown) writer.WriteObject((byte)2); writer.WriteObject(TypeName); writer.WriteObject(Timecode.Ticks); writer.WriteObject(XS1ObjectID); writer.WriteObject(Value); return writer.ToArray(); }
public void TestBools() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { bool[] values = new bool[Config.MULTI_TEST_COUNT]; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) { values[i] = rand.Next(0, 2) == 1; sw.Write(values[i]); } sw.Flush(); ms.Position = 0; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) Assert.AreEqual(values[i], sr.Read<bool>()); } }
public void Serialize(SerializationWriter writer, object value) { Type type = value.GetType(); if (type == typeof(Pair)) Serialize(writer, (Pair) value); else if (type == typeof(Triplet)) Serialize(writer, (Triplet) value); else if (type == typeof(StateBag)) Serialize(writer, (StateBag) value); else if (type == typeof(Unit)) Serialize(writer, (Unit) value); else if (type == typeof(Hashtable)) Serialize(writer, (Hashtable) value); else { throw new InvalidOperationException(string.Format("{0} does not support Type: {1}", GetType(), type)); } }
public void TestDateTimes() { Random rand = new Random(); using (MemoryStream ms = new MemoryStream()) using (SerializationWriter sw = new SerializationWriter(ms)) using (SerializationReader sr = new SerializationReader(ms)) { DateTime[] values = new DateTime[Config.MULTI_TEST_COUNT]; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) { values[i] = new DateTime(rand.Next(1970, 5623), rand.Next(1, 13), rand.Next(1, 29), rand.Next(0, 24), rand.Next(0, 60), rand.Next(0, 60), DateTimeKind.Utc); sw.Write(values[i]); } sw.Flush(); ms.Position = 0; for (int i = 0; i < Config.MULTI_TEST_COUNT; i++) Assert.AreEqual(values[i], sr.Read<DateTime>()); } }
protected virtual void GetObjectData(SerializationWriter sw) { if (IsCompactable) { // OPT: compact all parts before serialization Compact(); } sw.Write(f_TimeStamp); sw.Write(f_MessageParts); sw.Write((Int32) f_MessageType); }
public virtual void Serialize(SerializationWriter writer) { writer.WritePointer(codelets); // info.AddValue("codelets", codelets) }
public void Serialize(SerializationWriter mySerializationWriter, object myObject) { Serialize(ref mySerializationWriter, (DirectoryEntry) myObject); }
private byte[] Serialize(ref SerializationWriter mySerializationWriter, ADBSettingsBase myValue) { #region Write Basics try { if (myValue != null) { mySerializationWriter.WriteString(myValue.Name); mySerializationWriter.WriteString(myValue.Description); mySerializationWriter.WriteObject(myValue.OwnerID); myValue.Type.Serialize(ref mySerializationWriter); mySerializationWriter.WriteObject(myValue.Default.Value); mySerializationWriter.WriteObject(myValue._Value.Value); _isDirty = false; } else { mySerializationWriter.WriteString(Name); mySerializationWriter.WriteString(Description); mySerializationWriter.WriteObject(myValue.OwnerID); myValue.Type.Serialize(ref mySerializationWriter); mySerializationWriter.WriteObject(Default.Value); mySerializationWriter.WriteObject(_Value.Value); } } catch (SerializationException e) { throw new SerializationException(e.Message); } #endregion return mySerializationWriter.ToArray(); }
public override void Serialize(SerializationWriter writer, object value) { Serialize(ref writer, (DBNumber)value); }
private void Serialize(ref SerializationWriter mySerializationWriter, DBNumber myValue) { mySerializationWriter.WriteObject(myValue._Value); }
public override void Serialize(ref SerializationWriter mySerializationWriter) { Serialize(ref mySerializationWriter, this); }
public void Save(SerializationWriter writer) { if (ReadResource()) { try { writer.Write(0);//parameter writer.Write(_idx.Count); foreach (var aKV in _idx) { writer.WriteObject(aKV.Key); writer.Write(aKV.Value.Count); foreach (var aItem in aKV.Value) { writer.Write(aItem.Id); } } } finally { FinishReadResource(); } return; } throw new CollisionException(this); }
public byte[] Serialize() { var _SerializationWriter = new SerializationWriter(); if (StorageURIs == null) _SerializationWriter.WriteUInt32(0); else _SerializationWriter.WriteUInt32((UInt32)StorageURIs.Count); foreach (String uri in StorageURIs) _SerializationWriter.WriteString(uri); _SerializationWriter.WriteString(StorageType); _SerializationWriter.WriteUInt64(StorageSize); return _SerializationWriter.ToArray(); }
private void Serialize(ref SerializationWriter mySerializationWriter, DirectoryEntry myDirectoryEntry) { try { #region Write the InlineData mySerializationWriter.Write(myDirectoryEntry._InlineData); #endregion #region Write the INodePositions mySerializationWriter.WriteUInt32((UInt32)myDirectoryEntry.INodePositions.Count); foreach (var _ExtendedPosition in myDirectoryEntry.INodePositions) { _ExtendedPosition.StorageUUID.Serialize(ref mySerializationWriter); mySerializationWriter.WriteUInt64(_ExtendedPosition.Position); } #endregion #region Write the ObjectStreamsList mySerializationWriter.WriteUInt32((UInt32)myDirectoryEntry.ObjectStreamsList.Count); foreach (var _ObjectStreamType in myDirectoryEntry.ObjectStreamsList) mySerializationWriter.WriteString(_ObjectStreamType); #endregion myDirectoryEntry.isDirty = false; } catch (SerializationException e) { throw new SerializationException(e.Message); } }
public Byte[] Serialize() { SerializationWriter writer = new SerializationWriter(); writer.WriteString(ServiceGlobalUniqueName); writer.WriteString(ServiceUri.ToString()); writer.WriteByte((Byte)ServiceType); return writer.ToArray(); }