UnmarshalJSON satisfies the json.Unmarshaler interface. If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it decodes hex data from b into h.
(b []byte)
| 69 | // If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it |
| 70 | // decodes hex data from b into h. |
| 71 | func (h *Hash) UnmarshalJSON(b []byte) error { |
| 72 | if bytes.Equal(b, []byte("null")) { |
| 73 | *h = Hash{} |
| 74 | return nil |
| 75 | } |
| 76 | var s string |
| 77 | err := json.Unmarshal(b, &s) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | return h.UnmarshalText([]byte(s)) |
| 82 | } |
| 83 | |
| 84 | // Bytes returns the hash as a byte slice. |
| 85 | func (h Hash) Bytes() []byte { |