// The schema the protobuf port is characterised by, on both arms. // // It is compiled TWICE and the two results are compared: // // * at recipe time by the BUILD-MACHINE protoc, into the probe that ships // (protobuf_probe.cpp includes the header it emits), and // * on target by the wasm32 protoc, 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 protobuf does not promise it is stable, so a map would make the wire // comparison below a coin flip rather than an assertion. // // proto3, matching what the 25.x runtime is 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: protobuf serialises 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. }