Example #1
0
        public static void Write(Stream stream, byte type, Stream exportStream)
        {
            stream.WriteByte(type);
            stream.Write(NetworkConverter.GetBytes((int)exportStream.Length), 0, 4);

            byte[] buffer = null;

            try
            {

                buffer = _bufferManager.TakeBuffer(1024 * 4);
                int length = 0;

                while ((length = exportStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    stream.Write(buffer, 0, length);
                }
            }
            finally
            {
                if (buffer != null)
                {
                    _bufferManager.ReturnBuffer(buffer);
                }
            }
        }
Example #2
0
	public void EndMessage(Stream stream)
	{
		SDebug.Assert(message != RemoteMessage.Invalid);

		// Write message header
		stream.WriteByte((byte)message);
		uint len = (uint)packet.Length;
		stream.WriteByte((byte)(len & 0xFF));
		stream.WriteByte((byte)((len >> 8) & 0xFF));
		stream.WriteByte((byte)((len >> 16) & 0xFF));
		stream.WriteByte((byte)((len >> 24) & 0xFF));

		// Write the message
		packet.Position = 0;
		Utils.CopyToStream(packet, stream, buffer, (int)packet.Length);

		message = RemoteMessage.Invalid;
	}
 public static bool WriteBeyondEndTest(Stream s)
 {
     Console.WriteLine("Write Beyond End test on "+s.GetType().Name);
     FileStream fs = s as FileStream;
     if (fs != null)
         Console.WriteLine("FileStream type is: "+(fs.IsAsync ? "asynchronous" : "synchronous"));
     long origLength = s.Length;        
     byte[] bytes = new byte[10];
     for(int i=0; i<bytes.Length; i++)
         bytes[i] = (byte) i;
     int spanPastEnd = 5;
     s.Seek(spanPastEnd, SeekOrigin.End);
     if (s.Position != s.Length + spanPastEnd)
         throw new Exception("Position is incorrect!  Seek(5, SeekOrigin.End) should leave us at s.Length + spanPastEnd ("+(s.Length + spanPastEnd)+"), but got: "+s.Position);
     Console.WriteLine("Original Length: "+origLength);
     s.Write(bytes, 0, bytes.Length);
     long pos = s.Position;
     if (pos != origLength + spanPastEnd + bytes.Length)
         throw new Exception(String.Format("After asynchronously writing beyond end of the stream, position is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     if (s.Length != origLength + spanPastEnd + bytes.Length)
         throw new Exception(String.Format("After asynchronously writing beyond end of the stream, Length is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     WritePastEndHelper(s, bytes, origLength, spanPastEnd, false);
     origLength = s.Length;
     s.Position = s.Length + spanPastEnd;
     s.WriteByte(0x42);
     long expected = origLength + spanPastEnd + 1;
     if (s.Position != expected)
     {
         iCountErrors++ ;
         throw new Exception("After WriteByte, Position was wrong!  got: "+s.Position+"  expected: "+expected);
     }
     if (s.Length != expected)
     {
         iCountErrors++ ;
         throw new Exception("After WriteByte, Length was wrong!  got: "+s.Length+"  expected: "+expected);
     }
     origLength = s.Length;
     s.Position = s.Length + spanPastEnd;
     IAsyncResult ar = s.BeginWrite(bytes, 0, bytes.Length, null, null);
     s.EndWrite(ar);
     pos = s.Position;
     if (pos != origLength + spanPastEnd + bytes.Length) 
     {
         iCountErrors++ ;
         throw new Exception(String.Format("After writing beyond end of the stream, position is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     }
     if (s.Length != origLength + spanPastEnd + bytes.Length) 
     {
         iCountErrors++;
         throw new Exception(String.Format("After writing beyond end of the stream, Length is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     }
     WritePastEndHelper(s, bytes, origLength, spanPastEnd, true);
     return true;
 }
Example #4
0
 public static void ByteTest(Stream s) 
 {
     Console.WriteLine("  (01)  ByteTest on "+s.GetType( ).Name);
     int		size	= 0x25000;
     int		r;
     for(int i=0;i<size;i++)			s.WriteByte((byte)i);
     s.Position=0;
     for(int i=0;i<size;i++) 
     {
         r=s.ReadByte( );
         if(r!=i%256)
             throw new Exception("Didn't get the correct value for i at: "
                 +i+"  expected: "+(i%256)+"  got: "+r);
     }
 }
Example #5
0
 public static void SpanTest(Stream s) 
 {
     Console.WriteLine("  (02)  SpanTest on "+s.GetType( ).Name);
     //	If a read request spans across two buffers, make sure we get the data
     //	back in one read request, since it would be silly to not do so. This 
     //	caught a bug in BufferedStream, which was missing a case to handle the
     //	second read request.
     //	Here's a legend.  The space is at the 8K buffer boundary.
     //	/-------------------|------- -------|------------------\ 
     //	First for loop 	  Read(bytes)	 Second for loop
     int			max;
     int			r;
     byte[]		bytes;
     int			numBytes;
     const int	bufferSize	= 8*(1<<10);
     for(int i=0;i<bufferSize*2;i++)			s.WriteByte((byte)(i % 256));
     s.Position=0;
     max = bufferSize-(bufferSize>>2);
     for(int i=0;i<max;i++) 
     {
         r=s.ReadByte( );
         if(r!=i%256)
             throw new Exception("Didn't get the correct value for i at: "
                 +i+"  expected: "+(i%256)+"  got: "+r);
     }
     bytes = new byte[bufferSize>>1];
     numBytes=s.Read(bytes,0,bytes.Length);
     if (numBytes!=bytes.Length)
         throw new Exception("While reading into a byte[] spanning a buffer starting at position "
             +max+", didn't get the right number of bytes!  asked for: "
             +bytes.Length+"  got: "+numBytes);
     for(int i=0;i<bytes.Length;i++) 
     {
         if(bytes[i]!=((i+max)%256))
             throw new Exception("When reading in an array that spans across two buffers, "+
                 "got an incorrect value at index: "+i+
                 "  expected: "+((i+max)%256)+"  got: "+bytes[i]);
     }
     //	Read rest of data
     for(int i=0;i<max;i++) 
     {
         r=s.ReadByte( );
         if(r!=(i+max+bytes.Length)%256)
             throw new Exception("While reading the last part of the buffer, "
                 +"didn't get the correct value for i at: "+i
                 +"  expected: "+((i+max+bytes.Length)%256)+"  got: "+r);
     }
 }
    public CompressedOutputStream(Stream baseStream, CompressionType compressionType)
    {
        _baseStream = baseStream;
        _compressionType = compressionType;

        _baseStream.WriteByte((byte)_compressionType);

        switch (_compressionType)
        {
        case CompressionType.NONE:
            _compressor = _baseStream;
            break;
        case CompressionType.LZF:
            _compressor = new LzfOutputStream(_baseStream);
            break;
        case CompressionType.BZIP2:
            _compressor = new BZip2OutputStream(_baseStream);
            break;
        }
    }
Example #7
0
        public static void Write(Stream stream, byte type, string value)
        {
            Encoding encoding = _threadLocalEncoding.Value;

            byte[] buffer = null;

            try
            {
                buffer = _bufferManager.TakeBuffer(encoding.GetMaxByteCount(value.Length));
                var length = encoding.GetBytes(value, 0, value.Length, buffer, 0);

                stream.WriteByte(type);
                stream.Write(NetworkConverter.GetBytes(length), 0, 4);
                stream.Write(buffer, 0, length);
            }
            finally
            {
                if (buffer != null)
                {
                    _bufferManager.ReturnBuffer(buffer);
                }
            }
        }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, TheirMessage instance)
 {
     // Key for field: 1, Varint
     stream.WriteByte(8);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldA);
 }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, ExternalStruct instance)
 {
     BinaryWriter bw = new BinaryWriter(stream);
     // Key for field: 1, Fixed64
     stream.WriteByte(9);
     bw.Write(instance.X);
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, EnumDescriptorProto instance)
        {
            if (instance.Name != null)
            {
                // Key for field: 1, LengthDelimited
                stream.WriteByte(10);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Name));
            }
            if (instance.Value != null)
            {
                foreach (var i2 in instance.Value)
                {
                    // Key for field: 2, LengthDelimited
                    stream.WriteByte(18);
                    using (var ms2 = new MemoryStream())
                    {
                        Google.protobuf.EnumValueDescriptorProto.Serialize(ms2, i2);
                        // Length delimited byte array
                        uint ms2Length = (uint)ms2.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);
                        stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
                    }

                }
            }
            if (instance.Options != null)
            {
                // Key for field: 3, LengthDelimited
                stream.WriteByte(26);
                using (var ms3 = new MemoryStream())
                {
                    Google.protobuf.EnumOptions.Serialize(ms3, instance.Options);
                    // Length delimited byte array
                    uint ms3Length = (uint)ms3.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms3Length);
                    stream.Write(ms3.GetBuffer(), 0, (int)ms3Length);
                }

            }
        }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, MyMessage instance)
 {
     // Key for field: 1, Varint
     stream.WriteByte(8);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Foo);
     if (instance.Bar != null)
     {
         // Key for field: 2, LengthDelimited
         stream.WriteByte(18);
         global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Bar));
     }
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, MethodDescriptorProto instance)
        {
            if (instance.Name != null)
            {
                // Key for field: 1, LengthDelimited
                stream.WriteByte(10);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Name));
            }
            if (instance.InputType != null)
            {
                // Key for field: 2, LengthDelimited
                stream.WriteByte(18);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.InputType));
            }
            if (instance.OutputType != null)
            {
                // Key for field: 3, LengthDelimited
                stream.WriteByte(26);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.OutputType));
            }
            if (instance.Options != null)
            {
                // Key for field: 4, LengthDelimited
                stream.WriteByte(34);
                using (var ms4 = new MemoryStream())
                {
                    Google.protobuf.MethodOptions.Serialize(ms4, instance.Options);
                    // Length delimited byte array
                    uint ms4Length = (uint)ms4.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms4Length);
                    stream.Write(ms4.GetBuffer(), 0, (int)ms4Length);
                }

            }
        }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, FileOptions instance)
        {
            if (instance.JavaPackage != null)
            {
                // Key for field: 1, LengthDelimited
                stream.WriteByte(10);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.JavaPackage));
            }
            if (instance.JavaOuterClassname != null)
            {
                // Key for field: 8, LengthDelimited
                stream.WriteByte(66);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.JavaOuterClassname));
            }
            // Key for field: 10, Varint
            stream.WriteByte(80);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.JavaMultipleFiles);
            // Key for field: 20, Varint
            stream.Write(new byte[]{160, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.JavaGenerateEqualsAndHash);
            if (instance.OptimizeFor != OptimizeMode.SPEED)
            {
                // Key for field: 9, Varint
                stream.WriteByte(72);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.OptimizeFor);
            }
            if (instance.GoPackage != null)
            {
                // Key for field: 11, LengthDelimited
                stream.WriteByte(90);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.GoPackage));
            }
            // Key for field: 16, Varint
            stream.Write(new byte[]{128, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.CcGenericServices);
            // Key for field: 17, Varint
            stream.Write(new byte[]{136, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.JavaGenericServices);
            // Key for field: 18, Varint
            stream.Write(new byte[]{144, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.PyGenericServices);
            if (instance.UninterpretedOption != null)
            {
                foreach (var i999 in instance.UninterpretedOption)
                {
                    // Key for field: 999, LengthDelimited
                    stream.Write(new byte[]{186, 62}, 0, 2);
                    using (var ms999 = new MemoryStream())
                    {
                        Google.protobuf.UninterpretedOption.Serialize(ms999, i999);
                        // Length delimited byte array
                        uint ms999Length = (uint)ms999.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms999Length);
                        stream.Write(ms999.GetBuffer(), 0, (int)ms999Length);
                    }

                }
            }
        }
Example #14
0
 public static bool ReadWriteBufferSwitchTest(Stream s) 
 {
     String	writableStr		= "read-only";
     if(s.CanWrite)
         writableStr="read/write";
     Console.WriteLine("  (05)  ReadWriteBufferSwitch test for a "+writableStr+" "+s.GetType( ).Name);
     if(s.Length<8200)		
         Console.WriteLine("ReadWriteBufferSwitchTest assumes stream len is at least 8200");
     s.Position = 0;
     //	Assume buffer size is 8192
     for(int i=0;i<8192;i++)		s.ReadByte( );
     //		Console.WriteLine("  (05)  Pos: "+s.Position+"  s.Length: "+s.Length);
     s.WriteByte(0);
     //	Calling the position property will verify internal buffer state.
     if(8193!=s.Position)
         throw new Exception("Position should be 8193!  Position: "+s.Position);
     s.ReadByte( );
     return true;
 }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, MyMessageV1 instance)
 {
     // Key for field: 1, Varint
     stream.WriteByte(8);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldA);
     if (instance.PreservedFields != null)
     {
         foreach (var kv in instance.PreservedFields)
         {
             global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteKey(stream, kv.Key);
             stream.Write(kv.Value, 0, kv.Value.Length);
         }
     }
 }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, ExtensionRange instance)
 {
     // Key for field: 1, Varint
     stream.WriteByte(8);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Start);
     // Key for field: 2, Varint
     stream.WriteByte(16);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.End);
 }
        /// <summary>Serialize the instance into the stream</summary>
        internal static void Serialize(Stream stream, LocalFeatures instance)
        {
            instance.BeforeSerialize();

            BinaryWriter bw = new BinaryWriter(stream);
            // Key for field: 1, Varint
            stream.WriteByte(8);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Uptime.Ticks);
            // Key for field: 2, Varint
            stream.WriteByte(16);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.DueDate.Ticks);
            // Key for field: 3, Fixed64
            stream.WriteByte(25);
            bw.Write(instance.Amount);
            if (instance.Denial != null)
            {
                // Key for field: 4, LengthDelimited
                stream.WriteByte(34);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Denial));
            }
            if (instance.Secret != null)
            {
                // Key for field: 5, LengthDelimited
                stream.WriteByte(42);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Secret));
            }
            if (instance.Internal != null)
            {
                // Key for field: 6, LengthDelimited
                stream.WriteByte(50);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Internal));
            }
            if (instance.PR != null)
            {
                // Key for field: 7, LengthDelimited
                stream.WriteByte(58);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.PR));
            }
            if (instance.TestingReadOnly != null)
            {
                // Key for field: 8, LengthDelimited
                stream.WriteByte(66);
                using (var ms8 = new MemoryStream())
                {
                    Mine.MyMessageV1.Serialize(ms8, instance.TestingReadOnly);
                    // Length delimited byte array
                    uint ms8Length = (uint)ms8.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms8Length);
                    stream.Write(ms8.GetBuffer(), 0, (int)ms8Length);
                }

            }
            if (instance.MyInterface == null)
                throw new ArgumentNullException("MyInterface", "Required by proto specification.");
            // Key for field: 9, LengthDelimited
            stream.WriteByte(74);
            using (var ms9 = new MemoryStream())
            {
                LocalFeatureTest.InterfaceTestSerializer.Serialize(ms9, instance.MyInterface);
                // Length delimited byte array
                uint ms9Length = (uint)ms9.Length;
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms9Length);
                stream.Write(ms9.GetBuffer(), 0, (int)ms9Length);
            }

            // Key for field: 10, LengthDelimited
            stream.WriteByte(82);
            using (var ms10 = new MemoryStream())
            {
                LocalFeatureTest.StructTest.Serialize(ms10, instance.MyStruct);
                // Length delimited byte array
                uint ms10Length = (uint)ms10.Length;
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms10Length);
                stream.Write(ms10.GetBuffer(), 0, (int)ms10Length);
            }

            // Key for field: 11, LengthDelimited
            stream.WriteByte(90);
            using (var ms11 = new MemoryStream())
            {
                TestB.ExternalStructSerializer.Serialize(ms11, instance.MyExtStruct);
                // Length delimited byte array
                uint ms11Length = (uint)ms11.Length;
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms11Length);
                stream.Write(ms11.GetBuffer(), 0, (int)ms11Length);
            }

            if (instance.MyExtClass != null)
            {
                // Key for field: 12, LengthDelimited
                stream.WriteByte(98);
                using (var ms12 = new MemoryStream())
                {
                    TestB.ExternalClassSerializer.Serialize(ms12, instance.MyExtClass);
                    // Length delimited byte array
                    uint ms12Length = (uint)ms12.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms12Length);
                    stream.Write(ms12.GetBuffer(), 0, (int)ms12Length);
                }

            }
            // Key for field: 13, Varint
            stream.WriteByte(104);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.MyEnum);
        }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, NamePart instance)
 {
     if (instance.NamePartField == null)
         throw new ArgumentNullException("NamePartField", "Required by proto specification.");
     // Key for field: 1, LengthDelimited
     stream.WriteByte(10);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.NamePartField));
     // Key for field: 2, Varint
     stream.WriteByte(16);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.IsExtension);
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, UninterpretedOption instance)
        {
            BinaryWriter bw = new BinaryWriter(stream);
            if (instance.Name != null)
            {
                foreach (var i2 in instance.Name)
                {
                    // Key for field: 2, LengthDelimited
                    stream.WriteByte(18);
                    using (var ms2 = new MemoryStream())
                    {
                        Google.protobuf.UninterpretedOption.NamePart.Serialize(ms2, i2);
                        // Length delimited byte array
                        uint ms2Length = (uint)ms2.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);
                        stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
                    }

                }
            }
            if (instance.IdentifierValue != null)
            {
                // Key for field: 3, LengthDelimited
                stream.WriteByte(26);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.IdentifierValue));
            }
            // Key for field: 4, Varint
            stream.WriteByte(32);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream, instance.PositiveIntValue);
            // Key for field: 5, Varint
            stream.WriteByte(40);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.NegativeIntValue);
            // Key for field: 6, Fixed64
            stream.WriteByte(49);
            bw.Write(instance.DoubleValue);
            if (instance.StringValue != null)
            {
                // Key for field: 7, LengthDelimited
                stream.WriteByte(58);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, instance.StringValue);
            }
            if (instance.AggregateValue != null)
            {
                // Key for field: 8, LengthDelimited
                stream.WriteByte(66);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.AggregateValue));
            }
        }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, Location instance)
 {
     if (instance.Path != null)
     {
         // Key for field: 1, LengthDelimited
         stream.WriteByte(10);
         using (var ms1 = new MemoryStream())
         {
             foreach (var i1 in instance.Path)
             {
                 global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(ms1,(ulong)i1);
             }
             // Length delimited byte array
             uint ms1Length = (uint)ms1.Length;
             global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms1Length);
             stream.Write(ms1.GetBuffer(), 0, (int)ms1Length);
         }
     }
     if (instance.Span != null)
     {
         // Key for field: 2, LengthDelimited
         stream.WriteByte(18);
         using (var ms2 = new MemoryStream())
         {
             foreach (var i2 in instance.Span)
             {
                 global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(ms2,(ulong)i2);
             }
             // Length delimited byte array
             uint ms2Length = (uint)ms2.Length;
             global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);
             stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
         }
     }
     if (instance.LeadingComments != null)
     {
         // Key for field: 3, LengthDelimited
         stream.WriteByte(26);
         global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.LeadingComments));
     }
     if (instance.TrailingComments != null)
     {
         // Key for field: 4, LengthDelimited
         stream.WriteByte(34);
         global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.TrailingComments));
     }
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, SourceCodeInfo instance)
        {
            if (instance.LocationField != null)
            {
                foreach (var i1 in instance.LocationField)
                {
                    // Key for field: 1, LengthDelimited
                    stream.WriteByte(10);
                    using (var ms1 = new MemoryStream())
                    {
                        Google.protobuf.SourceCodeInfo.Location.Serialize(ms1, i1);
                        // Length delimited byte array
                        uint ms1Length = (uint)ms1.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms1Length);
                        stream.Write(ms1.GetBuffer(), 0, (int)ms1Length);
                    }

                }
            }
        }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, MyMessageV2 instance)
        {
            BinaryWriter bw = new BinaryWriter(stream);
            // Key for field: 1, Varint
            stream.WriteByte(8);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldA);
            // Key for field: 2, Fixed64
            stream.WriteByte(17);
            bw.Write(instance.FieldB);
            // Key for field: 3, Fixed32
            stream.WriteByte(29);
            bw.Write(instance.FieldC);
            // Key for field: 4, Varint
            stream.WriteByte(32);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldD);
            // Key for field: 5, Varint
            stream.WriteByte(40);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldE);
            // Key for field: 6, Varint
            stream.WriteByte(48);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, instance.FieldF);
            // Key for field: 7, Varint
            stream.WriteByte(56);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream, instance.FieldG);
            // Key for field: 8, Varint
            stream.WriteByte(64);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteZInt32(stream, instance.FieldH);
            // Key for field: 9, Varint
            stream.WriteByte(72);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteZInt64(stream, instance.FieldI);
            // Key for field: 10, Fixed32
            stream.WriteByte(85);
            bw.Write(instance.FieldJ);
            // Key for field: 11, Fixed64
            stream.WriteByte(89);
            bw.Write(instance.FieldK);
            // Key for field: 12, Fixed32
            stream.WriteByte(101);
            bw.Write(instance.FieldL);
            // Key for field: 13, Fixed64
            stream.WriteByte(105);
            bw.Write(instance.FieldM);
            // Key for field: 14, Varint
            stream.WriteByte(112);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.FieldN);
            if (instance.FieldO == null)
                throw new ArgumentNullException("FieldO", "Required by proto specification.");
            // Key for field: 15, LengthDelimited
            stream.WriteByte(122);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.FieldO));
            if (instance.FieldP == null)
                throw new ArgumentNullException("FieldP", "Required by proto specification.");
            // Key for field: 16, LengthDelimited
            stream.Write(new byte[]{130, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, instance.FieldP);
            // Key for field: 17, Varint
            stream.Write(new byte[]{136, 1}, 0, 2);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldQ);
            if (instance.FieldR != MyEnum.ETest2)
            {
                // Key for field: 18, Varint
                stream.Write(new byte[]{144, 1}, 0, 2);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.FieldR);
            }
            if (instance.Dummy != null)
            {
                // Key for field: 19, LengthDelimited
                stream.Write(new byte[]{154, 1}, 0, 2);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Dummy));
            }
            if (instance.FieldT != null)
            {
                // Key for field: 20, LengthDelimited
                stream.Write(new byte[]{162, 1}, 0, 2);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, 4u * (uint)instance.FieldT.Count);
                foreach (var i20 in instance.FieldT)
                {
                    bw.Write(i20);
                }
            }
            if (instance.FieldS != null)
            {
                foreach (var i21 in instance.FieldS)
                {
                    // Key for field: 21, Varint
                    stream.Write(new byte[]{168, 1}, 0, 2);
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, i21);
                }
            }
            if (instance.FieldU != null)
            {
                // Key for field: 22, LengthDelimited
                stream.Write(new byte[]{178, 1}, 0, 2);
                using (var ms22 = new MemoryStream())
                {
                    Theirs.TheirMessage.Serialize(ms22, instance.FieldU);
                    // Length delimited byte array
                    uint ms22Length = (uint)ms22.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms22Length);
                    stream.Write(ms22.GetBuffer(), 0, (int)ms22Length);
                }

            }
            if (instance.FieldV != null)
            {
                foreach (var i23 in instance.FieldV)
                {
                    // Key for field: 23, LengthDelimited
                    stream.Write(new byte[]{186, 1}, 0, 2);
                    using (var ms23 = new MemoryStream())
                    {
                        Theirs.TheirMessage.Serialize(ms23, i23);
                        // Length delimited byte array
                        uint ms23Length = (uint)ms23.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms23Length);
                        stream.Write(ms23.GetBuffer(), 0, (int)ms23Length);
                    }

                }
            }
        }
Example #23
0
        public static async Task StreamTest(Stream stream, Boolean fSuppress)
        {

            string strValue;
            int iValue;

            //[] We will first use the stream's 2 writing methods
            int iLength = 1 << 10;
            stream.Seek(0, SeekOrigin.Begin);

            for (int i = 0; i < iLength; i++)
                stream.WriteByte((byte)i);

            byte[] btArr = new byte[iLength];
            for (int i = 0; i < iLength; i++)
                btArr[i] = (byte)i;
            stream.Write(btArr, 0, iLength);

            //we will write many things here using a binary writer
            BinaryWriter bw1 = new BinaryWriter(stream);
            bw1.Write(false);
            bw1.Write(true);

            for (int i = 0; i < 10; i++)
            {
                bw1.Write((byte)i);
                bw1.Write((sbyte)i);
                bw1.Write((short)i);
                bw1.Write((char)i);
                bw1.Write((UInt16)i);
                bw1.Write(i);
                bw1.Write((uint)i);
                bw1.Write((Int64)i);
                bw1.Write((ulong)i);
                bw1.Write((float)i);
                bw1.Write((double)i);
            }

            //Some strings, chars and Bytes
            char[] chArr = new char[iLength];
            for (int i = 0; i < iLength; i++)
                chArr[i] = (char)i;

            bw1.Write(chArr);
            bw1.Write(chArr, 512, 512);

            bw1.Write(new string(chArr));
            bw1.Write(new string(chArr));

            //[] we will now read
            stream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < iLength; i++)
            {
                Assert.Equal(i % 256, stream.ReadByte());
            }


            btArr = new byte[iLength];
            stream.Read(btArr, 0, iLength);
            for (int i = 0; i < iLength; i++)
            {
                Assert.Equal((byte)i, btArr[i]);
            }

            //Now, for the binary reader
            BinaryReader br1 = new BinaryReader(stream);

            Assert.False(br1.ReadBoolean());
            Assert.True(br1.ReadBoolean());

            for (int i = 0; i < 10; i++)
            {
                Assert.Equal( (byte)i, br1.ReadByte());
                Assert.Equal((sbyte)i, br1.ReadSByte());
                Assert.Equal((short)i, br1.ReadInt16());
                Assert.Equal((char)i, br1.ReadChar());
                Assert.Equal((UInt16)i, br1.ReadUInt16());
                Assert.Equal(i, br1.ReadInt32());
                Assert.Equal((uint)i, br1.ReadUInt32());
                Assert.Equal((Int64)i, br1.ReadInt64());
                Assert.Equal((ulong)i, br1.ReadUInt64());
                Assert.Equal((float)i, br1.ReadSingle());
                Assert.Equal((double)i, br1.ReadDouble());
            }

            chArr = br1.ReadChars(iLength);
            for (int i = 0; i < iLength; i++)
            {
                Assert.Equal((char)i, chArr[i]);
            }

            chArr = new char[512];
            chArr = br1.ReadChars(iLength / 2);
            for (int i = 0; i < iLength / 2; i++)
            {
                Assert.Equal((char)(iLength / 2 + i), chArr[i]);
            }

            chArr = new char[iLength];
            for (int i = 0; i < iLength; i++)
                chArr[i] = (char)i;
            strValue = br1.ReadString();
            Assert.Equal(new string(chArr), strValue);

            strValue = br1.ReadString();
            Assert.Equal(new string(chArr), strValue);

            stream.Seek(1, SeekOrigin.Current); // In the original test, success here would end the test

            //[] we will do some async tests here now
            stream.Position = 0;

            btArr = new byte[iLength];
            for (int i = 0; i < iLength; i++)
                btArr[i] = (byte)(i + 5);

            await stream.WriteAsync(btArr, 0, btArr.Length);

            stream.Position = 0;
            for (int i = 0; i < iLength; i++)
            {
                Assert.Equal((byte)(i + 5), stream.ReadByte());
            }

            //we will read asynchronously
            stream.Position = 0;

            byte[] compArr = new byte[iLength];

            iValue = await stream.ReadAsync(compArr, 0, compArr.Length);

            Assert.Equal(btArr.Length, iValue);

            for (int i = 0; i < iLength; i++)
            {
                Assert.Equal(compArr[i], btArr[i]);
            }
        }
