gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

provider.go (741B)


      1 package bunjson
      2 
      3 import (
      4 	"io"
      5 )
      6 
      7 var provider Provider = StdProvider{}
      8 
      9 func SetProvider(p Provider) {
     10 	provider = p
     11 }
     12 
     13 type Provider interface {
     14 	Marshal(v interface{}) ([]byte, error)
     15 	Unmarshal(data []byte, v interface{}) error
     16 	NewEncoder(w io.Writer) Encoder
     17 	NewDecoder(r io.Reader) Decoder
     18 }
     19 
     20 type Decoder interface {
     21 	Decode(v interface{}) error
     22 	UseNumber()
     23 }
     24 
     25 type Encoder interface {
     26 	Encode(v interface{}) error
     27 }
     28 
     29 func Marshal(v interface{}) ([]byte, error) {
     30 	return provider.Marshal(v)
     31 }
     32 
     33 func Unmarshal(data []byte, v interface{}) error {
     34 	return provider.Unmarshal(data, v)
     35 }
     36 
     37 func NewEncoder(w io.Writer) Encoder {
     38 	return provider.NewEncoder(w)
     39 }
     40 
     41 func NewDecoder(r io.Reader) Decoder {
     42 	return provider.NewDecoder(r)
     43 }