Skip to content

Instantly share code, notes, and snippets.

@edwardIshaq
Last active April 8, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardIshaq/bf8df49bb058de120fac68b846f23f92 to your computer and use it in GitHub Desktop.
Save edwardIshaq/bf8df49bb058de120fac68b846f23f92 to your computer and use it in GitHub Desktop.
Wrapping around Snappy error
// SnappyJSON type implements json.Marshaler and represents a snappy compressed []byte
type SnappyJSON []byte
// SnappyError wrapper around the error returned from snappy
type SnappyError struct {
json SnappyJSON
err error
}
func (s *SnappyError) Error() string {
return fmt.Sprintf("SnappyJSON: Error compressing %v", s)
}
// UnmarshalJSON from json -> SnappyJSON
func (s *SnappyJSON) UnmarshalJSON(b []byte) error {
compressed, err := snappyCompress(b)
if err != nil {
return &SnappyError{b, err}
// return err
}
//Assign compressed to `s`
*s = compressed
return nil
}
@edwardIshaq
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment