File Transport between Server/Client

梦想的初衷 提交于 2019-12-01 21:11:49

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!