| 1 | package utilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.21 context/" |
| 5 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.21 io/" |
| 7 | "syncscip-go gomod github.com/golang/go/src go1.21 sync/" |
| 8 | |
| 9 | "github.com/tonistiigi/fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/" |
| 10 | ) |
| 11 | |
| 12 | var bufPoolscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/bufPool. = syncscip-go gomod github.com/golang/go/src go1.21 sync/.Poolscip-go gomod github.com/golang/go/src go1.21 sync/Pool#{ |
| 13 | Newscip-go gomod github.com/golang/go/src go1.21 sync/Pool#New.: func() interface{} { |
| 14 | buf := make([]byte, 32*1<<10) |
| 15 | return &buf |
| 16 | }, |
| 17 | } |
| 18 | |
| 19 | func NewProtoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/NewProtoStream().(ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, r ioscip-go gomod github.com/golang/go/src go1.21 io/.Readerscip-go gomod github.com/golang/go/src go1.21 io/Reader#, w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#) fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.Streamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/Stream# { |
| 20 | return &protoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#{ctx, r, w} |
| 21 | } |
| 22 | |
| 23 | type protoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream# struct { |
| 24 | ctxscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#ctx. contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context# |
| 25 | ioscip-go gomod github.com/golang/go/src go1.21 io/.Readerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Reader. |
| 26 | ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Writer. |
| 27 | } |
| 28 | |
| 29 | func (c *protoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#) RecvMsgscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#RecvMsg().(m interface{}) error { |
| 30 | type unmarshaler interface { |
| 31 | Unmarshal([]byte) error |
| 32 | } |
| 33 | var h [4]byte |
| 34 | if _, err := ioscip-go gomod github.com/golang/go/src go1.21 io/.ReadFullscip-go gomod github.com/golang/go/src go1.21 io/ReadFull().(c.Readerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Reader., h[:]); err != nil { |
| 35 | return err |
| 36 | } |
| 37 | msg := m.(unmarshaler) |
| 38 | length := binaryscip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/bigEndian#Uint32().(h[:]) |
| 39 | if length == 0 { |
| 40 | return nil |
| 41 | } |
| 42 | buf := *bufPoolscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/bufPool..Getscip-go gomod github.com/golang/go/src go1.21 sync/Pool#Get().().(*[]byte) |
| 43 | if cap(buf) < int(length) { |
| 44 | buf = make([]byte, length) |
| 45 | } else { |
| 46 | buf = buf[:length] |
| 47 | } |
| 48 | defer bufPoolscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/bufPool..Putscip-go gomod github.com/golang/go/src go1.21 sync/Pool#Put().(&buf) |
| 49 | if _, err := ioscip-go gomod github.com/golang/go/src go1.21 io/.ReadFullscip-go gomod github.com/golang/go/src go1.21 io/ReadFull().(c.Readerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Reader., buf); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | err := msg.Unmarshal(buf) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | func (c *protoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#) SendMsgscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#SendMsg().(m interface{}) error { |
| 60 | type marshalerSizer interface { |
| 61 | MarshalTo([]byte) (int, error) |
| 62 | Size() int |
| 63 | } |
| 64 | msg := m.(marshalerSizer) |
| 65 | size := msg.Size() |
| 66 | b := make([]byte, msg.Size()+4) |
| 67 | binaryscip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.21 `encoding/binary`/bigEndian#PutUint32().(b[:4], uint32(size)) |
| 68 | if _, err := msg.MarshalTo(b[4:]); err != nil { |
| 69 | return err |
| 70 | } |
| 71 | _, err := c.Writerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Writer..Writescip-go gomod github.com/golang/go/src go1.21 io/Writer#Write().(b) |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | func (c *protoStreamscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#) Contextscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#Context().() contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context# { |
| 76 | return c.ctxscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/util`/protoStream#ctx. |
| 77 | } |