当前位置: 首页>>代码示例>>C#>>正文


C# Slice.ReadUInt64BE方法代码示例

本文整理汇总了C#中Slice.ReadUInt64BE方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.ReadUInt64BE方法的具体用法?C# Slice.ReadUInt64BE怎么用?C# Slice.ReadUInt64BE使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slice的用法示例。


在下文中一共展示了Slice.ReadUInt64BE方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseDouble

		internal static double ParseDouble(Slice slice)
		{
			Contract.Requires(slice.HasValue && slice[0] == FdbTupleTypes.Double);

			if (slice.Count != 9)
			{
				throw new FormatException("Slice has invalid size for a Double");
			}

			// We need to reverse encoding process: if first byte < 0x80 then it is negative (bits need to be flipped), else it is positive (highest bit must be set to 0)

			// read the raw bits
			ulong bits = slice.ReadUInt64BE(1, 8); //OPTIMIZE: inline version?

			if ((bits & 0x8000000000000000UL) == 0)
			{ // negative
				bits = ~bits;
			}
			else
			{ // postive
				bits ^= 0x8000000000000000UL;
			}

			// note: we could use BitConverter.Int64BitsToDouble(...), but it does the same thing, and also it does not exist for floats...
			double value;
			unsafe { value = *((double*)&bits); }

			return value;
		}
开发者ID:Rustemt,项目名称:foundationdb-dotnet-client,代码行数:29,代码来源:FdbTupleParser.cs

示例2: ParseInt64

		internal static long ParseInt64(int type, Slice slice)
		{
			int bytes = type - FdbTupleTypes.IntBase;
			if (bytes == 0) return 0L;

			bool neg = false;
			if (bytes < 0)
			{
				bytes = -bytes;
				neg = true;
			}

			if (bytes > 8) throw new FormatException("Invalid size for tuple integer");
			long value = (long)slice.ReadUInt64BE(1, bytes);

			if (neg)
			{ // the value is encoded as the one's complement of the absolute value
				value = (-(~value));
				if (bytes < 8) value |= (-1L << (bytes << 3));
				return value;
			}

			return value;
		}
开发者ID:Rustemt,项目名称:foundationdb-dotnet-client,代码行数:24,代码来源:FdbTupleParser.cs


注:本文中的Slice.ReadUInt64BE方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。