Example #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}");
            }
        }
Example #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("}");
 }
Example #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));
 }
Example #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());
         }
 }
Example #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();
        }
Example #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));
        }
Example #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());
            }
Example #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();
        }
Example #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);
            }
        }
Example #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);
 }
Example #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)));
 }
Example #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();
 }
Example #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();
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #29
0
 /// <summary>
 /// Writes the message to the the formatted stream.
 /// </summary>
 public override void WriteMessage(IMessageLite message)
 {
     WriteMessageStart();
     message.WriteTo(this);
     WriteMessageEnd();
 }
Example #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();
     }
 }
Example #32
0
 public void WriteMessageNoTag(IMessageLite value)
 {
     WriteRawVarint32((uint)value.SerializedSize);
     value.WriteTo(this);
 }