Library for encoding using optional informational elements in a given protocol. A TLV encoded data stream contains code related to the record type, the length of the record value, and finally the value itself.
Library | Version |
---|---|
.Net core | 5.0.0 |
Example of object serialization in TLV. It is necessary to define annotations with a unique identifier in byte eg 0x01
.
public class Authorization
{
[TlvTag(Id = 0x01)]
public string Id { get; set; }
[TlvTag(Id = 0x02)]
public string Authorizer { get; set; }
[TlvTag(Id = 0x03)]
public string Operation { get; set; }
}
Obs: The type is defined in byte.
Serialization
var bufferRx = TlvSerialize.Serialize(new Authorization
{
Id = "001",
Authorizer = "CIELO",
Operation = "CREDIT"
});
Output: 010330303102054349454C4F0306435245444954
Type | Length | Value |
---|---|---|
0x01 |
3 | 303031 |
0x02 |
5 | 4349454C4F |
0x03 |
6 | 435245444954 |
Example of deserialization from TLV to object.
var content = TlvSerialize
.Deserialize<Authorization>("010330303102054349454C4F0306435245444954");
var dumpRx = TlvSerialize.Dump(new Authorization
{
Id = "001",
Authorizer = "CIELO",
Operation = "CREDIT"
});
001(003): 001
002(005): CIELO
003(006): CREDIT
var dump = TlvSerialize
.Dump("010330303102054349454C4F0306435245444954");
001(003): 001
002(005): CIELO
003(006): CREDIT