15.go开源groupcache项目笔记——sinks代码

15.go开源groupcache项目笔记——sinks代码

结构体和接口

类型Sink

为接口。

type Sink interface {

         SetString(sstring) error

         SetBytes(v[]byte) error

         SetProto(mproto.Message) error

         view()(ByteView, error)

}

然后定义了不同的结构体。每个结构体都实现各自的接口。

stringSink

type stringSink struct {

         sp*string

         v  ByteView

}

byteViewSink

type byteViewSink struct {

         dst*ByteView

}

protoSink

type protoSink struct {

         dstproto.Message // authorative value

         typstring

 

         vByteView // encoded

}

truncBytesSink

type truncBytesSink struct {

         dst*[]byte

         v   ByteView

}

allocBytesSink

type allocBytesSink struct {

         dst*[]byte

         v   ByteView

}

cloneBytes函数

返回byte数组,复制参数b的数组。

setSinkView函数

入参为Sink,    ByteView.

包含一个viewSetter接口,接口包含setView函数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值