WriteNestedTlv Method
WriteNestedTlv(Int32)
Start a new Nested TLV.
public TlvWriter.TlvScope WriteNestedTlv(int tag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | tag | The tag that will be written out when encoding the TLV. |
Returns
Remarks
The way the caller is supposed to build Nested schemas using TlvWriter is as follows.
var writer = new TlvWriter();
using (writer.WriteNestedTlv(tag0))
{
writer.WriteValue(tag1, element1);
writer.WriteValue(tag2, element2);
}
byte[] encoding = tlvWriter.Encode();
The using directive in this case means that when the variable goes out of scope, the Dispose method will be called immediately. Furthermore, when written this way (with the curly braces), the variable goes out of scope upon completion of the close curly brace.
The WriteNestedTlv method returns an instance of TlvWriter.TlvScope. So in the above construction, the variable for which the using is constructed is the TlvWriter.TlvScope returned by the method.
Normally, a Dispose method overwrites sensitive data or releases
resources (files, internet connections, etc.). However, the Dispose in
this class simply makes sure the Nested TLV is closed. Any new calls to
Write
will apply to the next level up.
There are certain calls you can make only after a schema has been completely entered. To be completely entered means the outermost Nested TLV has been closed (the closing curly brace).