Skip to content

Commit

Permalink
Add overloads for GetBuffer(..) and SetBuffer(..) that take an explic…
Browse files Browse the repository at this point in the history
…it offset and length. (#394)
  • Loading branch information
timyhac authored Jul 11, 2024
1 parent 66e12d8 commit c18df56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/libplctag/NativeTagWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,14 @@ public Status GetStatus()
}

public void GetBuffer(byte[] buffer)
{
GetBuffer(0, buffer, buffer.Length);
}

public void GetBuffer(int offset, byte[] buffer, int length)
{
ThrowIfAlreadyDisposed();
var result = (Status)_native.plc_tag_get_raw_bytes(nativeTagHandle, 0, buffer, buffer.Length);
var result = (Status)_native.plc_tag_get_raw_bytes(nativeTagHandle, offset, buffer, length);
ThrowIfStatusNotOk(result);
}

Expand All @@ -551,14 +556,21 @@ public byte[] GetBuffer()
}

public void SetBuffer(byte[] buffer)
{
SetBuffer(0, buffer, buffer.Length);
}

public void SetBuffer(int start_offset, byte[] buffer, int length)
{
ThrowIfAlreadyDisposed();

GetNativeValueAndThrowOnNegativeResult(_native.plc_tag_set_size, buffer.Length);
var result = (Status)_native.plc_tag_set_raw_bytes(nativeTagHandle, 0, buffer, buffer.Length);
var result = (Status)_native.plc_tag_set_raw_bytes(nativeTagHandle, start_offset, buffer, length);
ThrowIfStatusNotOk(result);
}



private int GetIntAttribute(string attributeName)
{
var result = _native.plc_tag_get_int_attribute(nativeTagHandle, attributeName, int.MinValue);
Expand Down
12 changes: 11 additions & 1 deletion src/libplctag/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,17 @@ public uint? MaxRequestsInFlight
/// Use this instead of <see cref="GetBuffer()"/> to avoid creating a new block of memory.
/// </remarks>
public void GetBuffer(byte[] buffer) => _tag.GetBuffer(buffer);
public void SetBuffer(byte[] newBuffer) => _tag.SetBuffer(newBuffer);

/// <summary>
/// Fills the supplied buffer with the raw, unprocessed bytes from the tag buffer.
/// </summary>
/// <remarks>
/// Use this instead of <see cref="GetBuffer()"/> to avoid creating a new block of memory.
/// </remarks>
public void GetBuffer(int offset, byte[] buffer, int length) => _tag.GetBuffer(offset, buffer, length);

public void SetBuffer(byte[] newBuffer) => _tag.SetBuffer(newBuffer);
public void SetBuffer(int offset, byte[] buffer, int length) => _tag.SetBuffer(offset, buffer, length);

/// <summary>
/// This function retrieves an attribute of the raw tag byte array.
Expand Down

0 comments on commit c18df56

Please sign in to comment.