Browse Source

Added CodedInputStream ctor symmetrical with CodedOutputStream.

Charles Stanhope 15 years ago
parent
commit
ef234da0e3
1 changed files with 14 additions and 5 deletions
  1. 14 5
      src/ProtocolBuffers/CodedInputStream.cs

+ 14 - 5
src/ProtocolBuffers/CodedInputStream.cs

@@ -105,13 +105,22 @@ namespace Google.ProtocolBuffers {
     /// byte array.
     /// </summary>
     public static CodedInputStream CreateInstance(byte[] buf) {
-      return new CodedInputStream(buf);
+      return new CodedInputStream(buf, 0, buf.Length);
     }
 
-    private CodedInputStream(byte[] buffer) {
-      this.buffer = buffer;
-      this.bufferSize = buffer.Length;
-      this.input = null;
+    /// <summary>
+    /// Creates a new CodedInputStream that reads from the given
+    /// byte array slice.
+    /// </summary>
+    public static CodedInputStream CreateInstance(byte[] buf, int offset, int length) {
+        return new CodedInputStream(buf, offset, length);
+    }
+
+    private CodedInputStream(byte[] buffer, int offset, int length) {
+        this.buffer = buffer;
+        this.bufferPos = offset;
+        this.bufferSize = offset + length;
+        this.input = null;
     }
 
     private CodedInputStream(Stream input) {