mirror of
https://github.com/prebid/openrtb.git
synced 2026-06-15 14:36:36 +03:00
5b614ff545
As proposed in: https://github.com/mxmCherry/openrtb/issues/8
26 lines
707 B
Go
26 lines
707 B
Go
package openrtb
|
|
|
|
import "errors"
|
|
|
|
// RawJSON is a raw encoded JSON value.
|
|
// It implements encoding/json.Marshaler and encoding/json.Unmarshaler and can
|
|
// be used to delay JSON decoding or precompute a JSON encoding.
|
|
//
|
|
// Basically, it's just a copy of encoding/json.RawMessage type,
|
|
// but with more convenient non-pointer encoding.
|
|
type RawJSON []byte
|
|
|
|
// MarshalJSON returns m as the JSON encoding of m.
|
|
func (m RawJSON) MarshalJSON() ([]byte, error) {
|
|
return m, nil
|
|
}
|
|
|
|
// UnmarshalJSON sets *m to a copy of data.
|
|
func (m *RawJSON) UnmarshalJSON(data []byte) error {
|
|
if m == nil {
|
|
return errors.New("openrtb.RawJSON: UnmarshalJSON on nil pointer")
|
|
}
|
|
*m = append((*m)[0:0], data...)
|
|
return nil
|
|
}
|