示例#1
0
        private static void SendRequest(IMessageLite request)
        {
            try
            {
                if (!_socket.Connected)
                {
                    return;
                }
                var size   = request.SerializedSize;
                var header = new byte[4];
                header[0] = (byte)((size >> 24) & 0xFF);
                header[1] = (byte)((size >> 16) & 0xFF);
                header[2] = (byte)((size >> 8) & 0xFF);
                header[3] = (byte)(size & 0xFF);

                var headerSize = header.Length;
                _stream.Write(header, 0, headerSize);
                request.WriteTo(_stream);
                _stream.Flush();

                // Enable reply message if needed (debugging only).
                //var reply = ReceiveReply();
                //Console.WriteLine($@"Reply: {reply.ToString()}");
            }
            catch (Exception ex)
            {
                Notifications.Error($"Failed to send request.{ex.Message}");
            }
        }
示例#2
0
        private static void SendRequest(IMessageLite request)
        {
            try
            {
                if (!_socket.Connected)
                {
                    return;
                }
                var size   = request.SerializedSize;
                var header = new byte[4];
                header[0] = (byte)((size >> 24) & 0xFF);
                header[1] = (byte)((size >> 16) & 0xFF);
                header[2] = (byte)((size >> 8) & 0xFF);
                header[3] = (byte)(size & 0xFF);

                var headerSize = header.Length;
                _stream.Write(header, 0, headerSize);
                request.WriteTo(_stream);
                _stream.Flush();

                // Enable reply message if needed (debugging only)
                //HyperionReply reply = ReceiveReply();
                //Logger("Reply: " + reply.ToString());
            }
            catch (Exception) {
            }
        }
 public void WriteMessage(int fieldNumber, string fieldName, IMessageLite value)
 {
     output.WriteLine("{0}: {{", fieldName);
     output.Indent();
     value.WriteTo(this);
     output.Outdent();
     output.WriteLine("}");
 }
示例#4
0
 uint writePB(IMessageLite pbMsg, byte errorCode = 0)
 {
     byte[] bytes;
     using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
         pbMsg.WriteTo(stream);
         bytes = stream.ToArray();
     }
     return(writePB(bytes, errorCode));
 }
示例#5
0
 public uint writePB(IMessageLite pbMsg)
 {
     byte[] bytes;
     using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
         pbMsg.WriteTo(stream);
         bytes = stream.ToArray();
     }
     return(writePB(bytes));
 }
 private byte[] Compress(IMessageLite message)
 {
     using (var bos = new MemoryStream(BufferSize))
     using (var gzipStream = new GZipStream(bos, CompressionMode.Compress))
     {
         message.WriteTo(gzipStream);
         gzipStream.Close();
         return bos.ToArray();
     }
 }
 /// <summary>
 /// Compresses the protobuf message using GZIP compression
 /// </summary>
 /// <param name="message">The message to compress</param>
 /// <returns>A byte array containing the compressed message</returns>
 public byte[] Compress(IMessageLite message)
 {
     using (var bos = new MemoryStream(BufferSize))
         using (var gzipStream = new GZipStream(bos, CompressionMode.Compress))
         {
             message.WriteTo(gzipStream);
             gzipStream.Dispose();
             return(bos.ToArray());
         }
 }
示例#8
0
 private byte[] Compress(IMessageLite proto)
 {
     using (var memStream = new MemoryStream(BufferSize))
         using (var gzip = new GZipStream(memStream, CompressionLevel.Fastest))
         {
             proto.WriteTo(gzip);
             gzip.Flush();
             memStream.Position = 0;
             return(memStream.ToArray());
         }
 }
        /// <summary>
        /// Writes a message
        /// </summary>
        protected override void WriteMessageOrGroup(string field, IMessageLite message)
        {
            _output.WriteStartElement(field);

            if (TestOption(XmlWriterOptions.OutputJsonTypes))
            {
                _output.WriteAttributeString("type", "object");
            }

            message.WriteTo(this);
            _output.WriteEndElement();
        }
