feature_any_object.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. package jsoniter
  2. import (
  3. "fmt"
  4. "reflect"
  5. "unsafe"
  6. )
  7. type objectLazyAny struct {
  8. baseAny
  9. buf []byte
  10. iter *Iterator
  11. err error
  12. cache map[string]Any
  13. remaining []byte
  14. }
  15. func (any *objectLazyAny) ValueType() ValueType {
  16. return Object
  17. }
  18. func (any *objectLazyAny) Parse() *Iterator {
  19. iter := any.iter
  20. if iter == nil {
  21. iter = NewIterator()
  22. any.iter = iter
  23. }
  24. iter.ResetBytes(any.remaining)
  25. return iter
  26. }
  27. func (any *objectLazyAny) fillCacheUntil(target string) Any {
  28. if any.remaining == nil {
  29. return any.cache[target]
  30. }
  31. if any.cache == nil {
  32. any.cache = map[string]Any{}
  33. }
  34. val := any.cache[target]
  35. if val != nil {
  36. return val
  37. }
  38. iter := any.Parse()
  39. if len(any.remaining) == len(any.buf) {
  40. iter.head++
  41. c := iter.nextToken()
  42. if c != '}' {
  43. iter.unreadByte()
  44. k := string(iter.readObjectFieldAsBytes())
  45. v := iter.readAny(iter)
  46. any.cache[k] = v
  47. if target == k {
  48. any.remaining = iter.buf[iter.head:]
  49. any.err = iter.Error
  50. return v
  51. }
  52. } else {
  53. any.remaining = nil
  54. any.err = iter.Error
  55. return nil
  56. }
  57. }
  58. for iter.nextToken() == ',' {
  59. k := string(iter.readObjectFieldAsBytes())
  60. v := iter.readAny(iter)
  61. any.cache[k] = v
  62. if target == k {
  63. any.remaining = iter.buf[iter.head:]
  64. any.err = iter.Error
  65. return v
  66. }
  67. }
  68. any.remaining = nil
  69. any.err = iter.Error
  70. return nil
  71. }
  72. func (any *objectLazyAny) fillCache() {
  73. if any.remaining == nil {
  74. return
  75. }
  76. if any.cache == nil {
  77. any.cache = map[string]Any{}
  78. }
  79. iter := any.Parse()
  80. if len(any.remaining) == len(any.buf) {
  81. iter.head++
  82. c := iter.nextToken()
  83. if c != '}' {
  84. iter.unreadByte()
  85. k := string(iter.readObjectFieldAsBytes())
  86. v := iter.readAny(iter)
  87. any.cache[k] = v
  88. } else {
  89. any.remaining = nil
  90. any.err = iter.Error
  91. return
  92. }
  93. }
  94. for iter.nextToken() == ',' {
  95. k := string(iter.readObjectFieldAsBytes())
  96. v := iter.readAny(iter)
  97. any.cache[k] = v
  98. }
  99. any.remaining = nil
  100. any.err = iter.Error
  101. return
  102. }
  103. func (any *objectLazyAny) LastError() error {
  104. return any.err
  105. }
  106. func (any *objectLazyAny) ToBool() bool {
  107. if any.cache == nil {
  108. any.IterateObject() // trigger first value read
  109. }
  110. return len(any.cache) != 0
  111. }
  112. func (any *objectLazyAny) ToInt() int {
  113. if any.cache == nil {
  114. any.IterateObject() // trigger first value read
  115. }
  116. if len(any.cache) == 0 {
  117. return 0
  118. }
  119. return 1
  120. }
  121. func (any *objectLazyAny) ToInt32() int32 {
  122. if any.cache == nil {
  123. any.IterateObject() // trigger first value read
  124. }
  125. if len(any.cache) == 0 {
  126. return 0
  127. }
  128. return 1
  129. }
  130. func (any *objectLazyAny) ToInt64() int64 {
  131. if any.cache == nil {
  132. any.IterateObject() // trigger first value read
  133. }
  134. if len(any.cache) == 0 {
  135. return 0
  136. }
  137. return 1
  138. }
  139. func (any *objectLazyAny) ToUint() uint {
  140. if any.cache == nil {
  141. any.IterateObject() // trigger first value read
  142. }
  143. if len(any.cache) == 0 {
  144. return 0
  145. }
  146. return 1
  147. }
  148. func (any *objectLazyAny) ToUint32() uint32 {
  149. if any.cache == nil {
  150. any.IterateObject() // trigger first value read
  151. }
  152. if len(any.cache) == 0 {
  153. return 0
  154. }
  155. return 1
  156. }
  157. func (any *objectLazyAny) ToUint64() uint64 {
  158. if any.cache == nil {
  159. any.IterateObject() // trigger first value read
  160. }
  161. if len(any.cache) == 0 {
  162. return 0
  163. }
  164. return 1
  165. }
  166. func (any *objectLazyAny) ToFloat32() float32 {
  167. if any.cache == nil {
  168. any.IterateObject() // trigger first value read
  169. }
  170. if len(any.cache) == 0 {
  171. return 0
  172. }
  173. return 1
  174. }
  175. func (any *objectLazyAny) ToFloat64() float64 {
  176. if any.cache == nil {
  177. any.IterateObject() // trigger first value read
  178. }
  179. if len(any.cache) == 0 {
  180. return 0
  181. }
  182. return 1
  183. }
  184. func (any *objectLazyAny) ToString() string {
  185. if len(any.remaining) == len(any.buf) {
  186. // nothing has been parsed yet
  187. return *(*string)(unsafe.Pointer(&any.buf))
  188. } else {
  189. any.fillCache()
  190. str, err := MarshalToString(any.cache)
  191. any.err = err
  192. return str
  193. }
  194. }
  195. func (any *objectLazyAny) Get(path ...interface{}) Any {
  196. if len(path) == 0 {
  197. return any
  198. }
  199. var element Any
  200. switch firstPath := path[0].(type) {
  201. case string:
  202. element = any.fillCacheUntil(firstPath)
  203. if element == nil {
  204. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  205. }
  206. case int32:
  207. if '*' == firstPath {
  208. any.fillCache()
  209. mappedAll := map[string]Any{}
  210. for key, value := range any.cache {
  211. mapped := value.Get(path[1:]...)
  212. if mapped.ValueType() != Invalid {
  213. mappedAll[key] = mapped
  214. }
  215. }
  216. return wrapMap(mappedAll)
  217. } else {
  218. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  219. }
  220. default:
  221. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  222. }
  223. if len(path) == 1 {
  224. return element
  225. } else {
  226. return element.Get(path[1:]...)
  227. }
  228. }
  229. func (any *objectLazyAny) Keys() []string {
  230. any.fillCache()
  231. keys := make([]string, 0, len(any.cache))
  232. for key := range any.cache {
  233. keys = append(keys, key)
  234. }
  235. return keys
  236. }
  237. func (any *objectLazyAny) Size() int {
  238. any.fillCache()
  239. return len(any.cache)
  240. }
  241. func (any *objectLazyAny) IterateObject() (func() (string, Any, bool), bool) {
  242. if any.cache == nil {
  243. any.cache = map[string]Any{}
  244. }
  245. remaining := any.remaining
  246. if len(remaining) == len(any.buf) {
  247. iter := any.Parse()
  248. iter.head++
  249. c := iter.nextToken()
  250. if c != '}' {
  251. iter.unreadByte()
  252. k := string(iter.readObjectFieldAsBytes())
  253. v := iter.readAny(iter)
  254. any.cache[k] = v
  255. remaining = iter.buf[iter.head:]
  256. any.remaining = remaining
  257. } else {
  258. remaining = nil
  259. any.remaining = nil
  260. any.err = iter.Error
  261. return nil, false
  262. }
  263. }
  264. if len(any.cache) == 0 {
  265. return nil, false
  266. }
  267. keys := make([]string, 0, len(any.cache))
  268. values := make([]Any, 0, len(any.cache))
  269. for key, value := range any.cache {
  270. keys = append(keys, key)
  271. values = append(values, value)
  272. }
  273. nextKey := keys[0]
  274. nextValue := values[0]
  275. i := 1
  276. return func() (string, Any, bool) {
  277. key := nextKey
  278. value := nextValue
  279. if i < len(keys) {
  280. // read from cache
  281. nextKey = keys[i]
  282. nextValue = values[i]
  283. i++
  284. return key, value, true
  285. } else {
  286. // read from buffer
  287. iter := any.iter
  288. if iter == nil {
  289. iter = NewIterator()
  290. any.iter = iter
  291. }
  292. iter.ResetBytes(remaining)
  293. c := iter.nextToken()
  294. if c == ',' {
  295. nextKey = string(iter.readObjectFieldAsBytes())
  296. nextValue = iter.readAny(iter)
  297. any.cache[nextKey] = nextValue
  298. remaining = iter.buf[iter.head:]
  299. any.remaining = remaining
  300. any.err = iter.Error
  301. return key, value, true
  302. } else {
  303. nextKey = ""
  304. remaining = nil
  305. any.remaining = nil
  306. any.err = iter.Error
  307. return key, value, false
  308. }
  309. }
  310. }, true
  311. }
  312. func (any *objectLazyAny) GetObject() map[string]Any {
  313. any.fillCache()
  314. return any.cache
  315. }
  316. func (any *objectLazyAny) SetObject(val map[string]Any) bool {
  317. any.fillCache()
  318. any.cache = val
  319. return true
  320. }
  321. func (any *objectLazyAny) WriteTo(stream *Stream) {
  322. if len(any.remaining) == len(any.buf) {
  323. // nothing has been parsed yet
  324. stream.Write(any.buf)
  325. } else {
  326. any.fillCache()
  327. stream.WriteVal(any.cache)
  328. }
  329. }
  330. func (any *objectLazyAny) GetInterface() interface{} {
  331. any.fillCache()
  332. return any.cache
  333. }
  334. type objectAny struct {
  335. baseAny
  336. err error
  337. cache map[string]Any
  338. val reflect.Value
  339. }
  340. func wrapStruct(val interface{}) *objectAny {
  341. return &objectAny{baseAny{}, nil, nil, reflect.ValueOf(val)}
  342. }
  343. func (any *objectAny) ValueType() ValueType {
  344. return Object
  345. }
  346. func (any *objectAny) Parse() *Iterator {
  347. return nil
  348. }
  349. func (any *objectAny) fillCacheUntil(target string) Any {
  350. if any.cache == nil {
  351. any.cache = map[string]Any{}
  352. }
  353. element, found := any.cache[target]
  354. if found {
  355. return element
  356. }
  357. for i := len(any.cache); i < any.val.NumField(); i++ {
  358. field := any.val.Field(i)
  359. fieldName := any.val.Type().Field(i).Name
  360. var element Any
  361. if field.CanInterface() {
  362. element = Wrap(field.Interface())
  363. } else {
  364. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", fieldName, any.cache)}
  365. }
  366. any.cache[fieldName] = element
  367. if fieldName == target {
  368. return element
  369. }
  370. }
  371. return nil
  372. }
  373. func (any *objectAny) fillCache() {
  374. if any.cache == nil {
  375. any.cache = map[string]Any{}
  376. }
  377. if len(any.cache) == any.val.NumField() {
  378. return
  379. }
  380. for i := 0; i < any.val.NumField(); i++ {
  381. field := any.val.Field(i)
  382. fieldName := any.val.Type().Field(i).Name
  383. var element Any
  384. if field.CanInterface() {
  385. element = Wrap(field.Interface())
  386. } else {
  387. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", fieldName, any.cache)}
  388. }
  389. any.cache[fieldName] = element
  390. }
  391. }
  392. func (any *objectAny) LastError() error {
  393. return any.err
  394. }
  395. func (any *objectAny) ToBool() bool {
  396. return any.val.NumField() != 0
  397. }
  398. func (any *objectAny) ToInt() int {
  399. if any.val.NumField() == 0 {
  400. return 0
  401. }
  402. return 1
  403. }
  404. func (any *objectAny) ToInt32() int32 {
  405. if any.val.NumField() == 0 {
  406. return 0
  407. }
  408. return 1
  409. }
  410. func (any *objectAny) ToInt64() int64 {
  411. if any.val.NumField() == 0 {
  412. return 0
  413. }
  414. return 1
  415. }
  416. func (any *objectAny) ToUint() uint {
  417. if any.val.NumField() == 0 {
  418. return 0
  419. }
  420. return 1
  421. }
  422. func (any *objectAny) ToUint32() uint32 {
  423. if any.val.NumField() == 0 {
  424. return 0
  425. }
  426. return 1
  427. }
  428. func (any *objectAny) ToUint64() uint64 {
  429. if any.val.NumField() == 0 {
  430. return 0
  431. }
  432. return 1
  433. }
  434. func (any *objectAny) ToFloat32() float32 {
  435. if any.val.NumField() == 0 {
  436. return 0
  437. }
  438. return 1
  439. }
  440. func (any *objectAny) ToFloat64() float64 {
  441. if any.val.NumField() == 0 {
  442. return 0
  443. }
  444. return 1
  445. }
  446. func (any *objectAny) ToString() string {
  447. if len(any.cache) == 0 {
  448. str, err := MarshalToString(any.val.Interface())
  449. any.err = err
  450. return str
  451. } else {
  452. any.fillCache()
  453. str, err := MarshalToString(any.cache)
  454. any.err = err
  455. return str
  456. }
  457. }
  458. func (any *objectAny) Get(path ...interface{}) Any {
  459. if len(path) == 0 {
  460. return any
  461. }
  462. var element Any
  463. switch firstPath := path[0].(type) {
  464. case string:
  465. element = any.fillCacheUntil(firstPath)
  466. if element == nil {
  467. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  468. }
  469. case int32:
  470. if '*' == firstPath {
  471. any.fillCache()
  472. mappedAll := map[string]Any{}
  473. for key, value := range any.cache {
  474. mapped := value.Get(path[1:]...)
  475. if mapped.ValueType() != Invalid {
  476. mappedAll[key] = mapped
  477. }
  478. }
  479. return wrapMap(mappedAll)
  480. } else {
  481. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  482. }
  483. default:
  484. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  485. }
  486. if len(path) == 1 {
  487. return element
  488. } else {
  489. return element.Get(path[1:]...)
  490. }
  491. }
  492. func (any *objectAny) Keys() []string {
  493. any.fillCache()
  494. keys := make([]string, 0, len(any.cache))
  495. for key := range any.cache {
  496. keys = append(keys, key)
  497. }
  498. return keys
  499. }
  500. func (any *objectAny) Size() int {
  501. any.fillCache()
  502. return len(any.cache)
  503. }
  504. func (any *objectAny) IterateObject() (func() (string, Any, bool), bool) {
  505. if any.cache == nil {
  506. any.cache = map[string]Any{}
  507. }
  508. if any.val.NumField() == 0 {
  509. return nil, false
  510. }
  511. cacheKeys := make([]string, len(any.cache))
  512. i := 0
  513. for key := range any.cache {
  514. cacheKeys[i] = key
  515. i++
  516. }
  517. i = 0
  518. return func() (string, Any, bool) {
  519. if i == any.val.NumField() {
  520. return "", nil, false
  521. }
  522. var fieldName string
  523. var fieldValueAsAny Any
  524. if i == len(cacheKeys) {
  525. fieldName = any.val.Type().Field(i).Name
  526. cacheKeys = append(cacheKeys, fieldName)
  527. fieldValue := any.val.Field(i)
  528. if fieldValue.CanInterface() {
  529. fieldValueAsAny = Wrap(fieldValue.Interface())
  530. any.cache[fieldName] = fieldValueAsAny
  531. } else {
  532. fieldValueAsAny = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", fieldName, any.cache)}
  533. any.cache[fieldName] = fieldValueAsAny
  534. }
  535. } else {
  536. fieldName = cacheKeys[i]
  537. fieldValueAsAny = any.cache[fieldName]
  538. }
  539. i++
  540. return fieldName, fieldValueAsAny, i != any.val.NumField()
  541. }, true
  542. }
  543. func (any *objectAny) GetObject() map[string]Any {
  544. any.fillCache()
  545. return any.cache
  546. }
  547. func (any *objectAny) SetObject(val map[string]Any) bool {
  548. any.fillCache()
  549. any.cache = val
  550. return true
  551. }
  552. func (any *objectAny) WriteTo(stream *Stream) {
  553. if len(any.cache) == 0 {
  554. // nothing has been parsed yet
  555. stream.WriteVal(any.val)
  556. } else {
  557. any.fillCache()
  558. stream.WriteVal(any.cache)
  559. }
  560. }
  561. func (any *objectAny) GetInterface() interface{} {
  562. any.fillCache()
  563. return any.cache
  564. }
  565. type mapAny struct {
  566. baseAny
  567. err error
  568. cache map[string]Any
  569. val reflect.Value
  570. }
  571. func wrapMap(val interface{}) *mapAny {
  572. return &mapAny{baseAny{}, nil, nil, reflect.ValueOf(val)}
  573. }
  574. func (any *mapAny) ValueType() ValueType {
  575. return Object
  576. }
  577. func (any *mapAny) Parse() *Iterator {
  578. return nil
  579. }
  580. func (any *mapAny) fillCacheUntil(target string) Any {
  581. if any.cache == nil {
  582. any.cache = map[string]Any{}
  583. }
  584. element, found := any.cache[target]
  585. if found {
  586. return element
  587. }
  588. for _, key := range any.val.MapKeys() {
  589. keyAsStr := key.String()
  590. _, found := any.cache[keyAsStr]
  591. if found {
  592. continue
  593. }
  594. element := Wrap(any.val.MapIndex(key).Interface())
  595. any.cache[keyAsStr] = element
  596. if keyAsStr == target {
  597. return element
  598. }
  599. }
  600. return nil
  601. }
  602. func (any *mapAny) fillCache() {
  603. if any.cache == nil {
  604. any.cache = map[string]Any{}
  605. }
  606. if len(any.cache) == any.val.Len() {
  607. return
  608. }
  609. for _, key := range any.val.MapKeys() {
  610. keyAsStr := key.String()
  611. element := Wrap(any.val.MapIndex(key).Interface())
  612. any.cache[keyAsStr] = element
  613. }
  614. }
  615. func (any *mapAny) LastError() error {
  616. return any.err
  617. }
  618. func (any *mapAny) ToBool() bool {
  619. return any.val.Len() != 0
  620. }
  621. func (any *mapAny) ToInt() int {
  622. if any.val.Len() == 0 {
  623. return 0
  624. }
  625. return 1
  626. }
  627. func (any *mapAny) ToInt32() int32 {
  628. if any.val.Len() == 0 {
  629. return 0
  630. }
  631. return 1
  632. }
  633. func (any *mapAny) ToInt64() int64 {
  634. if any.val.Len() == 0 {
  635. return 0
  636. }
  637. return 1
  638. }
  639. func (any *mapAny) ToUint() uint {
  640. if any.val.Len() == 0 {
  641. return 0
  642. }
  643. return 1
  644. }
  645. func (any *mapAny) ToUint32() uint32 {
  646. if any.val.Len() == 0 {
  647. return 0
  648. }
  649. return 1
  650. }
  651. func (any *mapAny) ToUint64() uint64 {
  652. if any.val.Len() == 0 {
  653. return 0
  654. }
  655. return 1
  656. }
  657. func (any *mapAny) ToFloat32() float32 {
  658. if any.val.Len() == 0 {
  659. return 0
  660. }
  661. return 1
  662. }
  663. func (any *mapAny) ToFloat64() float64 {
  664. if any.val.Len() == 0 {
  665. return 0
  666. }
  667. return 1
  668. }
  669. func (any *mapAny) ToString() string {
  670. if len(any.cache) == 0 {
  671. str, err := MarshalToString(any.val.Interface())
  672. any.err = err
  673. return str
  674. } else {
  675. any.fillCache()
  676. str, err := MarshalToString(any.cache)
  677. any.err = err
  678. return str
  679. }
  680. }
  681. func (any *mapAny) Get(path ...interface{}) Any {
  682. if len(path) == 0 {
  683. return any
  684. }
  685. var element Any
  686. switch firstPath := path[0].(type) {
  687. case string:
  688. element = any.fillCacheUntil(firstPath)
  689. if element == nil {
  690. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  691. }
  692. case int32:
  693. if '*' == firstPath {
  694. any.fillCache()
  695. mappedAll := map[string]Any{}
  696. for key, value := range any.cache {
  697. mapped := value.Get(path[1:]...)
  698. if mapped.ValueType() != Invalid {
  699. mappedAll[key] = mapped
  700. }
  701. }
  702. return wrapMap(mappedAll)
  703. } else {
  704. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  705. }
  706. default:
  707. element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
  708. }
  709. if len(path) == 1 {
  710. return element
  711. } else {
  712. return element.Get(path[1:]...)
  713. }
  714. }
  715. func (any *mapAny) Keys() []string {
  716. any.fillCache()
  717. keys := make([]string, 0, len(any.cache))
  718. for key := range any.cache {
  719. keys = append(keys, key)
  720. }
  721. return keys
  722. }
  723. func (any *mapAny) Size() int {
  724. any.fillCache()
  725. return len(any.cache)
  726. }
  727. func (any *mapAny) IterateObject() (func() (string, Any, bool), bool) {
  728. any.fillCache()
  729. if len(any.cache) == 0 {
  730. return nil, false
  731. }
  732. keys := make([]string, len(any.cache))
  733. values := make([]Any, len(any.cache))
  734. i := 0
  735. for k, v := range any.cache {
  736. keys[i] = k
  737. values[i] = v
  738. i++
  739. }
  740. i = 0
  741. return func() (string, Any, bool) {
  742. if i == len(keys) {
  743. return "", nil, false
  744. }
  745. k := keys[i]
  746. v := values[i]
  747. i++
  748. return k, v, i != len(keys)
  749. }, true
  750. }
  751. func (any *mapAny) GetObject() map[string]Any {
  752. any.fillCache()
  753. return any.cache
  754. }
  755. func (any *mapAny) SetObject(val map[string]Any) bool {
  756. any.fillCache()
  757. any.cache = val
  758. return true
  759. }
  760. func (any *mapAny) WriteTo(stream *Stream) {
  761. if len(any.cache) == 0 {
  762. // nothing has been parsed yet
  763. stream.WriteVal(any.val)
  764. } else {
  765. any.fillCache()
  766. stream.WriteVal(any.cache)
  767. }
  768. }
  769. func (any *mapAny) GetInterface() interface{} {
  770. any.fillCache()
  771. return any.cache
  772. }