WriteInt64() public static method

Writes a signed 64-bit integer to the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant
public static WriteInt64 ( long value, ProtoWriter writer ) : void
value long
writer ProtoWriter
return void
        static void WriteDouble(double value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            switch (writer.wireType)
            {
            case WireType.Fixed32:
                float f = (float)value;
                if (Helpers.IsInfinity(f) &&
                    !Helpers.IsInfinity(value))
                {
                    throw new OverflowException();
                }
                ProtoWriter.WriteSingle(f, writer);
                return;

            case WireType.Fixed64:
#if FEAT_SAFE
                ProtoWriter.WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(value), 0), writer);
#else
                ProtoWriter.WriteInt64(*(long *)&value, writer);
#endif
                return;

            default:
                throw CreateException(writer);
            }
        }
        /// <summary>
        /// Writes an unsigned 16-bit integer to the stream; supported wire-types: Variant, Fixed32, Fixed64
        /// </summary>
        public static void WriteUInt32(uint value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            switch (writer.wireType)
            {
            case WireType.Fixed32:
                ProtoWriter.WriteInt32((int)value, writer);
                return;

            case WireType.Fixed64:
                ProtoWriter.WriteInt64((int)value, writer);
                return;

            case WireType.Variant:
                WriteUInt32Variant(value, writer);
                writer.wireType = WireType.None;
                return;

            default:
                throw CreateException(writer);
            }
        }
Example #3
0
        public static void WriteDouble(double value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            WireType wireType = writer.wireType;

            if (wireType == WireType.Fixed64)
            {
                ProtoWriter.WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(value), 0), writer);
                return;
            }
            if (wireType != WireType.Fixed32)
            {
                throw ProtoWriter.CreateException(writer);
            }
            float value2 = (float)value;

            if (Helpers.IsInfinity(value2) && !Helpers.IsInfinity(value))
            {
                throw new OverflowException();
            }
            ProtoWriter.WriteSingle(value2, writer);
        }
Example #4
0
        // Token: 0x0600015A RID: 346 RVA: 0x0000DA5C File Offset: 0x0000BC5C
        public static void WriteUInt32(uint value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            WireType wireType = writer.wireType;

            if (wireType == WireType.Variant)
            {
                ProtoWriter.WriteUInt32Variant(value, writer);
                writer.wireType = WireType.None;
                return;
            }
            if (wireType == WireType.Fixed64)
            {
                ProtoWriter.WriteInt64((long)value, writer);
                return;
            }
            if (wireType == WireType.Fixed32)
            {
                ProtoWriter.WriteInt32((int)value, writer);
                return;
            }
            throw ProtoWriter.CreateException(writer);
        }
Example #5
0
        /// <summary>
        /// Writes a TimeSpan to a protobuf stream
        /// </summary>
        public static void WriteTimeSpan(TimeSpan timeSpan, ProtoWriter dest)
        {
            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;
            }

            SubItemToken token = ProtoWriter.StartSubItem(null, dest);

            if (value != 0)
            {
                ProtoWriter.WriteFieldHeader(FieldTimeSpanValue, WireType.SignedVariant, dest);
                ProtoWriter.WriteInt64(value, dest);
            }
            if (scale != TimeSpanScale.Days)
            {
                ProtoWriter.WriteFieldHeader(FieldTimeSpanScale, WireType.Variant, dest);
                ProtoWriter.WriteInt32((int)scale, dest);
            }
            ProtoWriter.EndSubItem(token, dest);
        }
Example #6
0
        private static void WriteSecondsNanos(long seconds, int nanos, ProtoWriter dest, ref ProtoWriter.State state)
        {
            SubItemToken token = ProtoWriter.StartSubItem(null, dest, ref state);

            if (seconds != 0)
            {
                ProtoWriter.WriteFieldHeader(1, WireType.Variant, dest, ref state);
                ProtoWriter.WriteInt64(seconds, dest, ref state);
            }
            if (nanos != 0)
            {
                ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest, ref state);
                ProtoWriter.WriteInt32(nanos, dest, ref state);
            }
            ProtoWriter.EndSubItem(token, dest, ref state);
        }