Example #24
0
 public static void WriteData(Stream s) 
 {
     BinaryWriter	bw;
     int				offset	= 10;
     byte[]			bytes	= new byte[256 + offset];
     for (int i=0;i<256;i++)		bytes[i+offset] = (byte)i;
     //	Test reading & writing at an offset into the user array...
     s.Write(bytes,offset,bytes.Length-offset);
     //	Test WriteByte methods.
     s.WriteByte(0);
     s.WriteByte(65);
     s.WriteByte(255);
     s.Flush( );
     bw = new BinaryWriter(s);
     for(int i=0;i<1000;i++)								bw.Write(i);
     bw.Write(false);
     bw.Write(true);
     for(char ch='A';ch<='Z';ch++)						bw.Write(ch);
     for(short i=-32000;i<=32000;i+=1000)				bw.Write(i);
     for(int i=-2000000000;i<=2000000000;i+=100000000)	bw.Write(i);
     bw.Write(0x0123456789ABCDE7L);
     bw.Write(0x7EDCBA9876543210L);
     bw.Write("Hello world");
     bw.Write(Math.PI);
     bw.Write((float)(-2.0*Math.PI));
     bw.Flush( );
 }
Example #25
0
 public static bool CanPropertiesTest(Stream s) 
 {
     Console.WriteLine("  (06)  Can-Properties Test on "+s.GetType( ).Name);
     byte[]			bytes				= new byte[1];
     int				bytesTransferred;
     IAsyncResult	asyncResult;
     if(s.CanRead) 
     {			//	Ensure all Read methods work, if CanRead is true.
         int		n	= s.ReadByte( );
         if(n==-1)
             throw new Exception("On a readable stream, ReadByte returned -1...");
         bytesTransferred=s.Read(bytes,0,1);
         if(bytesTransferred!=1)
             throw new Exception("Read(byte[],0,1) should have returned 1!  got: "+bytesTransferred);
         asyncResult=s.BeginRead(bytes,0,1,null,null);									/*	BeginRead	*/ 
         bytesTransferred=s.EndRead(asyncResult);										/*	EndRead		*/ 
         if(bytesTransferred!=1)
             throw new Exception("BeginRead(byte[],0,1) should have returned 1!  got: "
                 +bytesTransferred);
     }						//	End of (s.CanRead) Block
     else 
     {					//	Begin of (!s.CanRead) Block
         try 
         {
             s.ReadByte( );
             throw new Exception("ReadByte on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.Read(bytes,0,1);
             throw new Exception("Read(bytes,0,1) on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.BeginRead(bytes,0,1,null,null);											/*	BeginRead	*/ 
             throw new Exception("BeginRead on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
     }						//	End of (!s.CanRead) Block
     if(s.CanWrite) 
     {		//	Ensure write methods work if CanWrite returns true.
         s.WriteByte(0);
         s.Write(bytes,0,1);
         asyncResult = s.BeginWrite(bytes,0,1,null,null);								/*	BeginWrite	*/ 
         s.EndWrite(asyncResult);														/*	EndWrite	*/ 
     }						//	End of (s.CanWrite) Block
     else 
     {					//	Begin of (!s.CanWrite) Block
         try 
         {
             s.WriteByte(2);
             throw new Exception("WriteByte on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.Write(bytes,0,1);
             throw new Exception("Write(bytes,0,1) on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.BeginWrite(bytes,0,1,null,null);											/*	BeginWrite	*/ 
             throw new Exception("BeginWrite on an unreadable stream should have thrown!");
         }
         catch(NotSupportedException)	{	}
     }						//	End of (!s.CanWrite) Block
     if(s.CanSeek) 
     {			//	Ensure length-related methods work if CanSeek returns true
         long	n	= s.Length;
         n=s.Position;
         if(s.Position>s.Length)
             throw new Exception("Position is beyond the length of the stream!");
         s.Position=0;
         s.Position=s.Length;
         if(s.Position!=s.Seek(0,SeekOrigin.Current))
             throw new Exception("s.Position!=s.Seek(0,SeekOrigin.Current)");
         if(s.CanWrite)		//	Verify you can set the length, if it's writable.
             s.SetLength(s.Length);
     }						//	End of (s.CanSeek) Block
     else 
     {					//	Begin of (!s.CanSeek) Block
         try 
         {
             s.Position=5;
             throw new Exception("set_Position should throw on a non-seekable stream!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             long	n	= s.Position;
             throw new Exception("get_Position should throw on a non-seekable stream!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             long	n	= s.Length;
             throw new Exception("get_Length should throw on a non-seekable stream!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.SetLength(1);
             throw new Exception("SetLength should throw on a non-seekable stream!");
         }
         catch(NotSupportedException)	{	}
         try 
         {
             s.Seek(0,SeekOrigin.Current);
             throw new Exception("Seek should throw on a non-seekable stream!");
         }
         catch(NotSupportedException)	{	}
     }						//	End of (!s.CanSeek) Block
     return true;
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, DescriptorProto instance)
        {
            if (instance.Name != null)
            {
                // Key for field: 1, LengthDelimited
                stream.WriteByte(10);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.Name));
            }
            if (instance.Field != null)
            {
                foreach (var i2 in instance.Field)
                {
                    // Key for field: 2, LengthDelimited
                    stream.WriteByte(18);
                    using (var ms2 = new MemoryStream())
                    {
                        Google.protobuf.FieldDescriptorProto.Serialize(ms2, i2);
                        // Length delimited byte array
                        uint ms2Length = (uint)ms2.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);
                        stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
                    }

                }
            }
            if (instance.Extension != null)
            {
                foreach (var i6 in instance.Extension)
                {
                    // Key for field: 6, LengthDelimited
                    stream.WriteByte(50);
                    using (var ms6 = new MemoryStream())
                    {
                        Google.protobuf.FieldDescriptorProto.Serialize(ms6, i6);
                        // Length delimited byte array
                        uint ms6Length = (uint)ms6.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms6Length);
                        stream.Write(ms6.GetBuffer(), 0, (int)ms6Length);
                    }

                }
            }
            if (instance.NestedType != null)
            {
                foreach (var i3 in instance.NestedType)
                {
                    // Key for field: 3, LengthDelimited
                    stream.WriteByte(26);
                    using (var ms3 = new MemoryStream())
                    {
                        Google.protobuf.DescriptorProto.Serialize(ms3, i3);
                        // Length delimited byte array
                        uint ms3Length = (uint)ms3.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms3Length);
                        stream.Write(ms3.GetBuffer(), 0, (int)ms3Length);
                    }

                }
            }
            if (instance.EnumType != null)
            {
                foreach (var i4 in instance.EnumType)
                {
                    // Key for field: 4, LengthDelimited
                    stream.WriteByte(34);
                    using (var ms4 = new MemoryStream())
                    {
                        Google.protobuf.EnumDescriptorProto.Serialize(ms4, i4);
                        // Length delimited byte array
                        uint ms4Length = (uint)ms4.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms4Length);
                        stream.Write(ms4.GetBuffer(), 0, (int)ms4Length);
                    }

                }
            }
            if (instance.ExtensionRangeField != null)
            {
                foreach (var i5 in instance.ExtensionRangeField)
                {
                    // Key for field: 5, LengthDelimited
                    stream.WriteByte(42);
                    using (var ms5 = new MemoryStream())
                    {
                        Google.protobuf.DescriptorProto.ExtensionRange.Serialize(ms5, i5);
                        // Length delimited byte array
                        uint ms5Length = (uint)ms5.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms5Length);
                        stream.Write(ms5.GetBuffer(), 0, (int)ms5Length);
                    }

                }
            }
            if (instance.Options != null)
            {
                // Key for field: 7, LengthDelimited
                stream.WriteByte(58);
                using (var ms7 = new MemoryStream())
                {
                    Google.protobuf.MessageOptions.Serialize(ms7, instance.Options);
                    // Length delimited byte array
                    uint ms7Length = (uint)ms7.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms7Length);
                    stream.Write(ms7.GetBuffer(), 0, (int)ms7Length);
                }

            }
        }
 /// <summary>Serialize the instance into the stream</summary>
 public static void Serialize(Stream stream, Data instance)
 {
     BinaryWriter bw = new BinaryWriter(stream);
     // Key for field: 1, Fixed64
     stream.WriteByte(9);
     bw.Write(instance.Somefield);
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, MessageOptions instance)
        {
            // Key for field: 1, Varint
            stream.WriteByte(8);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.MessageSetWireFormat);
            // Key for field: 2, Varint
            stream.WriteByte(16);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.NoStandardDescriptorAccessor);
            if (instance.UninterpretedOption != null)
            {
                foreach (var i999 in instance.UninterpretedOption)
                {
                    // Key for field: 999, LengthDelimited
                    stream.Write(new byte[]{186, 62}, 0, 2);
                    using (var ms999 = new MemoryStream())
                    {
                        Google.protobuf.UninterpretedOption.Serialize(ms999, i999);
                        // Length delimited byte array
                        uint ms999Length = (uint)ms999.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms999Length);
                        stream.Write(ms999.GetBuffer(), 0, (int)ms999Length);
                    }

                }
            }
        }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, Container instance)
        {
            if (instance.MyNestedMessage != null)
            {
                // Key for field: 1, LengthDelimited
                stream.WriteByte(10);
                using (var ms1 = new MemoryStream())
                {
                    Proto.test.Container.Nested.Serialize(ms1, instance.MyNestedMessage);
                    // Length delimited byte array
                    uint ms1Length = (uint)ms1.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms1Length);
                    stream.Write(ms1.GetBuffer(), 0, (int)ms1Length);
                }

            }
            if (instance.NestedField != null)
            {
                // Key for field: 2, LengthDelimited
                stream.WriteByte(18);
                using (var ms2 = new MemoryStream())
                {
                    Proto.test.Container.Nested.Serialize(ms2, instance.NestedField);
                    // Length delimited byte array
                    uint ms2Length = (uint)ms2.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);
                    stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
                }

            }
        }
            /// <summary>Serialize the instance into the stream</summary>
            public static void Serialize(Stream stream, Nested instance)
            {
                if (instance.NestedData != null)
                {
                    // Key for field: 1, LengthDelimited
                    stream.WriteByte(10);
                    using (var ms1 = new MemoryStream())
                    {
                        Proto.test.Data.Serialize(ms1, instance.NestedData);
                        // Length delimited byte array
                        uint ms1Length = (uint)ms1.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms1Length);
                        stream.Write(ms1.GetBuffer(), 0, (int)ms1Length);
                    }

                }
            }