| 540 | } |
| 541 | |
| 542 | void duration_example1() |
| 543 | { |
| 544 | auto duration = std::chrono::system_clock::now().time_since_epoch(); |
| 545 | auto time = std::chrono::duration_cast<std::chrono::seconds>(duration); |
| 546 | |
| 547 | std::vector<uint8_t> data; |
| 548 | cbor::encode_cbor(time, data); |
| 549 | |
| 550 | /* |
| 551 | c1, // Tag 1 (epoch time) |
| 552 | 1a, // 32 bit unsigned integer |
| 553 | 5f,23,29,18 // 1596139800 |
| 554 | */ |
| 555 | |
| 556 | std::cout << "CBOR bytes:\n" << jsoncons::byte_string_view(data) << "\n\n"; |
| 557 | |
| 558 | auto seconds = cbor::decode_cbor<std::chrono::seconds>(data); |
| 559 | std::cout << "Time since epoch (seconds): " << seconds.count() << "\n"; |
| 560 | } |
| 561 | |
| 562 | void duration_example2() |
| 563 | { |
no test coverage detected