Feature #4722
closedBlock literal
100%
Description
Block literal allows creating a Block
with a simple syntax like "0703 080141"_block
.
It is a useful feature and should be exposed to callers outside of ndn-cxx tests.
Updated by Junxiao Shi over 6 years ago
- Status changed from In Progress to Code review
- % Done changed from 0 to 100
https://gerrit.named-data.net/#/c/ndn-cxx/+/4926 moves block literal operator and adds unit testing.
Updated by Davide Pesavento over 6 years ago
- Status changed from Code review to Closed
Updated by Ju Pan over 5 years ago
A stupid question, how should I generate the input for _block operator?
For "0703 080141"_block,
How should I generate "0703 080141"
Updated by Junxiao Shi over 5 years ago
For
"0703 080141"_block,
How should I generate "0703 080141"
These are handwritten according to packet format.
Every L2 developer should learn to read and write common packets in hexadecimal.
Updated by Alex Afanasyev over 5 years ago
Junxiao, please try to more considerate statements.
@Ju, as Junxiao mentioned, one way is to do it by hand. If you want to just fix encoding of a certain block, you can write a small for loop that will print out values to std::cout/cerr and then you copy/paste. We used to have such for loops (commented out) in some of the test cases, but not sure if we still have.
Updated by Ju Pan over 5 years ago
Alex Afanasyev wrote:
Junxiao, please try to more considerate statements.
@Ju, as Junxiao mentioned, one way is to do it by hand. If you want to just fix encoding of a certain block, you can write a small for loop that will print out values to std::cout/cerr and then you copy/paste. We used to have such for loops (commented out) in some of the test cases, but not sure if we still have.
Hey Alex, thanks for the explanation. Yes, there is a for loop to generate the plain hex (now sure if you are talking about this one):
for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
printf("0x%02x", *it);
}
but according to Juxiao's code review:
There's a guideline about improving readability. Whether you use block literal or HEX, I need to see comments about TLV structure:
- label every TLV-TYPE
- indent nested TLV
It seems we still need to handwrite the encoding according to the packet format for the formatting. Not sure if I understand it correctly.
Updated by Davide Pesavento over 5 years ago
@Ju, I would suggest to manually edit the existing hex array. Just add the new field, adjust the length of affected TLVs, and that's it. And write the corresponding TLV type in a comment next to the element's hex representation, to make Junxiao happy.
Updated by Ju Pan over 5 years ago
Davide Pesavento wrote:
@Ju, I would suggest to manually edit the existing hex array. Just add the new field, adjust the length of affected TLVs, and that's it. And write the corresponding TLV type in a comment next to the element's hex representation, to make Junxiao happy.
@Davide, thanks for the suggestion, I've changed the code.