mirror of
https://github.com/fbarresi/Sharp7.git
synced 2025-12-15 11:52:52 +00:00
@@ -1,6 +1,12 @@
|
||||
# Change Log
|
||||
All notable changed to this project will be documented in this file.
|
||||
|
||||
## [1.1.82] - 18.05.2022
|
||||
### Added
|
||||
### Changed
|
||||
### Fixed
|
||||
- Fixed string length check into SetStringAt [#28](https://github.com/fbarresi/Sharp7/issues/28)
|
||||
|
||||
## [1.1.81] - 18.05.2022
|
||||
### Added
|
||||
### Changed
|
||||
|
||||
@@ -337,11 +337,12 @@ namespace Sharp7.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("888", new byte[] {200, 3, 56,56,56})]
|
||||
public void TestSetStringAt(string test, byte[] expected)
|
||||
[InlineData("888", 200, new byte[] {200, 3, 56,56,56})]
|
||||
[InlineData("888888", 5, new byte[] {5, 5, 56,56,56,56,56})]
|
||||
public void TestSetStringAt(string test, int maxLength, byte[] expected)
|
||||
{
|
||||
var buffer = new byte[200];
|
||||
S7.SetStringAt(buffer, 0, buffer.Length, test);
|
||||
var buffer = new byte[maxLength+2];
|
||||
S7.SetStringAt(buffer, 0, maxLength, test);
|
||||
buffer.Take(expected.Length).ToArray().ShouldBe(expected);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Sharp7
|
||||
@@ -615,10 +616,12 @@ namespace Sharp7
|
||||
|
||||
public static void SetStringAt(this byte[] buffer, int pos, int MaxLen, string value)
|
||||
{
|
||||
int size = value.Length;
|
||||
int length = value.Length;
|
||||
// checking current length against MaxLen
|
||||
if (length > MaxLen) length = MaxLen;
|
||||
buffer[pos] = (byte) MaxLen;
|
||||
buffer[pos + 1] = (byte) size;
|
||||
Encoding.UTF8.GetBytes(value, 0, size, buffer, pos + 2);
|
||||
buffer[pos + 1] = (byte) length;
|
||||
Encoding.UTF8.GetBytes(value, 0, length, buffer, pos + 2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user