Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper for reading & writing from binary #1600

Merged
merged 8 commits into from
Jun 22, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions report/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package report

import (
"compress/gzip"
"encoding/gob"
"io"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (c byteCounter) Read(p []byte) (n int, err error) {
// ReadBinary reads bytes into a Report.
//
// Will decompress the binary if gzipped is true, and will use the given
// codecHandle to decode it. If codecHandle is nil, will decode as a gob.
// codecHandle to decode it.
func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handle) error {
var err error
var compressedSize, uncompressedSize uint64
Expand All @@ -56,13 +55,7 @@ func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handl
if log.GetLevel() == log.DebugLevel {
r = byteCounter{next: r, count: &uncompressedSize}
}
var decoder func(interface{}) error
if codecHandle != nil {
decoder = codec.NewDecoder(r, codecHandle).Decode
} else {
decoder = gob.NewDecoder(r).Decode
}
if err := decoder(&rep); err != nil {
if err := codec.NewDecoder(r, codecHandle).Decode(&rep); err != nil {
return err
}
log.Debugf(
Expand Down