示例#10
0
        uint writePB(IMessageLite pbMsg, byte errorCode = 0)
        {
            Debug.Log("WritePB: " + pbMsg);
            //byte[] bytes;

            /*
             *          using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
             *                  pbMsg.WriteTo (stream);
             *                  bytes = stream.ToArray ();
             *          }
             */
            simpleMemoryStream.Reset();
            //CodedOutputStream coutStream = CodedOutputStream.CreateInstance(simpleMemoryStream);
            pbMsg.WriteTo(coutStream);
            coutStream.Flush();
            return(writePB(simpleMemoryStream, errorCode));
        }
示例#11
0
            public TMessage CallMethod <TMessage, TBuilder>(string method, IMessageLite request, IBuilderLite <TMessage, TBuilder> response)
                where TMessage : IMessageLite <TMessage, TBuilder>
                where TBuilder : IBuilderLite <TMessage, TBuilder>
            {
                Stream            stream = new MemoryStream();
                CodedOutputStream output = CodedOutputStream.CreateInstance(stream);

                output.WriteStringNoTag(method);
                request.WriteTo(output);
                output.Flush();

                stream.Position = 0;
                stream          = _channel.Invoke(stream);
                CodedInputStream input = CodedInputStream.CreateInstance(stream);

                response.MergeFrom(input);
                return(response.Build());
            }
示例#12
0
        /// <summary>
        /// Writes the message instance to the stream using the content type provided
        /// </summary>
        /// <param name="message">An instance of a message</param>
        /// <param name="options">Options specific to writing this message and/or content type</param>
        /// <param name="contentType">The mime type of the content to be written</param>
        /// <param name="output">The stream to write the message to</param>
        public static void WriteTo(
#if !NOEXTENSIONS
            this
#endif
            IMessageLite message, MessageFormatOptions options, string contentType, Stream output)
        {
            ICodedOutputStream codedOutput = MessageFormatFactory.CreateOutputStream(options, contentType, output);

            // Output the appropriate message preamble
            codedOutput.WriteMessageStart();

            // Write the message content to the output
            message.WriteTo(codedOutput);

            // Write the closing message fragment
            codedOutput.WriteMessageEnd();
            codedOutput.Flush();
        }
示例#13
0
        private void SendRequest(IMessageLite request)
        {
            var size   = request.SerializedSize;
            var header = new byte[4];

            header[0] = (byte)((size >> 24) & 0xFF);
            header[1] = (byte)((size >> 16) & 0xFF);
            header[2] = (byte)((size >> 8) & 0xFF);
            header[3] = (byte)(size & 0xFF);

            var headerSize = header.Length;

            _stream.Write(header, 0, headerSize);
            request.WriteTo(_stream);
            _stream.Flush();

            // Enable reply message if needed (debugging only).
            //var reply = ReceiveReply();
            //Console.WriteLine($@"Reply: {reply.ToString()}");
        }
        protected virtual void OnExecute(IClientContext client, Stream input, Stream output)
        {
            RpcRequestHeader requestHeader = RpcRequestHeader.DefaultInstance;

            RpcResponseHeader.Builder responseHeader = RpcResponseHeader.CreateBuilder();
            try
            {
                requestHeader = RpcRequestHeader.ParseDelimitedFrom(input, ExtensionRegistry);
                responseHeader.SetMessageId(requestHeader.MessageId);

                IMessageLite responseBody = OnExecute(client, requestHeader, CodedInputStream.CreateInstance(input),
                                                      responseHeader);

                responseHeader.Build().WriteDelimitedTo(output);
                responseBody.WriteTo(output);
            }
            catch (Exception ex)
            {
                OnException(requestHeader, responseHeader, ex);
                responseHeader.Build().WriteDelimitedTo(output);
            }
        }
