티스토리 뷰

etc

cbor

shannon. 2022. 12. 24. 02:02
반응형

https://www.rfc-editor.org/rfc/rfc7049

https://libcbor.readthedocs.io/en/v0.8.0/getting_started.html

 

Getting started — libcbor 0.8.0 documentation

For other platforms, you will need to compile it from source. Troubleshooting cbor.h not found: The headers directory is probably not in your include path. First, verify the installation location by checking the installation log. If you used make, it will

libcbor.readthedocs.io

 

 

json compact version

reduce the size a lot

install on ubuntu 18.04 -> sudo apt-get install -y libcbor-dev

 
Appendix C.  Pseudocode

   The well-formedness of a CBOR item can be checked by the pseudocode
   in Figure 1.  The data is well-formed if and only if:

   o  the pseudocode does not "fail";

   o  after execution of the pseudocode, no bytes are left in the input
      (except in streaming applications)

   The pseudocode has the following prerequisites:

   o  take(n) reads n bytes from the input data and returns them as a
      byte string.  If n bytes are no longer available, take(n) fails.

   o  uint() converts a byte string into an unsigned integer by
      interpreting the byte string in network byte order.

   o  Arithmetic works as in C.

   o  All variables are unsigned integers of sufficient range.
well_formed (breakable = false) {
     // process initial bytes
     ib = uint(take(1));
     mt = ib >> 5;
     val = ai = ib & 0x1f;
     switch (ai) {
       case 24: val = uint(take(1)); break;
       case 25: val = uint(take(2)); break;
       case 26: val = uint(take(4)); break;
       case 27: val = uint(take(8)); break;
       case 28: case 29: case 30: fail();
       case 31:
         return well_formed_indefinite(mt, breakable);
     }
     // process content
     switch (mt) {
       // case 0, 1, 7 do not have content; just use val
       case 2: case 3: take(val); break; // bytes/UTF-8
       case 4: for (i = 0; i < val; i++) well_formed(); break;
       case 5: for (i = 0; i < val*2; i++) well_formed(); break;
       case 6: well_formed(); break;     // 1 embedded data item
     }
     return mt;                    // finite data item
   }

   well_formed_indefinite(mt, breakable) {
     switch (mt) {
       case 2: case 3:
         while ((it = well_formed(true)) != -1)
           if (it != mt)           // need finite embedded
             fail();               //    of same type
         break;
       case 4: while (well_formed(true) != -1); break;
       case 5: while (well_formed(true) != -1) well_formed(); break;
       case 7:
         if (breakable)
           return -1;              // signal break out
         else fail();              // no enclosing indefinite
       default: fail();            // wrong mt
     }
     return 0;                     // no break out
   }

              Figure 1: Pseudocode for Well-Formedness Check

   Note that the remaining complexity of a complete CBOR decoder is
   about presenting data that has been parsed to the application in an
   appropriate form.
반응형

'etc' 카테고리의 다른 글

jvm setting flag 의미  (0) 2023.03.09
CAmkES / RISC-V/ ARM  (0) 2022.12.28
eng study  (0) 2022.12.24
영어 email 끝맫음 표현  (0) 2022.11.07
timeseries DB  (0) 2022.10.13
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함