cell_image.go 820 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package xvdoc
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. )
  6. type cellImage struct {
  7. x, y int
  8. path string
  9. name string
  10. ext string
  11. format JSONMap
  12. }
  13. func (s *cellImage) UnmarshalJSON(src []byte) (err error) {
  14. dec := json.NewDecoder(bytes.NewReader(src))
  15. var t json.Token
  16. for dec.More() && err == nil {
  17. if t, err = dec.Token(); err == nil {
  18. if _, check := t.(json.Delim); !check {
  19. switch t.(string) {
  20. case "x":
  21. err = dec.Decode(&s.x)
  22. case "y":
  23. err = dec.Decode(&s.y)
  24. case "path":
  25. err = dec.Decode(&s.path)
  26. case "format":
  27. if err = dec.Decode(&s.format); err != nil {
  28. s.format = nil
  29. }
  30. case "name":
  31. err = dec.Decode(&s.name)
  32. case "ext":
  33. err = dec.Decode(&s.ext)
  34. default:
  35. err = dec.Decode(new(interface{}))
  36. }
  37. }
  38. }
  39. }
  40. return
  41. }