Skip to content

TU-Darmstadt-APQ/Library-Arduino-Cbor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CBOR-CPP

CBOR C++ serialization library

Just a simple SAX-like Concise Binary Object Representation (CBOR).

http://tools.ietf.org/html/rfc7049

Examples

Writing:

  CborDynamicOutput output;
  CborWriter writer(output);

  writer.writeTag(123);
  writer.writeArray(3);
  writer.writeString("hello");
  writer.writeString("world");
  writer.writeInt(321);

  unsigned char *data = output.getData();
  size_t size = output.getSize();

Reading:

  class CborExampleListener : public CborListener {
  public:
    virtual void OnInteger(const int32_t value);
    virtual void OnByteString(char *data, const size_t size);
    virtual void OnTextString(char *data, const size_t size);
    virtual void OnArray(const size_t size);
    virtual void OnMap(const size_t size);
    virtual OnTag(const uint32_t tag);
    virtual void OnError(const CborError error);
  };

  ...

  void CborExampleListener::OnInteger(const int32_t value) {
    printf("Integer: %d\n", value);
  }

  void CborExampleListener::OnByteString(char *data, const size_t size) {
    printf("Byte string of size: %d", size);
  }

  void CborExampleListener::OnTextString(char *data, const size_t size) {
    printf("UTF-8 string of size: %d", size);
  }

  void CborExampleListener::OnArray(const size_t size) {
    printf("Array of size: %d\n", size);
  }

  void CborExampleListener::OnMap(const size_t size) {
    printf("Map of size: %d\n", size);
  }

  void CborExampleListener::OnTag(const uint32_t tag) {
    printf("Tag: %d\n", tag);
  }

  void CborExampleListener::OnError(const CborError error) {
    // Do something with the error enums
  }
  
  ...
  CborExampleListener listener;
  CborReader reader(&listener);
  reader.Run(data, size);
  ...
  // run again later with new data
  reader.Run(data, size);

About

Arduino Library to use Cbor encoder and several examples to use

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%