public override StreamElement Deserialize(StreamElement reuse, IDataInputView source)
        {
            int tag = source.ReadByte();

            if (tag == TagRecWithTimestamp)
            {
                var timestamp   = source.ReadLong();
                var value       = ContainedTypeSerializer.Deserialize(source);
                var reuseRecord = reuse.AsRecord <T>();
                reuseRecord.Replace(value, timestamp);
                return(reuseRecord);
            }
            else if (tag == TagRecWithoutTimestamp)
            {
                var value       = ContainedTypeSerializer.Deserialize(source);
                var reuseRecord = reuse.AsRecord <T>();
                reuseRecord.Replace(value);
                return(reuseRecord);
            }
            else if (tag == TagWatermark)
            {
                return(new Watermark(source.ReadLong()));
            }
            else if (tag == TagLatencyMarker)
            {
                return(new LatencyMarker(source.ReadLong(), new OperatorId(source.ReadLong(), source.ReadLong()), source.ReadInt()));
            }
            else
            {
                throw new IOException("Corrupt stream, found tag: " + tag);
            }
        }
        public override void Serialize(StreamElement value, IDataOutputView target)
        {
            if (value.IsRecord)
            {
                var record = value.AsRecord <T>();

                if (record.HasTimestamp)
                {
                    target.Write(TagRecWithTimestamp);
                    target.WriteLong(record.Timestamp);
                }
                else
                {
                    target.Write(TagRecWithoutTimestamp);
                }

                ContainedTypeSerializer.Serialize(record.Value, target);
            }
            else if (value.IsWatermark)
            {
                target.Write(TagWatermark);
                target.WriteLong(value.AsWatermark().Timestamp);
            }
            else if (value.IsStreamStatus)
            {
                target.Write(TagStreamStatus);
                target.WriteInt(value.AsStreamStatus().Status);
            }
            else if (value.IsLatencyMarker)
            {
                target.Write(TagLatencyMarker);
                target.WriteLong(value.AsLatencyMarker().MarkedTime);
                target.WriteLong(value.AsLatencyMarker().OperatorId.LowerPart);
                target.WriteLong(value.AsLatencyMarker().OperatorId.UpperPart);
                target.WriteInt(value.AsLatencyMarker().SubTaskIndex);
            }
            else
            {
                throw new RuntimeException();
            }
        }
 public override StreamElement Copy(StreamElement @from, StreamElement reuse)
 {
     throw new NotImplementedException();
 }