/// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary> public static byte[] SerializeToBytes(UserCharacter instance) { using (var ms = new MemoryStream()) { Serialize(ms, instance); return ms.ToArray(); } }
/// <summary>Helper: Serialize with a varint length prefix</summary> public static void SerializeLengthDelimited(Stream stream, UserCharacter instance) { var data = SerializeToBytes(instance); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, (uint)data.Length); stream.Write(data, 0, data.Length); }
/// <summary>Serialize the instance into the stream</summary> public static void Serialize(Stream stream, UserCharacter instance) { var msField = global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Pop(); if (instance.Name == null) throw new ArgumentNullException("Name", "Required by proto specification."); // Key for field: 1, LengthDelimited stream.WriteByte(10); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Name)); if (instance.UserEmail != null) { // Key for field: 2, LengthDelimited stream.WriteByte(18); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.UserEmail)); } // Key for field: 3, Varint stream.WriteByte(24); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.CharacterClassType); // Key for field: 4, Varint stream.WriteByte(32); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Level); // Key for field: 5, Varint stream.WriteByte(40); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Exp); // Key for field: 6, Varint stream.WriteByte(48); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Gold); // Key for field: 7, Varint stream.WriteByte(56); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.SkillPt); // Key for field: 8, Varint stream.WriteByte(64); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.StatsPt); // Key for field: 9, Varint stream.WriteByte(72); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.StrPt); // Key for field: 10, Varint stream.WriteByte(80); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.AgiPt); // Key for field: 11, Varint stream.WriteByte(88); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.IntPt); // Key for field: 12, Varint stream.WriteByte(96); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.StaPt); global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Push(msField); }
/// <summary>Helper: put the buffer into a MemoryStream and create a new instance to deserializing into</summary> public static UserCharacter Deserialize(byte[] buffer) { UserCharacter instance = new UserCharacter(); using (var ms = new MemoryStream(buffer)) Deserialize(ms, instance); return instance; }
/// <summary>Helper: create a new instance to deserializing into</summary> public static UserCharacter DeserializeLength(Stream stream, int length) { UserCharacter instance = new UserCharacter(); DeserializeLength(stream, length, instance); return instance; }
/// <summary>Helper: create a new instance to deserializing into</summary> public static UserCharacter DeserializeLengthDelimited(Stream stream) { UserCharacter instance = new UserCharacter(); DeserializeLengthDelimited(stream, instance); return instance; }
/// <summary>Helper: create a new instance to deserializing into</summary> public static UserCharacter Deserialize(Stream stream) { UserCharacter instance = new UserCharacter(); Deserialize(stream, instance); return instance; }