in vncclient/encoding.go [169:209]
func (z *ZRLEEncoding) Read(c *ClientConn, rect *Rectangle, r io.Reader) (Encoding, error) {
var length int32
if err := binary.Read(r, binary.BigEndian, &length); err != nil {
return nil, err
}
// Could maybe get by without the copy
compressed := make([]uint8, length)
if err := binary.Read(r, binary.BigEndian, &compressed); err != nil {
return nil, err
}
inflated, err := c.inflator.Inflate(compressed)
if err != nil {
return nil, errors.Annotate(err, "could not inflate")
}
// It's now safe to start reading other ZRLE messages if desired
log.Debugf("expanded zlib: %d bytes -> %d bytes", len(compressed), len(inflated))
// TODO: other format checks here
if c.PixelFormat.BPP < 24 {
return nil, errors.Errorf("unsupported bitsPerPixel: %d", c.PixelFormat.BPP)
}
// data := base64.StdEncoding.EncodeToString(inflated)
// log.Infof("payload %v %v %v %v: %v", rect.X, rect.Y, rect.Width, rect.Height, data)
buf := NewQuickBuf(inflated)
colors, err := z.parse(rect, buf)
if err != nil {
return nil, errors.Annotatef(err, "could not parse ZRLEEncoding colors")
}
if buf.Len() != 0 {
return nil, errors.Errorf("BUG: buffer still had %d unread bytes", buf.Len())
}
// buf := bytes.NewBuffer(inflated)
return &ZRLEEncoding{colors, length}, nil
}