| 1 |
package decoder |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"reflect" |
| 6 |
"unsafe" |
| 7 |
) |
| 8 |
|
| 9 |
type funcDecoder struct { |
| 10 |
typ reflect.Type |
| 11 |
structName string |
| 12 |
fieldName string |
| 13 |
} |
| 14 |
|
| 15 |
func newFuncDecoder(typ reflect.Type, structName, fieldName string) *funcDecoder { |
| 16 |
fnDecoder := &funcDecoder{typ, structName, fieldName} |
| 17 |
return fnDecoder |
| 18 |
} |
| 19 |
|
| 20 |
func (d *funcDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) { |
| 21 |
buf := ctx.Buf |
| 22 |
cursor = skipWhiteSpace(buf, cursor) |
| 23 |
if buf[cursor] == 'n' { |
| 24 |
if buf[cursor+1] != 'u' || buf[cursor+2] != 'l' || buf[cursor+3] != 'l' { |
| 25 |
return 0, literalSyntaxError(buf, cursor, "null") |
| 26 |
} |
| 27 |
*(*unsafe.Pointer)(p) = nil |
| 28 |
return cursor + 4, nil |
| 29 |
} |
| 30 |
// a func can't be decoded from any other value: it is a type error, after which the decoding goes on |
| 31 |
return ctx.skipTypeError(cursor, depth, d.typ) |
| 32 |
} |
| 33 |
|
| 34 |
func (d *funcDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) { |
| 35 |
return nil, 0, fmt.Errorf("json: func decoder does not support decode path") |
| 36 |
} |