예제 #1
0
 protected void TryReadMutationToken(byte[] buffer)
 {
     if (buffer.Length >= 40 && VBucket != null)
     {
         var uuid  = Converter.ToInt64(buffer, Header.ExtrasOffset);
         var seqno = Converter.ToInt64(buffer, Header.ExtrasOffset + 8);
         MutationToken = new MutationToken(VBucket.BucketName, (short)VBucket.Index, uuid, seqno);
     }
 }
예제 #2
0
 protected void TryReadMutationToken(ReadOnlySpan <byte> buffer)
 {
     if (buffer.Length >= 40 && VBucketId.HasValue)
     {
         var uuid  = Converter.ToInt64(buffer.Slice(Header.ExtrasOffset));
         var seqno = Converter.ToInt64(buffer.Slice(Header.ExtrasOffset + 8));
         MutationToken = new MutationToken(BucketName, VBucketId.Value, uuid, seqno);
     }
 }
예제 #3
0
        public T Deserialize <T>(byte[] buffer, int offset, int length)
        {
            object value = default(T);

            var typeCode = Type.GetTypeCode(typeof(T));

            switch (typeCode)
            {
            case TypeCode.Empty:
            case TypeCode.DBNull:
            case TypeCode.String:
            case TypeCode.Char:
                value = Deserialize(buffer, offset, length);
                break;

            case TypeCode.Int16:
                if (length > 0)
                {
                    value = _converter.ToInt16(buffer, offset);
                }
                break;

            case TypeCode.UInt16:
                if (length > 0)
                {
                    value = _converter.ToUInt16(buffer, offset);
                }
                break;

            case TypeCode.Int32:
                if (length > 0)
                {
                    value = _converter.ToInt32(buffer, offset);
                }
                break;

            case TypeCode.UInt32:
                if (length > 0)
                {
                    value = _converter.ToUInt32(buffer, offset);
                }
                break;

            case TypeCode.Int64:
                if (length > 0)
                {
                    value = _converter.ToInt64(buffer, offset);
                }
                break;

            case TypeCode.UInt64:
                if (length > 0)
                {
                    value = _converter.ToUInt64(buffer, offset);
                }
                break;

            case TypeCode.Single:
                break;

            case TypeCode.Double:
                break;

            case TypeCode.Decimal:
                break;

            case TypeCode.DateTime:
                break;

            case TypeCode.Boolean:
                break;

            case TypeCode.SByte:
                break;

            case TypeCode.Byte:
                break;

            case TypeCode.Object:
                value = DeserializeAsJson <T>(buffer, offset, length);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return((T)value);
        }
 /// <summary>
 /// Reads a <see cref="Int64"/> from a buffer, using network byte order.
 /// </summary>
 /// <param name="converter">The converter.</param>
 /// <param name="buffer">The buffer.</param>
 /// <returns></returns>
 public static long ToInt64(this IByteConverter converter, ReadOnlySpan <byte> buffer)
 {
     return(converter.ToInt64(buffer, true));
 }