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); }
public void Write(object value, [NotNull] IWireStreamWriterStrategy dest) { DecoratedSerializer.Write(value, dest); }