OSDN Git Service

Hulk did something
[bytom/vapor.git] / encoding / json / json.go
diff --git a/encoding/json/json.go b/encoding/json/json.go
new file mode 100644 (file)
index 0000000..0ad7b6a
--- /dev/null
@@ -0,0 +1,35 @@
+package json
+
+import (
+       "encoding/hex"
+       "encoding/json"
+)
+
+type HexBytes []byte
+
+func (h HexBytes) MarshalText() ([]byte, error) {
+       return []byte(hex.EncodeToString(h)), nil
+}
+
+func (h *HexBytes) UnmarshalText(text []byte) error {
+       n := hex.DecodedLen(len(text))
+       *h = make([]byte, n)
+       _, err := hex.Decode(*h, text)
+       return err
+}
+
+type Map []byte
+
+func (m Map) MarshalJSON() ([]byte, error) {
+       return m, nil
+}
+
+func (m *Map) UnmarshalJSON(text []byte) error {
+       var check map[string]*json.RawMessage
+       err := json.Unmarshal(text, &check)
+       if err != nil {
+               return err
+       }
+       *m = text
+       return nil
+}