예제 #1
0
        public void SerializesPickeDocString()
        {
            var pickleDocSring = new PickleDocString
            {
                Location = new Location
                {
                    Line   = 10,
                    Column = 20
                },
                ContentType = "text/plain",
                Content     = "some\ncontent\n"
            };

            byte[] serializedBytes;
            using (MemoryStream stream = new MemoryStream())
            {
                var codedOutputStream = new Google.Protobuf.CodedOutputStream(stream);
                codedOutputStream.WriteMessage(pickleDocSring);
                codedOutputStream.Flush();
                serializedBytes = stream.ToArray();
            }

            PickleDocString parsedCopy = PickleDocString.Parser.ParseDelimitedFrom(new MemoryStream(serializedBytes));

            Assert.Equal(pickleDocSring, parsedCopy);
        }
        public async Task <bool> PublishUpdate(PollSummary summary)
        {
            var pollId = summary.Poll?.Id;

            if (pollId == null || pollId == "")
            {
                return(false);
            }


            var memoryStream = new MemoryStream();

            using (var outputStream = new Google.Protobuf.CodedOutputStream(memoryStream))
            {
                summary.WriteTo(outputStream);
            }



            var summaryData = System.Convert.ToBase64String(memoryStream.ToArray());

            var receivers = await _subscriber.PublishAsync(GetRedisChannel(pollId), summaryData);

            _logger.LogDebug($"Publishing update to {receivers} receivers");
            return(true);
        }
예제 #3
0
        public void SendMsg(string routeKey, CatMessage message, string queueName = "Cat.IM.Chat")
        {
            if (string.IsNullOrWhiteSpace(routeKey))
            {
                _logger.LogInformation($"用户[{message.Chat.Info.Receiver}]不在线!");

                return;
            }

            _channel.QueueDeclare(queueName, true, false, false, null);

            _channel.QueueBind(queueName, ExchangeName, routeKey);

            var basicProperties = _channel.CreateBasicProperties();

            basicProperties.DeliveryMode = 2;

            var address = new PublicationAddress(ExchangeType.Topic, ExchangeName, routeKey);

            byte[] buffer = null;

            using (var memoryStream = new MemoryStream())
            {
                using (var output = new Google.Protobuf.CodedOutputStream(memoryStream))
                {
                    message.WriteTo(output);
                }

                buffer = memoryStream.ToArray();
            }

            _channel.BasicPublish(address, basicProperties, buffer);
        }
        public async Task <bool> UpsertPollSummary(PollSummary summary)
        {
            try
            {
                var memoryStream = new MemoryStream();
                using (var outputStream = new Google.Protobuf.CodedOutputStream(memoryStream))
                {
                    summary.WriteTo(outputStream);
                }


                var summaryData = memoryStream.ToArray();

                var pollId = summary.Poll?.Id;
                if (pollId == null || pollId == "")
                {
                    return(false);
                }

                var response = await _database.HashSetAsync(PollSummaryHashKey, pollId, summaryData, When.Always);

                var didPublish = await _pubSub.PublishUpdate(summary);

                return(didPublish);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while poll summary to database");
                return(false);
            }
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public ProtoMemory(byte[] data)
 {
     mDataBuffer = data;
     //position = 0;
     outputStream = new Google.Protobuf.CodedOutputStream(mDataBuffer);
     inputStream  = new Google.Protobuf.CodedInputStream(mDataBuffer);
 }
예제 #6
0
        //private int position = 0;
        #endregion ...Variables...

        #region ... Events     ...

        #endregion ...Events...

        #region ... Constructor...
        /// <summary>
        ///
        /// </summary>
        /// <param name="size"></param>
        public ProtoMemory(int size)
        {
            mDataBuffer = new byte[size];
            //position = 0;
            outputStream = new Google.Protobuf.CodedOutputStream(mDataBuffer);
            inputStream  = new Google.Protobuf.CodedInputStream(mDataBuffer);
        }
예제 #7
0
        public bool SendPacket(Proto.MsgId msgId, Google.Protobuf.IMessage msg)
        {
            if (_state != NetworkState.Connected)
            {
                return(false);
            }

            int size = 0;

            if (msg != null)
            {
                size = msg.CalculateSize();
            }

            if (msgId != Proto.MsgId.MiPing)
            {
                UnityEngine.Debug.Log("send msg. msg_id:" + msgId + " msg size:" + size);
            }

            var          byteStream = new MemoryStream();
            BinaryWriter bw         = new BinaryWriter(byteStream);
            var          totalLen   = size + PacketHead.HeadSize;

            bw.Write((ushort)totalLen);     // total size
            bw.Write((ushort)2);            // head size
            bw.Write((ushort)msgId);

            if (msg != null)
            {
                Google.Protobuf.CodedOutputStream outStream = new Google.Protobuf.CodedOutputStream(byteStream);
                msg.WriteTo(outStream);
                outStream.Flush();
            }

            Byte[] buf = byteStream.ToArray();
            size = size + PacketHead.HeadSize;

            try
            {
                int pos = 0;
                while (size > 0)
                {
                    int sent = _sock.Send(buf, pos, size, SocketFlags.None);
                    size -= sent;
                    pos  += sent;
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError(ex.Message);
                Disconnect();
                return(false);
            }

            return(true);
        }
예제 #8
0
        public static byte[] Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var decompressed = Conversion.DecompressBody(req.Body);

            if (decompressed != null)
            {
                Initialize();

                var readrequest = ReadRequest.Parser.ParseFrom(decompressed);

                log.LogMetric("querycount", readrequest.Queries.Count, new Dictionary <String, object>()
                {
                    { "type", "count" }
                });

                ReadResponse response = CreateResponse(readrequest, log);

                log.LogMetric("result", response.Results.Count, new Dictionary <String, object>()
                {
                    { "type", "count" }
                });
                log.LogMetric("timeseriesread", response.Results.Select(_ => _.Timeseries.Count).Sum(__ => __), new Dictionary <String, object>()
                {
                    { "type", "count" }
                });

                MemoryStream ms = new MemoryStream();
                Google.Protobuf.CodedOutputStream output = new Google.Protobuf.CodedOutputStream(ms);
                response.WriteTo(output);

                output.Flush();

                var resultUncompressed = ms.ToArray();

                if (resultUncompressed.Length > 0)
                {
                    //should be at least the size of the uncompressed one
                    byte[] resultCompressed = new byte[resultUncompressed.Length * 2];

                    var compressedSize = compressor.Compress(resultUncompressed, 0, resultUncompressed.Length, resultCompressed);

                    Array.Resize(ref resultCompressed, compressedSize);

                    return(resultCompressed);
                }
                else
                {
                    return(resultUncompressed);
                }
            }

            return(null);
        }
예제 #9
0
 async public Task send(Google.Protobuf.WellKnownTypes.Any any)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         Google.Protobuf.CodedOutputStream s = new Google.Protobuf.CodedOutputStream(stream);
         any.WriteTo(s);
         s.Flush();
         ArraySegment <byte> buffer = new ArraySegment <byte>(stream.ToArray());
         await client.SendAsync(buffer, WebSocketMessageType.Binary, true, cancelActionToken);
     }
 }
예제 #10
0
 static byte[] GetByteArray(User person)
 {
     using (var ms = new MemoryStream())
     {
         using (Google.Protobuf.CodedOutputStream output = new Google.Protobuf.CodedOutputStream(ms))
         {
             person.WriteTo(output);
         }
         return(ms.ToArray());
     }
 }
예제 #11
0
        public static byte[] SerializeProtoBuf3 <T>(T data) where T : Google.Protobuf.IMessage
        {
            using (MemoryStream rawOutput = new MemoryStream())
            {
                Google.Protobuf.CodedOutputStream output = new Google.Protobuf.CodedOutputStream(rawOutput);
                //output.WriteRawVarint32((uint)len);
                output.WriteMessage(data);
                output.Flush();
                byte[] result = rawOutput.ToArray();

                return(result);
            }
        }
예제 #12
0
        public byte[] SerializeMessage()
        {
            var mmstream = new MemoryStream(this.Message.CalculateSize());
            var stream   = new Google.Protobuf.CodedOutputStream(mmstream);

            this.Message.WriteTo(stream);
            System.Console.WriteLine($"len: {mmstream.CanRead}, {mmstream.CanWrite}, {mmstream.Capacity}, {this.Message.CalculateSize()}, {mmstream.GetBuffer()}");
            // read from stream
            var byteArray = mmstream.GetBuffer();

            // dispose after use
            stream.Dispose();
            // return byteArr;
            return(byteArray);
        }
