另客网go项目公用的代码库

any_int32.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }