Square的Retrofit响应解析逻辑:流式传输? [英] Square's Retrofit response parsing logic: streaming?

查看:183
本文介绍了Square的Retrofit响应解析逻辑:流式传输?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否解释一下Square的Retrofit响应解析逻辑. 我很想知道何时应该收到&解析一个大json(> 100Kb)-Retrofit是否会等待从服务器接收到所有内容而仅解析它,否则它将在获取流数据时立即开始解析它? 我的目标是加快响应处理速度.

Could you please explain Square's Retrofit response parsing logic. I'm interested in case when we should receive & parse a big json (>100Kb) - will Retrofit wait while all content will be received from server and only than parse it, or it will start to parse it immediately while getting stream data? My goal is to speedup response processing.

关于它的配置是否有任何选项?

Are there any options about it available to configure?

推荐答案

HTTP客户端解析标头后,InputStream将被交还给Retrofit,后者将把它直接交给Converter.这意味着,随着底层的转换器机制(例如Gson)正在提取字节,它们将直接从网络中读取(并可能阻塞).

As soon as the HTTP client parses the headers, the InputStream will be handed back to Retrofit which will then hand it directly to the Converter. This means that as the underlying converter mechanism (say, Gson) is pulling bytes they are being read (and potentially blocking) directly from the network.

注意:仅当关闭日志记录时,这才是正确的(因为它应该在生产/发布版本中).如果在HEADERS级别之外打开日志记录,则必须将响应主体全部读取为byte[],以便将数据记录并传递给转换器.

Note: this is only true if logging is off (as it should be in production / release builds). When logging is turned on beyond HEADERS level, the response body has to be read in its entirety into a byte[] in order to both log and hand the data to the converter.

这篇关于Square的Retrofit响应解析逻辑:流式传输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