예제 #13
0
        public void SendSayHelloRequest(string host, int port, string sender, int count)
        {
            try
            {
                var descriptor = Greeter.Descriptor;
                Console.WriteLine(descriptor);

                //build channel
                var channel = new Channel(host, port, ChannelCredentials.Insecure);

                //build client
                var client = new Greeter.GreeterClient(channel);

                //build request
                var request = new HelloRequest {
                    Name = sender + "-" + count, Surname = "abcdefg", Address = "aaaa"
                };
                //request to array
                var req_output_stream = new Google.Protobuf.CodedOutputStream(data);
                request.WriteTo(req_output_stream);
                //parse array to request
                len = req_output_stream.Position;
                var req = new byte[len];
                Array.Copy(data, req, len);
                var parsed_request = HelloRequest.Parser.ParseFrom(req);

                Console.WriteLine($"Sending[{count}]: Size={request.CalculateSize()}, StreamSize={req_output_stream.Position}/{req_output_stream.SpaceLeft}, ToString={request}, Parsed={parsed_request}");

                //send request
                var reply = client.SayHello(request);


                //response to array
                var rep_output_stream = new Google.Protobuf.CodedOutputStream(data);
                reply.WriteTo(rep_output_stream);
                //parse array to response
                len = rep_output_stream.Position;
                var rep = new byte[len];
                Array.Copy(data, rep, len);
                var parsed_reply = GetTestReplyFromArray(rep);

                Console.WriteLine($"Reply[{count}]: Size={reply.CalculateSize()}, StreamSize={rep_output_stream.Position}/{rep_output_stream.SpaceLeft}, ToString={reply}, Parsed={parsed_reply}");
            }
            catch (Exception ex)
            {
                Console.WriteLine("XXX | sending error: " + ex);
            }
        }
예제 #14
0
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
            HttpRequest req,
            ILogger log)
        {
            var decompressed = HttpConversion.DecompressBody(req.Body);
            if (decompressed != null)
            {
                InitializeKustoClient(log);

                var readRequest = ReadRequest.Parser.ParseFrom(decompressed);
                log.LogMetric("querycount", readRequest.Queries.Count,
                    new Dictionary<string, object>() { { "type", "count" } });

                var response = CreateResponse(readRequest, log);

                log.LogMetric("result", response.Results.Count, new Dictionary<string, object>() { { "type", "count" } });
                log.LogMetric("timeseriesread", response.Results.Select(_ => _.Timeseries.Count).Sum(__ => __),
                    new Dictionary<string, object>() { { "type", "count" } });

                var ms = new MemoryStream();
                var output = new Google.Protobuf.CodedOutputStream(ms);
                response.WriteTo(output);

                output.Flush();

                var resultUncompressed = ms.ToArray();

                if (resultUncompressed.Length > 0)
                {
                    // Should be at least the size of the uncompressed one
                    byte[] resultCompressed = new byte[resultUncompressed.Length * 2];

                    var compressedSize = Compressor.Compress(resultUncompressed, 0, resultUncompressed.Length,
                        resultCompressed);

                    Array.Resize(ref resultCompressed, compressedSize);

                    return new FileContentResult(resultCompressed, "application/x-protobuf");
                }
                else
                {
                    return new FileContentResult(resultUncompressed, "application/x-protobuf");
                }
            }

            return null;
        } // - function Read
예제 #15
0
        /// <summary>
        ///
        /// </summary>
        public void Reset()
        {
            if (outputStream != null)
            {
                outputStream.Dispose();
            }

            if (inputStream != null)
            {
                inputStream.Dispose();
            }

            outputStream = new Google.Protobuf.CodedOutputStream(mDataBuffer);
            inputStream  = new Google.Protobuf.CodedInputStream(mDataBuffer);
            mDataBuffer.AsSpan().Fill(0);
        }
