本文整理汇总了C#中SerializationContext.EncodeInt64方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationContext.EncodeInt64方法的具体用法?C# SerializationContext.EncodeInt64怎么用?C# SerializationContext.EncodeInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerializationContext
的用法示例。
在下文中一共展示了SerializationContext.EncodeInt64方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeDecimal
public static int SerializeDecimal(decimal value, SerializationContext context, bool lengthPrefixed)
{
int[] bits = decimal.GetBits(value);
ulong a = ((ulong)bits[1]) << 32, b = ((ulong)bits[0]) & 0xFFFFFFFFL;
ulong low = a | b;
uint high = (uint) bits[2];
uint signScale = (uint)(((bits[3] >> 15) & 0x01FE) | ((bits[3] >> 31) & 0x0001));
int len = 0;
if (lengthPrefixed)
{
if (low != 0) len += 1 + SerializationContext.GetLength((long)low);
if (high != 0) len += 1 + SerializationContext.GetLength((long)high);
if (signScale!=0) len += 2;
len = context.EncodeInt32(len);
}
if (low != 0)
{
context.WriteByte((FieldDecimalLow << 3) | (int)WireType.Variant);
len += 1 + context.EncodeInt64((long)low);
}
if (high != 0)
{ // note encode as long to avoid high sign issues
context.WriteByte((FieldDecimalHigh << 3) | (int)WireType.Variant);
len += 1 + context.EncodeInt64((long)high);
}
if (signScale != 0)
{
context.WriteByte((FieldDecimalSignScale << 3) | (int)WireType.Variant);
context.WriteByte((byte)signScale);
len += 2;
}
return len;
}