为什么io.WriterTo的WriteTo方法返回int64而不是int? [英] Why does io.WriterTo's WriteTo method return an int64 rather than an int?

查看:117
本文介绍了为什么io.WriterTo的WriteTo方法返回int64而不是int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Go的io中的大多数输出​​方法都返回(int, error),例如io.WriterWrite([]byte)方法和io.WriteString(io.Writer, string)函数.但是,某些输出方法(例如io.WriterToWriteTo方法)将返回(int64, error).这使得根据WriteWriteString来实现WriteTo而不存储中间值并将其从int转换为int64的类型非常不便.这种差异的原因是什么?

Most of the output methods in Go's io package return (int, error), for example io.Writer's Write([]byte) method and the io.WriteString(io.Writer, string) function. However, a few of the output methods, such as io.WriterTo's WriteTo method, return (int64, error) instead. This makes it inconvenient to implement WriteTo in terms of Write or WriteString without storing an intermediate value and type converting it from int to int64. What is the reason for this discrepancy?

推荐答案

WriteTo可能复制了超过int32字节的数据.

It's possible that WriteTo copies more than int32 bytes of data.

使用io.Readerio.Writer接口,数据量受给定切片的大小限制,对于当前体系结构,切片的长度受int限制.

With the io.Readerand io.Writer interfaces, the amount of data is limited by the size of the given slice, which has a length limited by int for the current architecture.

这篇关于为什么io.WriterTo的WriteTo方法返回int64而不是int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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