BO4ETestProject/TestProtobufSerialization.cs
/// <summary>
/// Serializes <paramref name="protoObject"/> as base64 (protobuf) string and deserializes it again
/// </summary>
/// <param name="protoObject"></param>
/// <typeparam name="TContract"></typeparam>
/// <returns></returns>
Serializes  as base64 (protobuf) string and deserializes it again
Serializes as base64 ( protobuf ) string and deserializes it again
protected static TContract SerializeAsBase64RoundTrip<TContract>(TContract protoObject)
        {
            string base64String;
            using (var stream = new MemoryStream())
            {
                Serializer.Serialize(stream, protoObject);
                using var reader = new BinaryReader(stream);
                base64String = Convert.ToBase64String(stream.ToArray());
            }
            Assert.IsFalse(string.IsNullOrWhiteSpace(base64String));
            TContract deserializedObject;
            using (var backStream = new MemoryStream(Convert.FromBase64String(base64String)))
            {
                backStream.Seek(0, SeekOrigin.Begin);
                deserializedObject = Serializer.Deserialize<TContract>(backStream);
            }
            return deserializedObject;
        }
protected static TContract SerializeAsBase64RoundTrip < TContract > ( TContract protoObject ) { string base64String ; using ( var stream = new MemoryStream ( ) ) { Serializer . Serialize ( stream , protoObject ) ; using var reader = new BinaryReader ( stream ) ; base64String = Convert . ToBase64String ( stream . ToArray ( ) ) ; } Assert . IsFalse ( string . IsNullOrWhiteSpace ( base64String ) ) ; TContract deserializedObject ; using ( var backStream = new MemoryStream ( Convert . FromBase64String ( base64String ) ) ) { backStream . Seek ( 0 , SeekOrigin . Begin ) ; deserializedObject = Serializer . Deserialize < TContract > ( backStream ) ; } return deserializedObject ; }
Serializes  as base64 (protobuf) string and deserializes it again
Serializes as base64 ( protobuf ) string and deserializes it again
// now use base64 string to get back the original
None
protoObject
TContract
None
typeparam
None