private void ReadContent(byte[] buffer, ErrorMap errorMap) { if (Header.BodyLength == 0 && buffer.Length >= HeaderIndexFor.HeaderLength) { var status = GetResponseStatus(Converter.ToInt16(buffer, HeaderIndexFor.Status), errorMap); Header = new OperationHeader { Magic = Converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = status, BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) }; if (Opaque != Header.Opaque) { var msg = string.Format("Expected opaque {0} but got {1}", Opaque, Header.Opaque); HandleClientError(msg, ResponseStatus.ClientFailure); } } LengthReceived += buffer.Length; }
/// <summary> /// Caution, this will only affect the query that use column data. does not update index or the real content body.. /// </summary> /// <typeparam name="TColumnType"></typeparam> /// <param name="key"></param> /// <param name="ColumnName"></param> /// <param name="value"></param> private void UpdateColumn <TColumnType>(TKey key, string ColumnName, TColumnType value) { if (ColumnName == null) { throw new Exception("column name is required"); } var col = this.GetColumn(ColumnName); if (col == null || col.DataType != typeof(TColumnType)) { throw new Exception("Column name not found or data type not match"); } IByteConverter <TColumnType> converter = ObjectContainer.GetConverter <TColumnType>(); long blockpoisiton = this.getBlockPosition(key); var bytes = converter.ToByte(value); if (col.IsString) { bytes = Helper.KeyHelper.AppendToKeyLength(bytes, true, col.Length); } lock (_Locker) { this.BlockFile.UpdateCol(blockpoisiton, col.relativePosition, col.Length, bytes); } }
public virtual void Read(byte[] buffer, int offset, int length) { if (Header.BodyLength == 0 && buffer.Length >= HeaderIndexFor.HeaderLength) { Header = new OperationHeader { Magic = Converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = (ResponseStatus)Converter.ToInt16(buffer, HeaderIndexFor.Status), BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) }; if (Opaque != Header.Opaque) { var msg = string.Format("Expected opaque {0} but got {1}", Opaque, Header.Opaque); HandleClientError(msg, ResponseStatus.ClientFailure); } } LengthReceived += length; Data.Write(buffer, offset, length); }
public virtual void Read(byte[] buffer, int offset, int length) { if (Header.BodyLength == 0) { Header = new OperationHeader { Magic = Converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = (ResponseStatus)Converter.ToInt16(buffer, HeaderIndexFor.Status), BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) }; } LengthReceived += length; Data.Write(buffer, offset, length); }
protected void CreateHeader(OperationAsyncState state) { var buffer = state.Data.GetBuffer(); if (buffer.Length > 0) { state.Header = new OperationHeader { Magic = _converter.ToByte(buffer, HeaderIndexFor.Magic), OperationCode = _converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), KeyLength = _converter.ToInt16(buffer, HeaderIndexFor.KeyLength), ExtrasLength = _converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), Status = (ResponseStatus)_converter.ToInt16(buffer, HeaderIndexFor.Status), BodyLength = _converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = _converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = _converter.ToUInt64(buffer, HeaderIndexFor.Cas) }; } }
public Filter <TKey, TValue> WhereEqual(string FieldOrPropertyName, Guid Value) { FilterItem item = new FilterItem(); item.Compare = Comparer.EqualTo; item.FieldOrProperty = FieldOrPropertyName; item.FieldType = typeof(Guid); IByteConverter <Guid> x = ObjectContainer.GetConverter <Guid>(); item.Value = x.ToByte(Value); item.Length = 16; this.items.Add(item); return(this); }
public Filter <TKey, TValue> Where(string FieldOrPropertyName, Comparer comparer, DateTime CompareValue, DateTimeScope scope) { FilterItem item = new FilterItem(); item.Compare = comparer; item.TimeScope = scope; item.FieldOrProperty = FieldOrPropertyName; item.FieldType = typeof(DateTime); item.Length = 8; IByteConverter <DateTime> x = ObjectContainer.GetConverter <DateTime>(); item.Value = x.ToByte(CompareValue); this.items.Add(item); return(this); }
internal static OperationHeader CreateHeader(this ReadOnlySpan <byte> buffer, ErrorMap errorMap, out ErrorCode errorCode) { if (buffer == null || buffer.Length < OperationHeader.Length) { errorCode = null; return(new OperationHeader { Status = ResponseStatus.None }); } int keyLength, framingExtrasLength; var magic = (Magic)Converter.ToByte(buffer.Slice(HeaderOffsets.Magic)); if (magic == Magic.AltResponse) { framingExtrasLength = Converter.ToByte(buffer.Slice(HeaderOffsets.FramingExtras)); keyLength = Converter.ToByte(buffer.Slice(HeaderOffsets.AltKeyLength)); } else { framingExtrasLength = 0; keyLength = Converter.ToInt16(buffer.Slice(HeaderOffsets.KeyLength)); } var statusCode = Converter.ToInt16(buffer.Slice(HeaderOffsets.Status)); var status = GetResponseStatus(statusCode, errorMap, out errorCode); return(new OperationHeader { Magic = (byte)magic, OpCode = Converter.ToByte(buffer.Slice(HeaderOffsets.Opcode)).ToOpCode(), FramingExtrasLength = framingExtrasLength, KeyLength = keyLength, ExtrasLength = Converter.ToByte(buffer.Slice(HeaderOffsets.ExtrasLength)), DataType = (DataType)Converter.ToByte(buffer.Slice(HeaderOffsets.Datatype)), Status = status, BodyLength = Converter.ToInt32(buffer.Slice(HeaderOffsets.Body)), Opaque = Converter.ToUInt32(buffer.Slice(HeaderOffsets.Opaque)), Cas = Converter.ToUInt64(buffer.Slice(HeaderOffsets.Cas)) }); }
internal static OperationHeader CreateHeader(this byte[] buffer, ErrorMap errorMap, out ErrorCode errorCode) { if (buffer == null || buffer.Length < HeaderIndexFor.HeaderLength) { errorCode = null; return(new OperationHeader { Status = ResponseStatus.None }); } int keyLength, framingExtrasLength; var magic = (Magic)Converter.ToByte(buffer, HeaderIndexFor.Magic); if (magic == Magic.AltResponse) { framingExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.FramingExtras); keyLength = Converter.ToByte(buffer, HeaderIndexFor.AltKeyLength); } else { framingExtrasLength = 0; keyLength = Converter.ToInt16(buffer, HeaderIndexFor.KeyLength); } var statusCode = Converter.ToInt16(buffer, HeaderIndexFor.Status); var status = GetResponseStatus(statusCode, errorMap, out errorCode); return(new OperationHeader { Magic = (byte)magic, OperationCode = Converter.ToByte(buffer, HeaderIndexFor.Opcode).ToOpCode(), FramingExtrasLength = framingExtrasLength, KeyLength = keyLength, ExtrasLength = Converter.ToByte(buffer, HeaderIndexFor.ExtrasLength), DataType = (DataType)Converter.ToByte(buffer, HeaderIndexFor.Datatype), Status = status, BodyLength = Converter.ToInt32(buffer, HeaderIndexFor.Body), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque), Cas = Converter.ToUInt64(buffer, HeaderIndexFor.Cas) }); }
public static byte ToByte(this IByteConverter converter, byte[] buffer, int index) { Contracts.Requires.That(converter != null); return(converter.ToByte(buffer, ref index)); }
private byte[] getByteValue(Type datatype, object objectvalue) { if (datatype == typeof(Int32)) { int value = Convert.ToInt32(objectvalue); IByteConverter <Int32> x = ObjectContainer.GetConverter <Int32>(); return(x.ToByte(value)); } else if (datatype == typeof(Int16)) { Int16 value = Convert.ToInt16(objectvalue); IByteConverter <Int16> x = ObjectContainer.GetConverter <Int16>(); return(x.ToByte(value)); } else if (datatype == typeof(string)) { string value = Convert.ToString(objectvalue); IByteConverter <string> x = ObjectContainer.GetConverter <string>(); return(x.ToByte(value)); } else if (datatype == typeof(Int64)) { Int64 value = Convert.ToInt64(objectvalue); IByteConverter <Int64> x = ObjectContainer.GetConverter <Int64>(); return(x.ToByte(value)); } else if (datatype == typeof(float)) { float value = Convert.ToSingle(objectvalue); IByteConverter <float> x = ObjectContainer.GetConverter <float>(); return(x.ToByte(value)); } else if (datatype == typeof(double)) { double value = Convert.ToDouble(objectvalue); IByteConverter <double> x = ObjectContainer.GetConverter <double>(); return(x.ToByte(value)); } else if (datatype == typeof(decimal)) { double value = Convert.ToDouble(objectvalue); IByteConverter <double> x = ObjectContainer.GetConverter <double>(); return(x.ToByte(value)); } else if (datatype == typeof(Guid)) { Guid value = Guid.Parse(Convert.ToString(objectvalue)); if (value == null) { return(null); } else { IByteConverter <Guid> x = ObjectContainer.GetConverter <Guid>(); return(x.ToByte(value)); } } else if (datatype == typeof(bool)) { bool value = Convert.ToBoolean(objectvalue); byte[] valuebyte = new byte[1]; if (value) { valuebyte[0] = 1; } else { valuebyte[0] = 0; } return(valuebyte); } else if (datatype == typeof(DateTime)) { DateTime datevalue = (DateTime)objectvalue; IByteConverter <DateTime> x = ObjectContainer.GetConverter <DateTime>(); return(x.ToByte(datevalue)); } else if (datatype == typeof(byte)) { byte[] valuebyte = new byte[1]; valuebyte[0] = Convert.ToByte(objectvalue); return(valuebyte); } else if (datatype.IsEnum) { int intvalue = (int)objectvalue; IByteConverter <Int32> x = ObjectContainer.GetConverter <Int32>(); return(x.ToByte(intvalue)); } else { throw new Exception("data type not supported for filter"); } }