Browse Source

make everything build, with some TODOs

Jan Tattermusch 5 years ago
parent
commit
d3eddf7e2d

+ 4 - 0
csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs

@@ -228,6 +228,10 @@ namespace Google.Protobuf
               }
             }
           }
+
+          void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+            // TODO: implement this, add tests!!!
+          }
         }
     }
 }

+ 23 - 0
csharp/src/Google.Protobuf/CodedOutputStream.cs

@@ -280,6 +280,29 @@ namespace Google.Protobuf
             }
         }
 
+        /// <summary>
+        /// Writes a message, without a tag, to the stream.
+        /// Only the message data is written, without a length-delimiter.
+        /// </summary>
+        /// <param name="value">The value to write</param>
+        public void WriteRawMessage(IMessage value)
+        {
+            // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method),
+            // what we're doing here works fine, but could be more efficient.
+            // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it).
+            var span = new Span<byte>(buffer);
+            WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
+            try
+            {
+                // TODO: fix fix fix
+                WritingPrimitivesMessages.WriteMessage(ref ctx, value);
+            }
+            finally
+            {
+                ctx.CopyStateTo(this);
+            }
+        }
+
         /// <summary>
         /// Writes a group, without a tag, to the stream.
         /// </summary>

+ 9 - 2
csharp/src/Google.Protobuf/Collections/MapField.cs

@@ -740,8 +740,15 @@ namespace Google.Protobuf.Collections
 
                 public void WriteTo(CodedOutputStream output)
                 {
-                    codec.keyCodec.WriteTagAndValue(output, Key);
-                    codec.valueCodec.WriteTagAndValue(output, Value);
+                    // Message adapter is an internal class and we know that all the writing will happen via InternalWriteTo.
+                    throw new NotImplementedException();
+                }
+
+                [SecuritySafeCritical]
+                public void InternalWriteTo(ref WriteContext ctx)
+                {
+                    codec.keyCodec.WriteTagAndValue(ref ctx, Key);
+                    codec.valueCodec.WriteTagAndValue(ref ctx, Value);
                 }
 
                 public int CalculateSize()

+ 7 - 1
csharp/src/Google.Protobuf/IBufferMessage.cs

@@ -35,7 +35,7 @@ namespace Google.Protobuf
 #if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY
     /// <summary>
     /// Interface for a Protocol Buffers message, supporting
-    /// parsing from <see cref="ParseContext"/>.
+    /// parsing from <see cref="ParseContext"/> and writing to <see cref="WriteContext"/>.
     /// </summary>
     public interface IBufferMessage : IMessage
     {
@@ -44,6 +44,12 @@ namespace Google.Protobuf
         /// Users should never invoke this method directly.
         /// </summary>        
         void InternalMergeFrom(ref ParseContext ctx);
+
+        /// <summary>
+        /// Internal implementation of writing this message to a given write context.
+        /// Users should never invoke this method directly.
+        /// </summary>        
+        void InternalWriteTo(ref WriteContext ctx);
     }
 #endif
 }