public sealed override void Write(string value, Span <byte> buffer, ref int offset)
        {
            //WARNING: Doing use this calculated string length in ANYTHING but writing, it may contain adjusted sizes.
            //We must write the length prefix first into the buffer
            int stringLength = CalculateOutgoingStringLength(value);

            stringLength++;             //add terminator character
            GenericTypePrimitiveSerializerStrategy <TLengthType> .Instance.Write(stringLength.Reinterpret <int, TLengthType>(), buffer, ref offset);

            int expectedByteLength = value.Length * MaximumCharacterSize;
            int lastOffset         = offset;

            DecoratedSerializer.Write(value, buffer.Slice(0, expectedByteLength + offset), ref offset);

            //TODO: This is a COMPLETE hack that should be toggleable honestly.
            //This isn't *really* how we should handle variable length encodings and stuff, but PSOBB does fixed-length UTF16 for fixed/known size
            //So to compensate for this we adjust the buffer offset to pretend we're fixed-length
            if (offset != lastOffset + expectedByteLength)
            {
                while (offset < lastOffset + expectedByteLength)
                {
                    GenericTypePrimitiveSerializerStrategy <byte> .Instance.Write(0, buffer, ref offset);
                }
            }

            //Now we can write terminator
            DecoratedTerminatorStrategy.Write(value, buffer, ref offset);
        }
Esempio n. 2
0
        public sealed override string Read(Span <byte> buffer, ref int offset)
        {
            int length = CalculateIncomingStringLength(buffer, ref offset);

            if (length == 0 || length < MaximumCharacterSize)
            {
                return(String.Empty);
            }

            //Read until terminator is found, then we skip over terminator in the buffer.
            //Slice just incase invalid data and terminator isn't there.
            string value = DecoratedSerializer.Read(buffer.Slice(0, (length) * MaximumCharacterSize + offset), ref offset);

            return(value);
        }
 public Task <TType> ReadAsync([NotNull] IWireStreamReaderStrategyAsync source)
 {
     return(DecoratedSerializer.ReadAsync(source));
 }
 public TType Read([NotNull] IWireStreamReaderStrategy source)
 {
     return(DecoratedSerializer.Read(source));
 }
 public Task ObjectIntoWriterAsync([CanBeNull] object obj, [NotNull] IWireStreamWriterStrategyAsync dest)
 {
     return(DecoratedSerializer.ObjectIntoWriterAsync(obj, dest));
 }
 public void ObjectIntoWriter([CanBeNull] object obj, [NotNull] IWireStreamWriterStrategy dest)
 {
     DecoratedSerializer.ObjectIntoWriter(obj, dest);
 }
 public byte[] GetBytes([NotNull] object obj)
 {
     return(DecoratedSerializer.GetBytes(obj));
 }
 public TType FromBytes([NotNull] byte[] bytes)
 {
     return(DecoratedSerializer.FromBytes(bytes));
 }
 async Task <object> ITypeSerializerStrategyAsync.ReadAsync(IWireStreamReaderStrategyAsync source)
 {
     return(await DecoratedSerializer.ReadAsync(source)
            .ConfigureAwait(false));
 }
 object ITypeSerializerStrategy.Read(IWireStreamReaderStrategy source)
 {
     return(DecoratedSerializer.Read(source));
 }
 object IObjectByteReader.FromBytes(byte[] bytes)
 {
     return(DecoratedSerializer.FromBytes(bytes));
 }
 public Task WriteAsync(object value, [NotNull] IWireStreamWriterStrategyAsync dest)
 {
     return(DecoratedSerializer.WriteAsync(value, dest));
 }
 public void Write(object value, [NotNull] IWireStreamWriterStrategy dest)
 {
     DecoratedSerializer.Write(value, dest);
 }
 public Task <object> ReadIntoObjectAsync([CanBeNull] object obj, [NotNull] IWireStreamReaderStrategyAsync source)
 {
     return(DecoratedSerializer.ReadIntoObjectAsync(obj, source));
 }
 public object ReadIntoObject([CanBeNull] object obj, [NotNull] IWireStreamReaderStrategy source)
 {
     return(DecoratedSerializer.ReadIntoObject(obj, source));
 }