Flesh out the proto config stuff some more.

This commit is contained in:
David Given
2021-05-10 22:38:04 +02:00
parent 74cb332706
commit a8f1469d36
5 changed files with 92 additions and 25 deletions

View File

@@ -1,6 +1,8 @@
syntax = "proto2";
message Brother {
message BrotherInput {}
message BrotherOutput {
optional double clock_rate_us = 1 [default = 3.83];
optional double post_index_gap_ms = 2 [default = 1.0];
optional double sector_spacing_ms = 3 [default = 16.2];

View File

@@ -1,6 +1,8 @@
syntax = "proto2";
message IBM {
message IBMInput {}
message IBMOutput {
enum FmMfm {
USE_MFM = 0;
USE_FM = 1;

View File

@@ -8,28 +8,55 @@ import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
optional string help = 50000;
repeated string parameter = 50001;
}
message DiskEncoding {
optional int32 cylinder = 1;
optional int32 head = 2;
oneof format {
IBM ibm = 3;
Brother brother = 4;
}
}
message FileEncoding {
optional string filename = 1;
oneof format {
Img img = 2;
}
}
message Config {
repeated DiskEncoding disk = 2;
optional FileEncoding file = 3;
optional Decoder decoder = 4 [(help) = "Options for the flux decoder process"];
message InputFile {
optional string filename = 1;
oneof format {
ImgInputOutput img = 2;
}
}
message InputDisk {
optional int32 drive = 1;
oneof format {
IBMInput ibm = 2;
BrotherInput brother = 3;
}
}
message OutputFile {
optional string filename = 1;
oneof format {
ImgInputOutput img = 2;
}
}
message OutputDisk {
optional int32 drive = 1;
oneof format {
IBMOutput ibm = 2;
BrotherOutput brother = 3;
}
}
message Input {
oneof input {
InputFile file = 1;
InputDisk disk = 2;
}
}
message Output {
oneof output {
OutputFile file = 1;
OutputDisk disk = 2;
}
}
optional Input input = 1;
optional Output output = 2;
optional Decoder decoder = 3;
}

View File

@@ -1,6 +1,6 @@
syntax = "proto2";
message Img {
message ImgInputOutput {
message Format {
optional int32 track = 1;
optional int32 side = 2;

View File

@@ -1,6 +1,7 @@
#include "globals.h"
#include "bytes.h"
#include "tests/testproto.pb.h"
#include "lib/config.pb.h"
#include "proto.h"
#include "snowhouse/snowhouse.h"
#include <google/protobuf/text_format.h>
@@ -9,6 +10,14 @@
using namespace snowhouse;
static std::string cleanup(const std::string& s)
{
auto outs = std::regex_replace(s, std::regex("[ \t\n]+"), " ");
outs = std::regex_replace(outs, std::regex("^[ \t\n]+"), "");
outs = std::regex_replace(outs, std::regex("[ \t\n]+$"), "");
return outs;
}
static void test_setting(void)
{
TestProto config;
@@ -23,13 +32,40 @@ static void test_setting(void)
std::string s;
google::protobuf::TextFormat::PrintToString(config, &s);
s = std::regex_replace(s, std::regex("[ \t\n]+"), " ");
AssertThat(s, Equals("i64: -1 i32: -2 u64: 3 u32: 4 d: 5.5 m { s: \"string\" } r { s: \"val2\" } "));
s = cleanup(s);
AssertThat(s, Equals("i64: -1 i32: -2 u64: 3 u32: 4 d: 5.5 m { s: \"string\" } r { s: \"val2\" }"));
}
static void test_config(void)
{
Config config;
const std::string text = R"M(
input {
file {
filename: "filename"
}
}
output {
disk {
drive: 0
ibm {
}
}
}
)M";
google::protobuf::TextFormat::MergeFromString(text, &config);
std::string s;
google::protobuf::TextFormat::PrintToString(config, &s);
AssertThat(cleanup(s), Equals(cleanup(text)));
}
int main(int argc, const char* argv[])
{
test_setting();
test_config();
return 0;
}