MCPcopy
hub / github.com/klauspost/compress / AppendTable

Method AppendTable

huff0/build_table.go:141–168  ·  view source on GitHub ↗

AppendTable serializes the table currently stored in prevTable (e.g. as installed by BuildCTable or carried over from a previous Compress call) into a self-delimiting zstd-style header and appends it to dst. The returned slice can be parsed back by ReadTable.

(dst []byte)

Source from the content-addressed store, hash-verified

139// into a self-delimiting zstd-style header and appends it to dst. The
140// returned slice can be parsed back by ReadTable.
141func (s *Scratch) AppendTable(dst []byte) ([]byte, error) {
142 if s == nil || len(s.prevTable) == 0 {
143 return dst, errors.New("huff0: AppendTable with empty table")
144 }
145 // cTable.write reads s.actualTableLog, s.symbolLen, s.huffWeight, s.fse
146 // and writes into s.Out. Save/restore Out so we don't disturb in-flight
147 // compression buffers.
148 saveOut := s.Out
149 saveTL := s.actualTableLog
150 saveSL := s.symbolLen
151 if s.fse == nil {
152 // Lazily init in case AppendTable is called on a fresh Scratch.
153 if _, err := s.prepare(nil); err != nil {
154 return dst, err
155 }
156 saveOut = s.Out
157 }
158 s.Out = s.Out[:0]
159 s.actualTableLog = s.prevTableLog
160 s.symbolLen = uint16(len(s.prevTable))
161 if err := s.prevTable.write(s); err != nil {
162 s.Out, s.actualTableLog, s.symbolLen = saveOut, saveTL, saveSL
163 return dst, err
164 }
165 dst = append(dst, s.Out...)
166 s.Out, s.actualTableLog, s.symbolLen = saveOut, saveTL, saveSL
167 return dst, nil
168}

Callers 1

TestAppendTableRoundtripFunction · 0.95

Calls 2

prepareMethod · 0.95
writeMethod · 0.45

Tested by 1

TestAppendTableRoundtripFunction · 0.76