File Transport between Server/Client

前端 未结 1 1690
死守一世寂寞
死守一世寂寞 2021-01-19 14:10

What kind of Service should I define for \".thrift\"-file to use it later for my Program?

This File Transport should be between the Client and the Server and it shou

相关标签:
1条回答
  • 2021-01-19 14:45

    Your code looks not so bad to me (not tested) and there is not much to change.

    How about

    typedef binary binar
    service StreamFileService {    
       binar getBytes(1:string fileName, 2: i64 offset, 3: i32 size);    
       i64 getSize(1:string fileName)
    }
    

    I would also return a struct holding the bytes, but that's more or less my personal opinion.

    struct FileChunk {
      1: binary data
      2: i64 remaining
    }
    
    service StreamFileService {    
       FileChunk getBytes(1:string fileName, 2: i64 offset, 3: i32 size);    
    }
    

    The FileChunk struct can be easily extended, if such becomes necessary, e.g. in order to return additional metadata, like total size (especially if the size grows/shrinks over time), remaining bytes, indications about the data format, or the like. You don't have to do that, as you can easily extend the interface if such becomes necessary later. Matter of taste.

    0 讨论(0)
提交回复
热议问题