Train My Brain: tmb-proto

쉽게 구조를 갖춰놓을 수 있는 프로젝트라 생각해서 먼저 다룬다. 프로토타이핑은 tensorflow의 예제를 많이 빌렸다. 우선 세 가지로 나누어 생각해봤다. 서버와 클라이언트가 주고 받는 통신에 대한 contents.proto와 param_return.proto 그리고 서비스에 대한 tmb_service.proto 이다.

  1. contents.proto는 실제로 어떤 메세지 형식을 주고 받을 건지 정의했다. Flask를 좀 쓰다보니 json or dictionary형식이 너무 익숙해서 여기서도 dict형태로 해보려고 한다. A는 B이다가 정확히 구조적으로 잘 정의돼 있어서다.

    syntax = 'proto3';
       
    package tmb_proto.communicate;
       
    import "google/protobuf/empty.proto";
       
    message TmbContents {
        map<string, Value> data = 1;
    }
       
    message BytesList {
        repeated bytes value = 1;
    }
       
    message FloatList {
        repeated float value = 1 [packed = true];
    }
       
    message Int64List {
        repeated int64 value = 1 [packed = true];
    }
       
    message Value {
        oneof typing {
            BytesList bytes_list = 1;
            FloatList float_list = 2;
            Int64List int64_list = 3;
        }
    }
       
    
  2. param_return.proto는 사실 서비스쪽에 넣을지 여기다 넣을지 고민하다가 통신 관련 프로토로 묶는게 더 맞다고 생각했다. 이 안에는 단순히 통신 서비스가 뭘 받아서 뭘 내뱉을지 정의 되어있다. 요청을 받고, 응답을 한다. 아주 간단하다. 아직 뭘 넣을지는 잘 모르겠다.

    syntax = 'proto3';
       
    package tmb_proto.communicate;
       
    import "tmb_proto/communicate/contents.proto";
       
    message Status {
        bool success = 1;
    }
       
    message Request {
        oneof content {
            tmb_proto.communicate.TmbContents tmb_contents = 1;
            google.protobuf.Empty empty_contents = 2;
        }
    }
       
    message Response {
       
    }
    
  3. tmb_service.proto 이거는 이제 실제로 클라이언트가 어떻게 행동할지를 정의해두었다. 다시 말하면 서버가 클라이언트한테 어떤 일을 시킬지를 (클라이언트가 어떤 서비스를 서버에게 제공할 지를) 정의했다. 일단 좀 테스트가 필요하니 test 서비스만 만들어두었다.

    syntax = 'proto3';
       
    package tmb_proto.service;
       
    import "tmb_proto/communicate/param_return.proto";
       
    service Tmb {
        rpc test (tmb_proto.communicate.Request) returns (tmb_proto.communicate.Response) {}
    }
    

(TBD) 조금씩 짜면서 아마 이 구조가 계속 바뀔 것이다. 그 때마다 수정하면서 포스팅 하겠다.