예제 #16
0
        private void SendMessage(Google.Protobuf.IMessage message)
        {
            byte[] messageBytes = new byte[bufferSize];
            Google.Protobuf.CodedOutputStream messageStream = new Google.Protobuf.CodedOutputStream(messageBytes);
            message.WriteTo(messageStream);
            uint messageSize = bufferSize - (uint)messageStream.SpaceLeft;

            Message.Header header = new Message.Header();
            header.MessageType = GetMessageType(message);
            header.MessageSize = messageSize;
            header.Ok          = true;

            byte[] headerBytes = new byte[headerSize];
            Google.Protobuf.CodedOutputStream headerStream = new Google.Protobuf.CodedOutputStream(headerBytes);
            header.WriteTo(headerStream);
            //uint headerSize = bufferSize - (uint)headerStream.SpaceLeft;

            socket.Blocking = false;

            Byte[] b = new Byte[headerSize];
            for (int i = 0; i < headerSize; ++i)
            {
                b[i] = headerBytes[i];
                //Console.WriteLine("HDR: b[{0}]={1:X}", i, headerBytes[i]); // TODO SARGE
            }
            if (headerSize == socket.Send(b))
            {
                b = new Byte[messageSize];
                for (int i = 0; i < messageSize; ++i)
                {
                    b[i] = messageBytes[i];
                    //Console.WriteLine("MSG: b[{0}]={1:X}", i, messageBytes[i]); // TODO SARGE
                }
                if (messageSize == socket.Send(b))
                {
                    // NOP
                }
                else
                {
                    Console.WriteLine("Unable to send message. :(");
                }
            }
            else
            {
                Console.WriteLine("Unable to send header. :(");
            }
        }
예제 #17
0
        static StackObject *WriteInt32_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @value = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.CodedOutputStream instance_of_this_method = (Google.Protobuf.CodedOutputStream) typeof(Google.Protobuf.CodedOutputStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.WriteInt32(@value);

            return(__ret);
        }
예제 #18
0
        static StackObject *WriteRawTag_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Byte @b1 = (byte)ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.CodedOutputStream instance_of_this_method = (Google.Protobuf.CodedOutputStream) typeof(Google.Protobuf.CodedOutputStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.WriteRawTag(@b1);

            return(__ret);
        }
        private void SendRequest(Request request)
        {
            using (var mem = new MemoryStream())
            {
                using (var stream = new Google.Protobuf.CodedOutputStream(mem))
                {
                    request.WriteTo(stream);
                }

                var data = mem.ToArray();

                lock (socketLock)
                {
                    lastRequest = request;
                    webSocket.Send(data, 0, data.Length);
                }
            }
        }
예제 #20
0
        static void Main(string[] args)
        {
            var m1 = new Winner3Way(
                new Outcome.Priced(1.85m),
                new Outcome.PricedWithProb(3.3m, 0.33f),
                new Outcome.Resulted(OutcomeResult.Canceled));

            Console.WriteLine($"Orig: {m1}");

            using var outputStream = new MemoryStream();
            using var output       = new Google.Protobuf.CodedOutputStream(outputStream);

            m1.FromDomain().WriteTo(output);
            output.Flush();

            var bytes = outputStream.ToArray();

            Console.WriteLine($"Protobuf Bytes Length={bytes.Length}, {BitConverter.ToString(bytes)}");

            using var inputStream = new MemoryStream(bytes);
            using var input       = new Google.Protobuf.CodedInputStream(inputStream);
            var protoCopy = new Domain.Protobuf.Winner3Way();

            protoCopy.MergeFrom(input);

            var copy = protoCopy.ToDomain();

            Console.WriteLine($"Copy: {copy}");

            using var jsonStream = new MemoryStream();
            using var jsonWriter = new System.Text.Json.Utf8JsonWriter(jsonStream);
            m1.WriteJson(jsonWriter);
            jsonWriter.Flush();
            var jsonString = Encoding.UTF8.GetString(jsonStream.ToArray());

            Console.WriteLine($"Json {jsonString}");

            var jsonDoc  = System.Text.Json.JsonDocument.Parse(jsonString);
            var jsonCopy = Json.ReadWinner3Way(jsonDoc.RootElement);

            Console.WriteLine($"Json Copy: {jsonCopy}");

            ComplexDomainDemo.Run();
        }
        public byte[] SerializeMessage()
        {
            var mmstream = new MemoryStream();
            var stream   = new Google.Protobuf.CodedOutputStream(mmstream);

            this.Message.WriteTo(stream);
            stream.Dispose();
            mmstream.Seek(0, SeekOrigin.Begin);
            var byteArray = new byte[mmstream.Length];
            var count     = mmstream.Read(byteArray, 0, 20);

            // Read the remaining bytes, byte by byte.
            while (count < mmstream.Length)
            {
                byteArray[count++] = Convert.ToByte(mmstream.ReadByte());
            }
            // return byteArr;
            return(byteArray);
        }