Example #7
0
        /// <summary>
        /// Writes an unsigned 64-bit integer to the stream; supported wire-types: Variant, Fixed32, Fixed64
        /// </summary>
        public static void WriteUInt64(ulong value, ProtoWriter writer)
        {
            switch (writer.wireType)
            {
            case WireType.Fixed64:
                ProtoWriter.WriteInt64((long)value, writer);
                return;

            case WireType.Variant:
                WriteUInt64Variant(value, writer);
                writer.wireType = WireType.None;
                return;

            case WireType.Fixed32:
                checked { ProtoWriter.WriteUInt32((uint)value, writer); }
                return;

            default:
                throw CreateException(writer);
            }
        }
Example #8
0
        public static void WriteUInt64(ulong value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            switch (writer.wireType)
            {
            case WireType.Variant:
                ProtoWriter.WriteUInt64Variant(value, writer);
                writer.wireType = WireType.None;
                return;

            case WireType.Fixed64:
                ProtoWriter.WriteInt64((long)value, writer);
                return;

            case WireType.Fixed32:
                ProtoWriter.WriteUInt32(checked ((uint)value), writer);
                return;
            }
            throw ProtoWriter.CreateException(writer);
        }
Example #9
0
        private void AppendExtensionField(ProtoWriter writer)
        {
            //TODO: replace this with stream-based, buffered raw copying
            ProtoWriter.WriteFieldHeader(fieldNumber, wireType, writer);
            switch (wireType)
            {
            case WireType.Fixed32:
                ProtoWriter.WriteInt32(ReadInt32(), writer);
                return;

            case WireType.Variant:
            case WireType.SignedVariant:
            case WireType.Fixed64:
                ProtoWriter.WriteInt64(ReadInt64(), writer);
                return;

            case WireType.String:
                ProtoWriter.WriteBytes(AppendBytes(null, this), writer);
                return;

            case WireType.StartGroup:
                SubItemToken readerToken = StartSubItem(this),
                             writerToken = ProtoWriter.StartSubItem(null, writer);
                while (ReadFieldHeader() > 0)
                {
                    AppendExtensionField(writer);
                }
                EndSubItem(readerToken, this);
                ProtoWriter.EndSubItem(writerToken, writer);
                return;

            case WireType.None:     // treat as explicit errorr
            case WireType.EndGroup: // treat as explicit error
            default:                // treat as implicit error
                throw CreateException();
            }
        }
        public static void WriteUInt32(uint value, ProtoWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            ProtoBuf.WireType wireType = writer.wireType;
            switch (wireType)
            {
            case ProtoBuf.WireType.Variant:
            {
                ProtoWriter.WriteUInt32Variant(value, writer);
                writer.wireType = ProtoBuf.WireType.None;
                return;
            }

            case ProtoBuf.WireType.Fixed64:
            {
                ProtoWriter.WriteInt64((long)value, writer);
                return;
            }

            default:
            {
                if (wireType != ProtoBuf.WireType.Fixed32)
                {
                    break;
                }
                else
                {
                    ProtoWriter.WriteInt32((int)value, writer);
                    return;
                }
            }
            }
            throw ProtoWriter.CreateException(writer);
        }
Example #11
0
        private void AppendExtensionField(ProtoWriter writer)
        {
            ProtoWriter.WriteFieldHeader(this.fieldNumber, this.wireType, writer);
            WireType wireType = this.wireType;

            switch (wireType + 1)
            {
            case WireType.Fixed64:
            case WireType.String:
            case (WireType)9:
                ProtoWriter.WriteInt64(this.ReadInt64(), writer);
                return;

            case WireType.StartGroup:
                ProtoWriter.WriteBytes(ProtoReader.AppendBytes(null, this), writer);
                return;

            case WireType.EndGroup:
            {
                SubItemToken token  = ProtoReader.StartSubItem(this);
                SubItemToken token2 = ProtoWriter.StartSubItem(null, writer);
                while (this.ReadFieldHeader() > 0)
                {
                    this.AppendExtensionField(writer);
                }
                ProtoReader.EndSubItem(token, this);
                ProtoWriter.EndSubItem(token2, writer);
                return;
            }

            case (WireType)6:
                ProtoWriter.WriteInt32(this.ReadInt32(), writer);
                return;
            }
            throw this.CreateWireTypeException();
        }
Example #12
0
        private void AppendExtensionField(ProtoWriter writer)
        {
            ProtoWriter.WriteFieldHeader(fieldNumber, wireType, writer);
            switch (wireType)
            {
            case WireType.Fixed32:
                ProtoWriter.WriteInt32(ReadInt32(), writer);
                break;

            case WireType.Variant:
            case WireType.Fixed64:
            case WireType.SignedVariant:
                ProtoWriter.WriteInt64(ReadInt64(), writer);
                break;

            case WireType.String:
                ProtoWriter.WriteBytes(AppendBytes(null, this), writer);
                break;

            case WireType.StartGroup:
            {
                SubItemToken token  = StartSubItem(this);
                SubItemToken token2 = ProtoWriter.StartSubItem(null, writer);
                while (ReadFieldHeader() > 0)
                {
                    AppendExtensionField(writer);
                }
                EndSubItem(token, this);
                ProtoWriter.EndSubItem(token2, writer);
                break;
            }

            default:
                throw CreateWireTypeException();
            }
        }
Example #13
0
        private static void WriteTimeSpanImpl(TimeSpan timeSpan, ProtoWriter dest, DateTimeKind kind)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            long value;

            switch (dest.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
                TimeSpanScale scale;
                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;
                }

                SubItemToken token = ProtoWriter.StartSubItem(null, dest);

                if (value != 0)
                {
                    ProtoWriter.WriteFieldHeader(FieldTimeSpanValue, WireType.SignedVariant, dest);
                    ProtoWriter.WriteInt64(value, dest);
                }
                if (scale != TimeSpanScale.Days)
                {
                    ProtoWriter.WriteFieldHeader(FieldTimeSpanScale, WireType.Variant, dest);
                    ProtoWriter.WriteInt32((int)scale, dest);
                }
                if (kind != DateTimeKind.Unspecified)
                {
                    ProtoWriter.WriteFieldHeader(FieldTimeSpanKind, WireType.Variant, dest);
                    ProtoWriter.WriteInt32((int)kind, dest);
                }
                ProtoWriter.EndSubItem(token, dest);
                break;

            case WireType.Fixed64:
                ProtoWriter.WriteInt64(timeSpan.Ticks, dest);
                break;

            default:
                throw new ProtoException("Unexpected wire-type: " + dest.WireType.ToString());
            }
        }
Example #14
0
        public static void WriteTimeSpan(TimeSpan timeSpan, ProtoWriter dest)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            switch (dest.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
            {
                long          num = timeSpan.Ticks;
                TimeSpanScale timeSpanScale;
                if (timeSpan == TimeSpan.MaxValue)
                {
                    num           = 1L;
                    timeSpanScale = TimeSpanScale.MinMax;
                }
                else if (timeSpan == TimeSpan.MinValue)
                {
                    num           = -1L;
                    timeSpanScale = TimeSpanScale.MinMax;
                }
                else if (num % 864000000000L == 0L)
                {
                    timeSpanScale = TimeSpanScale.Days;
                    num          /= 864000000000L;
                }
                else if (num % 36000000000L == 0L)
                {
                    timeSpanScale = TimeSpanScale.Hours;
                    num          /= 36000000000L;
                }
                else if (num % 600000000 == 0L)
                {
                    timeSpanScale = TimeSpanScale.Minutes;
                    num          /= 600000000;
                }
                else if (num % 10000000 == 0L)
                {
                    timeSpanScale = TimeSpanScale.Seconds;
                    num          /= 10000000;
                }
                else if (num % 10000 == 0L)
                {
                    timeSpanScale = TimeSpanScale.Milliseconds;
                    num          /= 10000;
                }
                else
                {
                    timeSpanScale = TimeSpanScale.Ticks;
                }
                SubItemToken token = ProtoWriter.StartSubItem(null, dest);
                if (num != 0L)
                {
                    ProtoWriter.WriteFieldHeader(1, WireType.SignedVariant, dest);
                    ProtoWriter.WriteInt64(num, dest);
                }
                if (timeSpanScale != 0)
                {
                    ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest);
                    ProtoWriter.WriteInt32((int)timeSpanScale, dest);
                }
                ProtoWriter.EndSubItem(token, dest);
                break;
            }

            case WireType.Fixed64:
                ProtoWriter.WriteInt64(timeSpan.Ticks, dest);
                break;

            default:
                throw new ProtoException("Unexpected wire-type: " + dest.WireType);
            }
        }
Example #15
0
        public static void WriteTimeSpan(TimeSpan timeSpan, ProtoWriter dest)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            WireType wireType = dest.WireType;

            if (wireType != WireType.Fixed64)
            {
                if ((uint)(wireType - 2) <= 1u)
                {
                    long          num = timeSpan.Ticks;
                    TimeSpanScale timeSpanScale;
                    if (timeSpan == TimeSpan.MaxValue)
                    {
                        num           = 1L;
                        timeSpanScale = TimeSpanScale.MinMax;
                    }
                    else if (timeSpan == TimeSpan.MinValue)
                    {
                        num           = -1L;
                        timeSpanScale = TimeSpanScale.MinMax;
                    }
                    else if (num % 864000000000L == 0L)
                    {
                        timeSpanScale = TimeSpanScale.Days;
                        num          /= 864000000000L;
                    }
                    else if (num % 36000000000L == 0L)
                    {
                        timeSpanScale = TimeSpanScale.Hours;
                        num          /= 36000000000L;
                    }
                    else if (num % 600000000 == 0L)
                    {
                        timeSpanScale = TimeSpanScale.Minutes;
                        num          /= 600000000;
                    }
                    else if (num % 10000000 == 0L)
                    {
                        timeSpanScale = TimeSpanScale.Seconds;
                        num          /= 10000000;
                    }
                    else if (num % 10000 == 0L)
                    {
                        timeSpanScale = TimeSpanScale.Milliseconds;
                        num          /= 10000;
                    }
                    else
                    {
                        timeSpanScale = TimeSpanScale.Ticks;
                    }
                    SubItemToken token = ProtoWriter.StartSubItem(null, dest);
                    if (num != 0L)
                    {
                        ProtoWriter.WriteFieldHeader(1, WireType.SignedVariant, dest);
                        ProtoWriter.WriteInt64(num, dest);
                    }
                    if (timeSpanScale != 0)
                    {
                        ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest);
                        ProtoWriter.WriteInt32((int)timeSpanScale, dest);
                    }
                    ProtoWriter.EndSubItem(token, dest);
                    return;
                }
                wireType = dest.WireType;
                throw new ProtoException("Unexpected wire-type: " + wireType.ToString());
            }
            ProtoWriter.WriteInt64(timeSpan.Ticks, dest);
        }
Example #16
0
        public static void WriteTimeSpan(TimeSpan timeSpan, ProtoWriter dest)
        {
            TimeSpanScale timeSpanScale;

            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            switch (dest.WireType)
            {
            case WireType.Fixed64:
            {
                ProtoWriter.WriteInt64(timeSpan.Ticks, dest);
                return;
            }

            case WireType.String:
            case WireType.StartGroup:
            {
                long ticks = timeSpan.Ticks;
                if (timeSpan == TimeSpan.MaxValue)
                {
                    ticks         = (long)1;
                    timeSpanScale = TimeSpanScale.MinMax;
                }
                else if (timeSpan == TimeSpan.MinValue)
                {
                    ticks         = (long)-1;
                    timeSpanScale = TimeSpanScale.MinMax;
                }
                else if (ticks % 864000000000L == (long)0)
                {
                    timeSpanScale = TimeSpanScale.Days;
                    ticks        /= 864000000000L;
                }
                else if (ticks % 36000000000L == (long)0)
                {
                    timeSpanScale = TimeSpanScale.Hours;
                    ticks        /= 36000000000L;
                }
                else if (ticks % (long)600000000 == (long)0)
                {
                    timeSpanScale = TimeSpanScale.Minutes;
                    ticks        /= (long)600000000;
                }
                else if (ticks % (long)10000000 == (long)0)
                {
                    timeSpanScale = TimeSpanScale.Seconds;
                    ticks        /= (long)10000000;
                }
                else if (ticks % (long)10000 != (long)0)
                {
                    timeSpanScale = TimeSpanScale.Ticks;
                }
                else
                {
                    timeSpanScale = TimeSpanScale.Milliseconds;
                    ticks        /= (long)10000;
                }
                SubItemToken subItemToken = ProtoWriter.StartSubItem(null, dest);
                if (ticks != (long)0)
                {
                    ProtoWriter.WriteFieldHeader(1, WireType.SignedVariant, dest);
                    ProtoWriter.WriteInt64(ticks, dest);
                }
                if (timeSpanScale != TimeSpanScale.Days)
                {
                    ProtoWriter.WriteFieldHeader(2, WireType.Variant, dest);
                    ProtoWriter.WriteInt32((int)timeSpanScale, dest);
                }
                ProtoWriter.EndSubItem(subItemToken, dest);
                return;
            }
            }
            throw new ProtoException(string.Concat("Unexpected wire-type: ", dest.WireType.ToString()));
        }