---
name: "tlv_encode"
section: "3"
platform: "linux"
package: "libfreefare-doc"
version: "0.4.0-2.3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/tlv"
---

# tlv\_encode(3)

TLV Manipulation Functions

Part of [tlv(3)](/tlv/3.md).

## NAME

**tlv\_encode**, **tlv\_decode** – TLV Manipulation Functions

## LIBRARY

Mifare card manipulation library (libfreefare, -lfreefare)

## SYNOPSIS

**#include \<freefare.h\>**

*uint8\_t \**\

**tlv\_encode**(*const uint8\_t type*, *const uint8\_t \*istream*, *uint16\_t isize*, *size\_t \*osize*);

*uint8\_t \**\

**tlv\_decode**(*const uint8\_t \*istream*, *uint8\_t \*type*, *uint16\_t \*size*);

## DESCRIPTION

The **tlv\_encode**() and **tlv\_decode**() functions are helpers to manipulate TLV (Text-Length-Value) data.

The **tlv\_encode**() function converts the *isize* bytes long *istream* message into a TLV stream of type *type* and set the value of *osize* to the length of the returned stream.

The **tlv\_decode**() function converts the *istream* TLV stream and set the *type* argument according to the type of the stream, and set the *size* argument to the length of the returned stream.

## RETURN VALUES

Both functions return memory allocated using [malloc(3)](/malloc/3.md) which should be reclaimed using [free(3)](/free/3.md) after usage.

## SEE ALSO

[freefare(3)](/freefare/3.md), [malloc(3)](/malloc/3.md), [free(3)](/free/3.md)

## AUTHORS

Romain Tartiere ⟨romain@blogreen.org⟩ Romuald Conty ⟨romuald@libnfc.org⟩