예제 #22
0
 private static void ReturnCodedOutputStream(Google.Protobuf.CodedOutputStream stream)
 {
     if (stream != null)
     {
         var index = System.Threading.Interlocked.Increment(ref _CodedOutputStreamPoolCnt);
         if (index > _CODED_STREAM_POOL_SLOT)
         {
             System.Threading.Interlocked.Decrement(ref _CodedOutputStreamPoolCnt);
         }
         else
         {
             --index;
             while (System.Threading.Interlocked.CompareExchange(ref _CodedOutputStreamPool[index], stream, null) != null)
             {
                 ;
             }
         }
     }
 }
예제 #23
0
            /**
             * Common logic for sending messages via protocol buffers.
             *
             * @param command
             * @param message
             * @param originator
             * @param label
             * @throws SiteWhereAgentException
             */
            protected void sendMessage(Lib.SiteWhere.SiteWhere.Types.Command command, Google.Protobuf.IMessage message, String originator, String label)
            {
                System.IO.MemoryStream            stream = new System.IO.MemoryStream();
                Google.Protobuf.CodedOutputStream output = new Google.Protobuf.CodedOutputStream(stream);
                try
                {
                    Lib.SiteWhere.SiteWhere.Types.Header h = new SiteWhere.SiteWhere.Types.Header();
                    h.Command = command;

                    if (originator != null)
                    {
                        h.Originator = originator;
                    }

                    h.WriteTo(output);
                    message.WriteTo(output);

                    output.Flush();

                    //string s = "2,8,1,50,10,10,121,117,110,103,111,97,108,50,50,50,18,36,55,100,102,100,54,100,54,51,45,53,101,56,100,45,52,51,56,48,45,98,101,48,52,45,102,99,53,99,55,51,56,48,49,100,102,98";
                    //List<byte> bytes = new List<byte>();
                    //foreach(var b in s.Split(','))
                    //{
                    //    byte br;
                    //    if (int.Parse(b) < 0)
                    //        br = (byte)(0xff & int.Parse(b));
                    //    else
                    //        br = byte.Parse(b);
                    //    bytes.Add(br);
                    //}

                    //connection.Publish(getTopic(), bytes.ToArray(), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                    connection.Publish(getTopic(), stream.ToArray(), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);

                    output.Dispose();
                }
                catch (Exception e)
                {
                    LOGGER.info(e.Message);
                }
            }
