Пример #1
0
        public void Example_ReadJsonUsingICodedInputStream()
        {
            TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
            ICodedInputStream      reader  = JsonFormatReader.CreateInstance(@"{""valid"":true}");

            reader.ReadMessageStart();  //manually read the begin the message '{'

            builder.MergeFrom(reader);  //write the message normally

            reader.ReadMessageEnd();    //manually read the end message '}'
        }
Пример #2
0
        public void Example_ReadXmlUsingICodedInputStream()
        {
            TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
            ICodedInputStream      reader  = XmlFormatReader.CreateInstance(@"<root><valid>true</valid></root>");

            reader.ReadMessageStart();  //manually read the begin the message '{'

            builder.MergeFrom(reader);  //read the message normally

            reader.ReadMessageEnd();    //manually read the end message '}'
        }
Пример #3
0
        public void TestXmlReadEmptyRoot()
        {
            TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
            ICodedInputStream      reader  = XmlFormatReader.CreateInstance(@"<root/>");

            reader.ReadMessageStart();  //manually read the begin the message '{'

            builder.MergeFrom(reader);  //write the message normally

            reader.ReadMessageEnd();    //manually read the end message '}'
        }
Пример #4
0
        /// <summary>
        /// Merges the message from the input stream based on the contentType provided
        /// </summary>
        /// <typeparam name="TBuilder">A type derived from IBuilderLite</typeparam>
        /// <param name="builder">An instance of a message builder</param>
        /// <param name="options">Options specific to reading this message and/or content type</param>
        /// <param name="contentType">The mime type of the input stream content</param>
        /// <param name="input">The stream to read the message from</param>
        /// <returns>The same builder instance that was supplied in the builder parameter</returns>
        public static TBuilder MergeFrom <TBuilder>(
#if !NOEXTENSIONS
            this
#endif
            TBuilder builder, MessageFormatOptions options, string contentType, Stream input) where TBuilder : IBuilderLite
        {
            ICodedInputStream codedInput = MessageFormatFactory.CreateInputStream(options, contentType, input);

            codedInput.ReadMessageStart();
            builder.WeakMergeFrom(codedInput, options.ExtensionRegistry);
            codedInput.ReadMessageEnd();
            return(builder);
        }
Пример #5
0
        /// <summary>
        /// Used to implement a service endpoint on an HTTP server.  This works with services generated with the
        /// service_generator_type option set to IRPCDISPATCH.
        /// </summary>
        /// <param name="stub">The service execution stub</param>
        /// <param name="methodName">The name of the method being invoked</param>
        /// <param name="options">optional arguments for the format reader/writer</param>
        /// <param name="contentType">The mime type for the input stream</param>
        /// <param name="input">The input stream</param>
        /// <param name="responseType">The mime type for the output stream</param>
        /// <param name="output">The output stream</param>
        public static void HttpCallMethod(
#if !NOEXTENSIONS
            this
#endif
            IRpcServerStub stub, string methodName, MessageFormatOptions options,
            string contentType, Stream input, string responseType, Stream output)
        {
            ICodedInputStream codedInput = MessageFormatFactory.CreateInputStream(options, contentType, input);

            codedInput.ReadMessageStart();
            IMessageLite response = stub.CallMethod(methodName, codedInput, options.ExtensionRegistry);

            codedInput.ReadMessageEnd();
            WriteTo(response, options, responseType, output);
        }