示例#1
0
        /// <summary>
        /// Processes the packet within the context. Returns true whether the packet was processed or throttled.
        /// </summary>
        /// <param name="channel">The through which the packet is coming/going out.</param>
        /// <param name="context">The packet context for this operation.</param>
        /// <returns>True whether the packet was processed or throttled, false otherwise.</returns>
        public static ProcessingState Process(Emitter.Connection channel, ProcessingContext context)
        {
            // Get the buffer to decompress
            var input = context.Buffer.AsSegment();

            try
            {
                // Reserve the buffer, we know exactly how many bytes to decompress
                var output = context.BufferReserve(
                    (int)VarInt.UvarInt(input.Array, input.Offset).Value
                    );

                // Decompress
                var length = Snappy.Decode(
                    input.Array, input.Offset, input.Count,
                    output.Array, output.Offset, output.Size
                    );

                // Switch the buffer to the decompressed one
                context.SwitchBuffer(output);
            }
            catch (Exception ex)
            {
                ex.Log();
            }

            return(ProcessingState.Success);
        }
示例#2
0
        void roundtrip(ulong x)
        {
            // Use some padding bytes to check nonzero offsets.
            var pad = 5;

            var buf = new byte[VarInt.MaxVarIntLen64 + pad];
            int n   = VarInt.PutUvarInt(buf, pad, x);

            var ret = VarInt.UvarInt(buf, pad);

            Assert.AreEqual(n, ret.VarIntLength);
            Assert.AreEqual(x, ret.Value);
        }