MCPcopy
hub / github.com/tinylib/msgp / WriteExtension

Method WriteExtension

msgp/extension.go:209–242  ·  view source on GitHub ↗

WriteExtension writes an extension type to the writer

(e Extension)

Source from the content-addressed store, hash-verified

207
208// WriteExtension writes an extension type to the writer
209func (mw *Writer) WriteExtension(e Extension) error {
210 length := e.Len()
211
212 err := mw.writeExtensionHeader(length, e.ExtensionType())
213 if err != nil {
214 return err
215 }
216
217 // we can only write directly to the
218 // buffer if we're sure that it
219 // fits the object
220 if length <= mw.bufsize() {
221 o, err := mw.require(length)
222 if err != nil {
223 return err
224 }
225 return e.MarshalBinaryTo(mw.buf[o:])
226 }
227 // here we create a new buffer
228 // just large enough for the body
229 // and save it as the write buffer
230 err = mw.flush()
231 if err != nil {
232 return err
233 }
234 buf := make([]byte, length)
235 err = e.MarshalBinaryTo(buf)
236 if err != nil {
237 return err
238 }
239 mw.buf = buf
240 mw.wloc = length
241 return nil
242}
243
244// WriteExtensionRaw writes an extension type to the writer
245func (mw *Writer) WriteExtensionRaw(extType int8, payload []byte) error {

Callers 8

BenchmarkSkipBytesFunction · 0.95
BenchmarkSkipFunction · 0.95
TestCopyNextFunction · 0.95
WriteIntfMethod · 0.95
TestUnmarshalJSONFunction · 0.95
TestReadWriteExtensionFunction · 0.95

Calls 7

writeExtensionHeaderMethod · 0.95
bufsizeMethod · 0.95
requireMethod · 0.95
flushMethod · 0.95
LenMethod · 0.65
ExtensionTypeMethod · 0.65
MarshalBinaryToMethod · 0.65

Tested by 7

BenchmarkSkipBytesFunction · 0.76
BenchmarkSkipFunction · 0.76
TestCopyNextFunction · 0.76
TestUnmarshalJSONFunction · 0.76
TestReadWriteExtensionFunction · 0.76