예제 #1
0
        private unsafe SyncResult[] DecodeResult(ArraySegment <byte> result)
        {
            var data = result.Array;

            if (data == null)
                throw new InvalidOperationException("No data received");

            fixed(byte *p = data)
            {
                var offset = result.Offset;
                var count  = BinaryConverter.DecodeUInt16(p, offset);
                var retval = new SyncResult[count];

                offset += 2;

                for (var i = 0; i < retval.Length; i++)
                {
                    var cas = BinaryConverter.DecodeUInt64(p, offset);
                    // skip vbucket (8-9)
                    var keyLength = BinaryConverter.DecodeUInt16(p, offset + 10);
                    var eventId   = (SyncEvent)p[offset + 12];
                    var key       = Encoding.UTF8.GetString(data, offset + 13, keyLength);

                    retval[i] = new SyncResult
                    {
                        Cas   = cas,
                        Event = eventId,
                        Key   = key
                    };

                    offset += (13 + keyLength);
                }

                return(retval);
            }
        }
예제 #2
0
        private unsafe SyncResult[] DecodeResult(ArraySegment<byte> result)
        {
            var data = result.Array;
            if (data == null)
                throw new InvalidOperationException("No data received");

            fixed (byte* p = data)
            {
                var offset = result.Offset;
                var count = BinaryConverter.DecodeUInt16(p, offset);
                var retval = new SyncResult[count];
                offset += 2;

                for (var i = 0; i < retval.Length; i++)
                {
                    var cas = BinaryConverter.DecodeUInt64(p, offset);
                    // skip vbucket (8-9)
                    var keyLength = BinaryConverter.DecodeUInt16(p, offset + 10);
                    var eventId = (SyncEvent)p[offset + 12];
                    var key = Encoding.UTF8.GetString(data, offset + 13, keyLength);

                    retval[i] = new SyncResult
                    {
                        Cas = cas,
                        Event = eventId,
                        Key = key
                    };

                    offset += (13 + keyLength);
                }

                return retval;
            }
        }