// The schema the protobuf-c port is characterised by. // // IT IS BYTE-FOR-BYTE THE SAME SCHEMA THE protobuf (C++) PORT USES, and that is // deliberate rather than convenient. protobuf-c is an INDEPENDENT // implementation of the same wire specification, so compiling one schema with // both and comparing the bytes is the strongest assertion either port can make: // it is answered by the spec, not by shared code. The two ports share no // runtime -- libprotobuf-c is pure C and links none of libprotobuf, libprotoc or // abseil -- so a match is genuine agreement and a mismatch is a real defect in // one of them. 83-protobuf-c.test makes that comparison explicitly // (wire/matches-protobuf-cxx) against the reference the C++ port already ships. // // It is compiled TWICE within this port as well, and those two results compared: // // * at recipe time by the BUILD-MACHINE protoc-c, into the probe that ships // (protobuf_c_probe.c includes the header it emits), and // * on target by the wasm32 protoc-c, against a byte-exact x86-64 reference in // brintos-selftests/data. // // So every construct below is here because it exercises a distinct part of the // wire format or the generator, not for realism: // // varint (int32, bool, enum), zigzag (sint32), fixed-width (fixed64, double), // length-delimited (string, bytes, submessage), and a PACKED repeated scalar. // // NO map<> ANYWHERE, deliberately. Map field serialisation order is unspecified // and neither implementation promises it is stable, so a map would make the // wire comparison a coin flip rather than an assertion. // // proto3, matching what both runtimes are built for. syntax = "proto3"; package brintos; enum Color { COLOR_RED = 0; COLOR_GREEN = 1; COLOR_BLUE = 2; } message Weapon { string name = 1; int32 damage = 2; } message Probe { string name = 1; // length-delimited int32 hp = 2; // varint int32 mana = 3; // varint, left at its default to prove proto3 elides it Color color = 4; // varint (enum) repeated int32 inventory = 5; // PACKED length-delimited run of varints repeated Weapon weapons = 6; // repeated submessage bytes blob = 7; // length-delimited, carries NUL and high bytes bool alive = 8; // varint double weight = 9; // 64-bit fixed, little-endian IEEE754 sint32 depth = 10; // zigzag varint, negative fixed64 id = 11; // 64-bit fixed, and DELIBERATELY THE HIGHEST FIELD // NUMBER: both implementations serialise in field // order, so this lands last on the wire. Being // last, fixed width and non-default is what makes // every proper prefix of the wire differ from the // whole message -- the property the truncation // cases assert. }