Skip to content

Commit

Permalink
create a convenience method on the header class
Browse files Browse the repository at this point in the history
  • Loading branch information
SiuTung08 committed Nov 11, 2024
1 parent df43364 commit 227d475
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/NATS.Client.Core/NatsHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ public void CopyTo(KeyValuePair<string, StringValues>[] array, int arrayIndex)
}
}

/// <summary>
/// Returns the bytes length of the header
/// </summary>
/// <param name="headerWriter">an instance of headerWriter</param>
/// <returns>bytes length of th header</returns>
public long GetBytesLength(HeaderWriter headerWriter)
{
return headerWriter.GetBytesLength(this);
}

/// <summary>
/// Removes the given item from the the collection.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion tests/NATS.Client.CoreUnit.Tests/NatsHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void GetBytesLengthTest()
["key"] = "a-long-header-value",
};
var writer = new HeaderWriter(Encoding.UTF8);
var bytesLength = writer.GetBytesLength(headers);
var bytesLength = headers.GetBytesLength(writer);

var text = "NATS/1.0\r\nk1: v1\r\nk2: v2-0\r\nk2: v2-1\r\na-long-header-key: value\r\nkey: a-long-header-value\r\n\r\n";
var expected = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(text));
Expand Down

0 comments on commit 227d475

Please sign in to comment.