WEBVTT

00:04.950 --> 00:10.500
So guys, continuing from the previous lecture video, here is one more example of the Tlv.

00:10.920 --> 00:15.480
Now here you can see that each Tlv can carry multiple values.

00:15.480 --> 00:16.170
Right?

00:16.170 --> 00:18.660
So while passing this tlv buffer.

00:18.690 --> 00:26.190
Now note that the contiguous chunk of memory which contains all the tlvs packed together is called tlv

00:26.190 --> 00:26.810
buffer.

00:26.820 --> 00:31.770
So these portion of memory is nothing, but it is called tlv buffer.

00:31.770 --> 00:32.520
Right.

00:32.520 --> 00:36.720
And it is contiguous straight flat chunk of memory.

00:37.370 --> 00:39.260
Now, how would you know that?

00:39.260 --> 00:43.700
Whether there are two units of values present in the value part of this Tlv.

00:44.210 --> 00:45.530
It's simple.

00:45.650 --> 00:53.120
You know that the type of the Tlv is one, and by definition whenever the type of the Tlv is one, it

00:53.120 --> 01:00.370
means that the data type of the value is a string as well as the length of one unit of data is 32 bytes.

01:00.380 --> 01:03.450
So here the length is specified as 64 bytes.

01:03.470 --> 01:09.500
When you divide this length value by one unit of data, you will get two, right?

01:09.500 --> 01:12.980
So 64 divided by 32 is equal to two.

01:13.010 --> 01:21.710
It simply means that the the value portion of this Tlv contains two strings, each of 32 bytes.

01:22.160 --> 01:26.570
And the same applies to the second Tlv as well as the third tlv.

01:27.170 --> 01:34.310
So this is how you read the Tlv by dividing the length of the value portion of this tlv by the size

01:34.310 --> 01:37.470
of one unit of data of this tlv.

01:37.830 --> 01:42.660
Now let us try to write a program regarding how would you parse this tlv?

01:42.930 --> 01:43.530
Right.

01:43.530 --> 01:49.460
So for example, let us suppose that I give you a pointer which points to the very start of this tlv

01:49.470 --> 01:52.830
buffer and the total size of this buffer.

01:52.830 --> 01:55.920
Let's say that it is 222 bytes.

01:57.220 --> 02:00.310
So how were you going to read the type field of this Tlv?

02:00.880 --> 02:06.970
You can read the type field of the Tlv by simply type casting the first byte of this tlv buffer into

02:06.970 --> 02:13.090
the unsigned int eight byte of data type and the length of the first tlv.

02:13.120 --> 02:17.650
You can obtained by incrementing the pointer of the tlv buffer by one.

02:17.680 --> 02:21.820
That is, you are reading one byte of the data starting from this pointer.

02:21.820 --> 02:22.570
Right?

02:22.570 --> 02:29.230
So it's a simple pointer arithmetic and the number of units which is packed in the value field of this

02:29.230 --> 02:33.070
Tlv can be obtained by dividing the total length of the Tlv.

02:33.100 --> 02:37.750
That is this value by the size of the unit data of this Tlv.

02:37.990 --> 02:43.900
So you can always write a function which takes an argument the type of the tlv and depending on the

02:43.900 --> 02:48.490
type of the Tlv, you can always return the size of unit data of this tlv.

02:49.000 --> 02:49.840
Right.

02:49.870 --> 02:56.830
So here you can see that I'm simply dividing the total length of this tlv by the size of unit data of

02:56.930 --> 02:57.560
this tlv.

02:57.800 --> 02:58.400
Right.

02:58.400 --> 03:03.540
So in this case I will get the number of units which is packed in this tlv value.

03:03.560 --> 03:05.960
So in this case it will return to.

03:06.580 --> 03:13.300
And following that, I can simply read the first name and then I can start a loop depending on the number

03:13.300 --> 03:19.980
of units and I can read all the names which are packaged in this value part of this.

03:19.990 --> 03:21.610
Tlv Right.

03:22.410 --> 03:28.980
And once we have read all the values which are present in the value part of this Tlv, we need to start

03:28.980 --> 03:30.990
reading the next Tlv from the beginning.

03:30.990 --> 03:37.470
So the TLB buffer pointer which was pointing to the start of the Tlv needs to be adjusted to the to

03:37.470 --> 03:39.360
point to the start of the second tlv.

03:39.600 --> 03:46.710
It is for this reason that we will increment the tlv buffer by size equal to the length of this tlv.

03:47.430 --> 03:52.230
And also you have to consider the tlv overhead also, which is two bytes.

03:53.040 --> 03:56.580
And after that we can start reading on to the next.

03:57.000 --> 04:02.130
Because our tlv buffer now points to the start of the second tlv right.

04:02.160 --> 04:09.810
So always you need to take a caution that you don't overshoot the TLB buffer and track how much buffer

04:09.810 --> 04:14.910
you have scanned so far, starting from the beginning to the end of the Tlv buffer.

04:14.910 --> 04:15.540
Right.

04:15.570 --> 04:21.300
Don't overshoot the tlv buffer, otherwise it will lead to memory, corruption or segmentation fault.

04:21.390 --> 04:24.340
So there is an assignment following this lecture video.

04:24.340 --> 04:25.780
Please do the assignment.

04:25.780 --> 04:32.230
In that assignment we will going to develop an easy way to parse the Tlv without having to worry about

04:32.230 --> 04:36.490
jumping the pointer from here to there within a buffer.
