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


C# SerializationContext.WriteByte方法代码示例

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


在下文中一共展示了SerializationContext.WriteByte方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
        }
开发者ID:amwtke,项目名称:commonlibrary,代码行数:34,代码来源:ProtoDecimal.cs

示例2: Serialize

        internal static int Serialize(Guid value, SerializationContext context, bool lengthPrefix)
        {
            if (value == Guid.Empty)
            {
                if (lengthPrefix)
                {
                    context.WriteByte(0);
                    return 1;
                }
                return 0;
            }
            byte[] buffer = value.ToByteArray();

            int len = 0;
            if (lengthPrefix)
            {
                context.WriteByte((byte)18);
                len = 1;
            }
            context.WriteByte(FieldLo << 3 | (int)WireType.Fixed64);
            context.WriteBlock(buffer, 0, 8);
            context.WriteByte(FieldHi << 3 | (int)WireType.Fixed64);
            context.WriteBlock(buffer, 8, 8);
            return len + 18;
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:25,代码来源:ProtoGuid.cs

示例3: SerializeTimeSpan

        internal static int SerializeTimeSpan(TimeSpan timeSpan, SerializationContext context, bool lengthPrefixed)
        {
            TimeSpanScale scale;
            long value = timeSpan.Ticks;
            if (timeSpan == TimeSpan.MaxValue)
            {
                value = 1;
                scale = TimeSpanScale.MinMax;
            }
            else if (timeSpan == TimeSpan.MinValue)
            {
                value = -1;
                scale = TimeSpanScale.MinMax;
            }
            else if (value % TimeSpan.TicksPerDay == 0)
            {
                scale = TimeSpanScale.Days;
                value /= TimeSpan.TicksPerDay;
            }
            else if (value % TimeSpan.TicksPerHour == 0)
            {
                scale = TimeSpanScale.Hours;
                value /= TimeSpan.TicksPerHour;
            }
            else if (value % TimeSpan.TicksPerMinute == 0)
            {
                scale = TimeSpanScale.Minutes;
                value /= TimeSpan.TicksPerMinute;
            }
            else if (value % TimeSpan.TicksPerSecond == 0)
            {
                scale = TimeSpanScale.Seconds;
                value /= TimeSpan.TicksPerSecond;
            }
            else if (value % TimeSpan.TicksPerMillisecond == 0)
            {
                scale = TimeSpanScale.Milliseconds;
                value /= TimeSpan.TicksPerMillisecond;
            }
            else
            {
                scale = TimeSpanScale.Ticks;
            }

            int len = 0;
            ulong zig = SerializationContext.Zig(value);
            if (lengthPrefixed)
            {
                if (scale != TimeSpanScale.Days)
                {
                    len += 2;
                }
                if (zig != 0)
                {
                    len += 1 + SerializationContext.GetLength(zig);
                }
                context.WriteByte((byte)len);
                len = 1;
            }
            if (value != 0)
            {
                context.WriteByte((FieldTimeSpanValue << 3) | (int)WireType.Variant);
                len += 1 + context.EncodeUInt64(zig);
            }
            if (scale != TimeSpanScale.Days)
            {
                context.WriteByte((FieldTimeSpanScale << 3) | (int)WireType.Variant);
                len += 1 + context.EncodeInt32((int)scale);
            }
            return len;
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:71,代码来源:ProtoTimeSpan.cs


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