示例#15
0
        protected virtual void CallService(RpcRequestHeader requestHeader, IMessageLite requestBody,
                                           out RpcResponseHeader responseHeader, out Stream responseBody)
        {
            byte[] requestBytes;
            using (MemoryStream input = new MemoryStream(1024))
            {
                requestHeader.WriteDelimitedTo(input);
                requestBody.WriteTo(input);
                requestBytes = input.ToArray();
            }

            Stream output = Execute(requestBytes);

            try
            {
                responseHeader = RpcResponseHeader.ParseDelimitedFrom(output, ExtensionRegistry);
                responseBody   = output;
            }
            catch
            {
                output.Dispose();
                throw;
            }
        }
 /// <summary>
 /// Writes a group field value, without a tag, to the stream.
 /// </summary>
 public void WriteGroupNoTag(IMessageLite value) {
   value.WriteTo(this);
 }
 /// <summary>
 /// Writes the message to the the formatted stream.
 /// </summary>
 public override void WriteMessage(IMessageLite message)
 {
     message.WriteTo(this);
 }
 public void WriteMessageNoTag(IMessageLite value) {
   WriteRawVarint32((uint)value.SerializedSize);
   value.WriteTo(this);
 }
示例#19
0
 /// <summary>
 /// Outputs a textual representation of the Protocol Message supplied into
 /// the parameter output.
 /// </summary>
 public static void Print(IMessageLite message, TextWriter output)
 {
     message.WriteTo(CodedTextOutputStream.CreateInstance(new TextGenerator(output)));
 }
示例#20
0
 /// <summary>
 /// Writes a message as an element with the given name
 /// </summary>
 public void WriteMessage(string elementName, IMessageLite message)
 {
     WriteMessageStart(elementName);
     message.WriteTo(this);
     WriteMessageEnd();
 }
示例#21
0
 /// <summary>
 /// Writes the message to the the formatted stream.
 /// </summary>
 public override void WriteMessage(IMessageLite message)
 {
     message.WriteTo(this);
 }
 /// <summary>
 /// Writes the message to the the formatted stream.
 /// </summary>
 public override void WriteMessage(IMessageLite message)
 {
     WriteMessageStart();
     message.WriteTo(this);
     WriteMessageEnd();
 }
 /// <summary>
 /// Writes a message as an element with the given name
 /// </summary>
 public void WriteMessage(string elementName, IMessageLite message)
 {
     WriteMessageStart(elementName);
     message.WriteTo(this);
     WriteMessageEnd();
 }
示例#24
0
 /// <summary>
 /// Writes a group field value, including tag, to the stream.
 /// </summary>
 public void WriteGroup(int fieldNumber, string fieldName, IMessageLite value)
 {
     WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
     value.WriteTo(this);
     WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
 }
示例#25
0
 public void WriteMessage(int fieldNumber, string fieldName, IMessageLite value)
 {
     WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
     WriteRawVarint32((uint)value.SerializedSize);
     value.WriteTo(this);
 }
 public void WriteUnknownGroup(int fieldNumber, IMessageLite value) {
   WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
   value.WriteTo(this);
   WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
 }
示例#27
0
 /// <summary>
 /// Writes a group field value, without a tag, to the stream.
 /// </summary>
 public void WriteGroupNoTag(IMessageLite value)
 {
     value.WriteTo(this);
 }
 public void WriteMessage(int fieldNumber, IMessageLite value) {
   WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
   WriteRawVarint32((uint)value.SerializedSize);
   value.WriteTo(this);
 }
示例#29
0
 /// <summary>
 /// Writes the message to the the formatted stream.
 /// </summary>
 public override void WriteMessage(IMessageLite message)
 {
     WriteMessageStart();
     message.WriteTo(this);
     WriteMessageEnd();
 }
示例#30
0
        /// <summary>
        /// Writes a message
        /// </summary>
        protected override void WriteMessageOrGroup(string field, IMessageLite message)
        {
            _output.WriteStartElement(field);

            if (TestOption(XmlWriterOptions.OutputJsonTypes))
            {
                _output.WriteAttributeString("type", "object");
            }

            message.WriteTo(this);
            _output.WriteEndElement();
        }
 private byte[] Compress(IMessageLite proto)
 {
     using (var memStream = new MemoryStream(BufferSize))
     using (var gzip = new GZipStream(memStream, CompressionLevel.Fastest))
     {
         proto.WriteTo(gzip);
         gzip.Flush();
         memStream.Position = 0;
         return memStream.ToArray();
     }
 }
示例#32
0
 public void WriteMessageNoTag(IMessageLite value)
 {
     WriteRawVarint32((uint)value.SerializedSize);
     value.WriteTo(this);
 }