TlvDecoder
com.rvi.application.TlvDecoder · Class · SocialCard 1.0.3
Read an NDEF message from its Type 2 Tag TLV wrapper.
When to use it
Section titled “When to use it”Use decode(bytes) when you have a complete buffer that begins with an NDEF TLV. Use encodedLength(headerBytes) with the first bytes of tag memory to determine how much more data to read.
Java example
Section titled “Java example”final NDefMessage message = new NDefEncoder().encodeURI("https://rithush.dev");final byte[] tlv = new TlvEncoder().encode(message);final int length = new TlvDecoder().encodedLength(Arrays.copyOf(tlv, 2));
System.out.println(length == tlv.length); // true for this short TLVSystem.out.println(new TlvDecoder().decode(tlv).equals(message)); // trueJava imports
import com.rvi.application.NDefEncoder;import com.rvi.application.TlvDecoder;import com.rvi.application.TlvEncoder;import com.rvi.domain.NDefMessage;import java.util.Arrays;A short length field needs two header bytes. When byte 1 is 0xFF, supply the full four-byte header.
How it works
Section titled “How it works”encodedLength() returns the header plus declared value plus one byte for the terminator. It needs only a complete header. decode() checks that the declared bytes and terminator exist, rejects empty values and passes the extracted NDEF bytes to NDefMessage for structural validation.