예제 #24
0
        static StackObject *WriteTo_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            Google.Protobuf.FieldCodec <System.Int32> codec = (Google.Protobuf.FieldCodec <System.Int32>) typeof(Google.Protobuf.FieldCodec <System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.CodedOutputStream output = (Google.Protobuf.CodedOutputStream) typeof(Google.Protobuf.CodedOutputStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            Google.Protobuf.Collections.RepeatedField <System.Int32> instance_of_this_method;
            instance_of_this_method = (Google.Protobuf.Collections.RepeatedField <System.Int32>) typeof(Google.Protobuf.Collections.RepeatedField <System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.WriteTo(output, codec);

            return(__ret);
        }
예제 #25
0
        public byte[] Marshal()
        {
            if (Attributes != null && Attributes.Count > 0 && Content != null && Content is List <WebMessageInfo> wms)
            {
                var nl = new List <Node>();
                foreach (var wm in wms)
                {
                    var bs = new byte[4096];
                    var me = new Google.Protobuf.CodedOutputStream(bs);
                    wm.WriteTo(me);
                    nl.Add(new Node
                    {
                        Content     = bs.Take((int)me.Position).ToArray(),
                        Description = "message"
                    });
                }
                Content = nl;
            }
            BinaryEncoder binaryEncoder = new BinaryEncoder();

            return(binaryEncoder.WriteNode(this));
        }
        static StackObject *WriteTo_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            Google.Protobuf.FieldCodec <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor> @codec = (Google.Protobuf.FieldCodec <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor>) typeof(Google.Protobuf.FieldCodec <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.CodedOutputStream @output = (Google.Protobuf.CodedOutputStream) typeof(Google.Protobuf.CodedOutputStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            Google.Protobuf.Collections.RepeatedField <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor> instance_of_this_method = (Google.Protobuf.Collections.RepeatedField <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor>) typeof(Google.Protobuf.Collections.RepeatedField <Google.Protobuf.ProtobufIMessageAdaptor.Adaptor>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.WriteTo(@output, @codec);

            return(__ret);
        }
예제 #27
0
        //public bool CryptoPackage<T>(T msg, Func<MemoryStream, MemoryStream, bool> func)
        //{
        //    MemoryStream body = new MemoryStream();
        //    ProtoBuf.Serializer.Serialize(body, msg);
        //    UInt16 protobufLen = (ushort)body.Length;

        //    if (blowFishInst != null && protobufLen > 0)
        //    {
        //        body = blowFishInst.Encrypt_CBC(body);
        //    }

        //    UInt16 len = (ushort)body.Length;
        //    MemoryStream header = new MemoryStream(PacketHeader.Size);

        //    header.Write(BitConverter.GetBytes(len), 0, 2);
        //    header.Write(BitConverter.GetBytes(protobufLen), 0, 2);
        //    header.Write(BitConverter.GetBytes(Engine.Foundation.Id<T>.Value), 0, 4);

        //    return func(header, body);
        //}

        //public bool Package<T>(T msg, Func<MemoryStream, bool> func)
        //{
        //    MemoryStream body = new MemoryStream();
        //    ProtoBuf.Serializer.Serialize(body, msg);

        //    UInt16 protobufLen = (ushort)body.Length;
        //    UInt16 len = (ushort)body.Length;
        //    //if (blowFishInst != null && protobufLen > 0)
        //    //{
        //    //    body = blowFishInst.Encrypt_CBC(body);
        //    //}
        //    MemoryStream packet = new MemoryStream(PacketHeader.Size);

        //    packet.Write(BitConverter.GetBytes(len), 0, 2);
        //    packet.Write(BitConverter.GetBytes(protobufLen), 0, 2);
        //    packet.Write(BitConverter.GetBytes(Engine.Foundation.Id<T>.Value), 0, 4);
        //    packet.Write(body.GetBuffer(), 0, len);

        //    return func(packet);
        //}
        public bool Package1 <T>(T msg, Func <MemoryStream, bool> func, uint msgid) where T : Google.Protobuf.IMessage <T>
        {
            MemoryStream body = new MemoryStream();

            Google.Protobuf.CodedOutputStream outbody = new Google.Protobuf.CodedOutputStream(body);
            outbody.WriteGroup(msg);
            outbody.Flush();
            UInt16 protobufLen = (ushort)body.Length;
            UInt16 len         = (ushort)body.Length;
            //if (blowFishInst != null && protobufLen > 0)
            //{
            //    body = blowFishInst.Encrypt_CBC(body);
            //}
            MemoryStream packet = new MemoryStream(PacketHeader.Size);

            packet.Write(BitConverter.GetBytes(len), 0, 2);
            //packet.Write(BitConverter.GetBytes(protobufLen), 0, 2);
            packet.Write(BitConverter.GetBytes(msgid), 0, 4);
            packet.Write(body.GetBuffer(), 0, len);

            return(func(packet));
        }
예제 #28
0
        static int _m_WriteTo(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                Google.Protobuf.IMessage gen_to_be_invoked = (Google.Protobuf.IMessage)translator.FastGetCSObj(L, 1);



                {
                    Google.Protobuf.CodedOutputStream _output = (Google.Protobuf.CodedOutputStream)translator.GetObject(L, 2, typeof(Google.Protobuf.CodedOutputStream));

                    gen_to_be_invoked.WriteTo(_output);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
 public void WriteTo(Google.Protobuf.CodedOutputStream output)
 {
     mWriteTo_1.Invoke(this.instance, output);
 }
예제 #30
0
 public void WriteTo(Google.Protobuf.CodedOutputStream output) => throw new NotImplementedException();