Exemple #1
0
        public override void Serialize(IPackStreamWriter writer, object value)
        {
            var msg = value.CastOrThrow <HelloMessage>();

            writer.WriteStructHeader(1, MsgHello);
            writer.Write(msg.MetaData);
        }
        public void Write(IPackStreamWriter writer, object value)
        {
            var point = value.CastOrThrow <CypherPoint>();

            switch (point.Dimension)
            {
            case CypherPoint.TwoD:
            {
                writer.WriteStructHeader(Point2DStructSize, Point2DStructType);
                writer.Write(point.SrId);
                writer.Write(point.X);
                writer.Write(point.Y);

                break;
            }

            case CypherPoint.ThreeD:
            {
                writer.WriteStructHeader(Point3DStructSize, Point3DStructType);
                writer.Write(point.SrId);
                writer.Write(point.X);
                writer.Write(point.Y);
                writer.Write(point.Z);

                break;
            }

            default:
                throw new ProtocolException(
                          $"{GetType().Name}: Dimension('{point.Dimension}') is not supported.");
            }
        }
Exemple #3
0
                public void Write(IPackStreamWriter writer, object value)
                {
                    var structValue = (StructType)value;

                    writer.WriteStructHeader(structValue.Values.Count, (byte)'S');
                    foreach (var innerValue in structValue.Values)
                    {
                        writer.Write(innerValue);
                    }
                }
Exemple #4
0
        public void Write(IRequestMessage message)
        {
            _chunkWriter.OpenChunk();
            _packStreamWriter.Write(message);
            _chunkWriter.CloseChunk();

            // add message boundary
            _chunkWriter.OpenChunk();
            _chunkWriter.CloseChunk();
        }
Exemple #5
0
        public override void Serialize(IPackStreamWriter writer, object value)
        {
            var dateTime = value.CastOrThrow <DateTime>();

            switch (dateTime.Kind)
            {
            case DateTimeKind.Local:
            case DateTimeKind.Unspecified:
                writer.Write(new LocalDateTime(dateTime));
                break;

            case DateTimeKind.Utc:
                writer.Write(new ZonedDateTime(dateTime, 0));
                break;

            default:
                throw new ProtocolException(
                          $"Unsupported DateTimeKind {dateTime.Kind} passed to {nameof(SystemDateTimeSerializer)}!");
            }
        }
        public override void Serialize(IPackStreamWriter writer, object value)
        {
            var time = value.CastOrThrow <TimeSpan>();

            if (time.Ticks < 0 || time.Ticks >= TimeSpan.TicksPerDay)
            {
                throw new ProtocolException(
                          $"TimeSpan instance ({time}) passed to {nameof(SystemDateTimeSerializer)} is not a valid time of day!");
            }

            writer.Write(new LocalTime(time));
        }
        public void Serialize(IPackStreamWriter writer, object value)
        {
            var dateTime = value.CastOrThrow <ZonedDateTime>();

            switch (dateTime.Zone)
            {
            case ZoneId zone:
                writer.WriteStructHeader(StructSize, StructTypeWithId);
                writer.Write(dateTime.ToEpochSeconds());
                writer.Write(dateTime.Nanosecond);
                writer.Write(zone.Id);
                break;

            case ZoneOffset zone:
                writer.WriteStructHeader(StructSize, StructTypeWithOffset);
                writer.Write(dateTime.ToEpochSeconds());
                writer.Write(dateTime.Nanosecond);
                writer.Write(zone.OffsetSeconds);
                break;

            default:
                throw new ProtocolException(
                          $"{GetType().Name}: Zone('{dateTime.Zone.GetType().Name}') is not supported.");
            }
        }
        private static void SerializePath(IPackStreamWriter writer, bool reverse = false)
        {
            writer.WriteStructHeader(3, PathSerializer.Path);

            writer.WriteListHeader(3);
            for (var i = 0; i < 3; i++)
            {
                SerializeNode(writer, i + 1);
            }

            writer.WriteListHeader(3);
            SerializeUnboundedRelationship(writer, 4);
            SerializeUnboundedRelationship(writer, 5);
            SerializeUnboundedRelationship(writer, 6);

            writer.WriteListHeader(6);
            writer.Write(1 * (reverse ? -1 : 1));
            writer.Write(1);
            writer.Write(2 * (reverse ? -1 : 1));
            writer.Write(2);
            writer.Write(3 * (reverse ? -1 : 1));
            writer.Write(0);
        }
Exemple #9
0
        public override void Write(IPackStreamWriter writer, object value)
        {
            var dateTime = value.CastOrThrow <DateTimeOffset>();

            writer.Write(new ZonedDateTime(dateTime));
        }