Esempio n. 1
0
        public static async Task WriteString(this Stream stream, string value, int length, byte fillByte = 0)
        {
            var bytes = LittleEndianConverter.ConvertToIso88591Bytes(value.Length > length
                ? value.Substring(0, length)
                : value);

            await stream.WriteBytes(bytes);

            if (bytes.Length < length)
            {
                var fillBytes = new byte[length - bytes.Length];
                for (var i = 0; i < fillBytes.Length; i++)
                {
                    fillBytes[i] = fillByte;
                }
                await stream.WriteBytes(fillBytes);

                // var zeroFilledBytes = new MemoryStream(new byte[length]);
                // await zeroFilledBytes.WriteBytes(bytes);
                // bytes = zeroFilledBytes.ToArray();
            }
        }