🗒️
notes
  • Journal
  • URLs
  • Java Card
    • SCP02
    • Rapid Notes
    • _FIXVALS_
    • Mifare
    • Chain Of Trust
  • Encoding
    • CBEFF
    • Bytes
  • Snippets
    • JNI_OnLoad
  • float to byte[]
  • Protobuf
  • C/C++
    • Containers
    • Basics
    • JNI
    • gcov
    • Castings
  • chess
    • Untitled
  • Compression
    • Untitled
  • Snippets
    • Untitled
  • Build Systems
    • Maven
    • Windows
  • Gradle
  • CMake
  • Java
    • Untitled
    • Certificates
  • Android
    • Mifare
  • Python
    • ctypes
  • WebSub
    • References
  • Spring Boot
    • Form-based Authentication
    • Basic Access Authentication
    • JWT Authentication
  • QR Code
    • Denso QR Code
  • Philosophical Inquiry
    • First
  • XML
    • xmlstarlet
Powered by GitBook
On this page

Was this helpful?

Protobuf

Convert stuff.proto to stuff.proto.jar , open bash shell and run:

protoc -I=proto/ --java_out=build/protogen/ proto/stuff.proto
javac -cp jars/protobuf-java-3.11.4.jar build/protogen/org/stuff/proto/*.java
jar cvf build/stuff.proto.jar -C build/protogen/ org

Needed executables: protoc, javac and jar

Check protoc --version is compatible to protobuf-java jar.

Illustrative example:

void kv_pair_test()
{
    idpass::Dictionary d;
    idpass::Pair* p = d.add_pairs();
    p->set_key("gender");
    p->set_value("male");

    idpass::Pair q;
    q.set_key("color");
    q.set_value("red");

    d.mutable_pairs()->AddAllocated(&q);
    int buf_len = d.ByteSizeLong();
    std::cout << buf_len;
    unsigned char* buf = new unsigned char[buf_len];
    d.SerializeToArray(buf, buf_len);

    std::cout << buf;
    idpass::Dictionary dd;
    assert(dd.ParseFromArray(buf, buf_len) == true);
    for (auto p : dd.pairs()) {
        std::cout << p.key(); 
        std::cout << p.value(); 
    }

    delete[] buf;
}
Previousfloat to byte[]NextContainers

Last updated 4 years ago

Was this helpful?