MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / duration_example1

Function duration_example1

examples/src/cbor_examples.cpp:542–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

540}
541
542void 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
562void duration_example2()
563{

Callers 1

mainFunction · 0.70

Calls 3

encode_cborFunction · 0.85
byte_string_viewClass · 0.85
countMethod · 0.45

Tested by

no test coverage detected