diff --git a/arch/brother/brother.proto b/arch/brother/brother.proto index f9d07f6a..9a314331 100644 --- a/arch/brother/brother.proto +++ b/arch/brother/brother.proto @@ -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]; diff --git a/arch/ibm/ibm.proto b/arch/ibm/ibm.proto index 848042ed..17ba570a 100644 --- a/arch/ibm/ibm.proto +++ b/arch/ibm/ibm.proto @@ -1,6 +1,8 @@ syntax = "proto2"; -message IBM { +message IBMInput {} + +message IBMOutput { enum FmMfm { USE_MFM = 0; USE_FM = 1; diff --git a/lib/config.proto b/lib/config.proto index 1c21b079..f3bdc687 100644 --- a/lib/config.proto +++ b/lib/config.proto @@ -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; } diff --git a/lib/imagereader/img.proto b/lib/imagereader/img.proto index 7d85059e..069e3611 100644 --- a/lib/imagereader/img.proto +++ b/lib/imagereader/img.proto @@ -1,6 +1,6 @@ syntax = "proto2"; -message Img { +message ImgInputOutput { message Format { optional int32 track = 1; optional int32 side = 2; diff --git a/tests/proto.cc b/tests/proto.cc index 4d1539f2..133d4cf8 100644 --- a/tests/proto.cc +++ b/tests/proto.cc @@ -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 @@ -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; }