コード例 #1
0
 /// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary>
 public static byte[] SerializeToBytes(PlayerReference instance)
 {
     using (var ms = new MemoryStream())
     {
         Serialize(ms, instance);
         return(ms.ToArray());
     }
 }
コード例 #2
0
        /// <summary>Helper: put the buffer into a MemoryStream and create a new instance to deserializing into</summary>
        public static PlayerReference Deserialize(byte[] buffer)
        {
            PlayerReference instance = new PlayerReference();

            using (var ms = new MemoryStream(buffer))
                Deserialize(ms, instance);
            return(instance);
        }
コード例 #3
0
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, PlayerReference instance)
        {
            var msField = global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Pop();

            // Key for field: 1, Varint
            stream.WriteByte(8);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream, instance.ID);
            if (instance.DisplayName == null)
            {
                throw new ArgumentNullException("DisplayName", "Required by proto specification.");
            }
            // Key for field: 2, LengthDelimited
            stream.WriteByte(18);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.DisplayName));
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Push(msField);
        }