any_int32.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package jsoniter
  2. import (
  3. "strconv"
  4. )
  5. type int32Any struct {
  6. baseAny
  7. val int32
  8. }
  9. func (any *int32Any) LastError() error {
  10. return nil
  11. }
  12. func (any *int32Any) ValueType() ValueType {
  13. return NumberValue
  14. }
  15. func (any *int32Any) MustBeValid() Any {
  16. return any
  17. }
  18. func (any *int32Any) ToBool() bool {
  19. return any.val != 0
  20. }
  21. func (any *int32Any) ToInt() int {
  22. return int(any.val)
  23. }
  24. func (any *int32Any) ToInt32() int32 {
  25. return any.val
  26. }
  27. func (any *int32Any) ToInt64() int64 {
  28. return int64(any.val)
  29. }
  30. func (any *int32Any) ToUint() uint {
  31. return uint(any.val)
  32. }
  33. func (any *int32Any) ToUint32() uint32 {
  34. return uint32(any.val)
  35. }
  36. func (any *int32Any) ToUint64() uint64 {
  37. return uint64(any.val)
  38. }
  39. func (any *int32Any) ToFloat32() float32 {
  40. return float32(any.val)
  41. }
  42. func (any *int32Any) ToFloat64() float64 {
  43. return float64(any.val)
  44. }
  45. func (any *int32Any) ToString() string {
  46. return strconv.FormatInt(int64(any.val), 10)
  47. }
  48. func (any *int32Any) WriteTo(stream *Stream) {
  49. stream.WriteInt32(any.val)
  50. }
  51. func (any *int32Any) Parse() *Iterator {
  52. return nil
  53. }
  54. func (any *int32Any) GetInterface() interface{} {
  55. return any.val
  56. }