浏览代码

address review comments

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

+ 2 - 2
csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs

@@ -463,7 +463,7 @@ namespace Google.Protobuf
             Assert.IsTrue(memoryStream.CanWrite);
             using (var cos = new CodedOutputStream(memoryStream))
             {
-                cos.WriteRawByte(0);
+                cos.WriteRawBytes(new byte[] {0});
                 Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
             }
             Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
@@ -477,7 +477,7 @@ namespace Google.Protobuf
             Assert.IsTrue(memoryStream.CanWrite);
             using (var cos = new CodedOutputStream(memoryStream, true))
             {
-                cos.WriteRawByte(0);
+                cos.WriteRawBytes(new byte[] {0});
                 Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
             }
             Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream

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

@@ -517,18 +517,6 @@ namespace Google.Protobuf
             WritingPrimitives.WriteRawLittleEndian64(ref span, ref state, value);
         }
 
-        internal void WriteRawByte(byte value)
-        {
-            var span = new Span<byte>(buffer);
-            WritingPrimitives.WriteRawByte(ref span, ref state, value);
-        }
-
-        internal void WriteRawByte(uint value)
-        {
-            var span = new Span<byte>(buffer);
-            WritingPrimitives.WriteRawByte(ref span, ref state, value);
-        }
-
         /// <summary>
         /// Writes out an array of bytes.
         /// </summary>

+ 2 - 0
csharp/src/Google.Protobuf/MessageExtensions.cs

@@ -151,6 +151,7 @@ namespace Google.Protobuf
         /// </summary>
         /// <param name="message">The message to write to the stream.</param>
         /// <param name="output">The stream to write to.</param>
+        [SecuritySafeCritical]
         public static void WriteTo(this IMessage message, IBufferWriter<byte> output)
         {
             ProtoPreconditions.CheckNotNull(message, nameof(message));
@@ -170,6 +171,7 @@ namespace Google.Protobuf
         /// </summary>
         /// <param name="message">The message to write to the stream.</param>
         /// <param name="output">The span to write to. Size must match size of the message exactly.</param>
+        [SecuritySafeCritical]
         public static void WriteTo(this IMessage message, Span<byte> output)
         {
             ProtoPreconditions.CheckNotNull(message, nameof(message));

+ 0 - 6
csharp/src/Google.Protobuf/WritingPrimitives.cs

@@ -391,12 +391,6 @@ namespace Google.Protobuf
             buffer[state.position++] = value;
         }
 
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static void WriteRawByte(ref Span<byte> buffer, ref WriterInternalState state, uint value)
-        {
-            WriteRawByte(ref buffer, ref state, (byte)value);
-        }
-
         /// <summary>
         /// Writes out an array of bytes.
         /// </summary>