浏览代码

fix a bunch of bugs

Jan Tattermusch 5 年之前
父节点
当前提交
5fc49bdd5a

+ 1 - 1
csharp/src/Google.Protobuf/CodedOutputStream.cs

@@ -33,6 +33,7 @@
 using Google.Protobuf.Collections;
 using System;
 using System.IO;
+using System.Security;
 using System.Text;
 
 namespace Google.Protobuf
@@ -304,7 +305,6 @@ namespace Google.Protobuf
         public void WriteBytes(ByteString value)
         {
             var span = new Span<byte>(buffer);
-            WritingPrimitives.WriteLength(ref span, ref state, value.Length);
             WritingPrimitives.WriteBytes(ref span, ref state, value);
         }
 

+ 1 - 1
csharp/src/Google.Protobuf/WriteBufferHelper.cs

@@ -47,7 +47,7 @@ namespace Google.Protobuf
         private IBufferWriter<byte> bufferWriter;
         private CodedOutputStream codedOutputStream;
 
-        public CodedOutputStream CodedOutputStream => CodedOutputStream;
+        public CodedOutputStream CodedOutputStream => codedOutputStream;
 
         /// <summary>
         /// Initialize an instance with a coded output stream.

+ 13 - 1
csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs

@@ -67,8 +67,20 @@ namespace Google.Protobuf
         {
             if (message is IBufferMessage bufferMessage)
             {
-                // TODO: actually invoke the method
+                // TODO: actually invoke the InternalWriteTo method!!!!
                 //bufferMessage.InternalWriteTo(ref ctx);
+
+                // TODO: get rid of this code!
+                ctx.CopyStateTo(ctx.state.CodedOutputStream);
+                try
+                {
+                    // fallback parse using the CodedOutputStream that started current serialization tree
+                    message.WriteTo(ctx.state.CodedOutputStream);
+                }
+                finally
+                {
+                    ctx.LoadStateFrom(ctx.state.CodedOutputStream);
+                }
             }
             else
             {