pricingmodel_codecs.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package pricingmodel
  12. import (
  13. "fmt"
  14. "reflect"
  15. "strings"
  16. "sync"
  17. "time"
  18. "github.com/opencost/opencost/core/pkg/model/shared"
  19. "github.com/opencost/opencost/core/pkg/util"
  20. )
  21. const (
  22. // GeneratorPackageName is the package the generator is targetting
  23. GeneratorPackageName string = "pricingmodel"
  24. )
  25. // BinaryTags represent the formatting tag used for specific optimization features
  26. const (
  27. // BinaryTagStringTable is written and/or read prior to the existence of a string
  28. // table (where each index is encoded as a string entry in the resource
  29. BinaryTagStringTable string = "BGST"
  30. )
  31. const (
  32. // DefaultCodecVersion is used for any resources listed in the Default version set
  33. DefaultCodecVersion uint8 = 1
  34. )
  35. //--------------------------------------------------------------------------
  36. // Type Map
  37. //--------------------------------------------------------------------------
  38. // Generated type map for resolving interface implementations to
  39. // to concrete types
  40. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  41. "NodeKey": reflect.TypeOf((*NodeKey)(nil)).Elem(),
  42. "NodePricing": reflect.TypeOf((*NodePricing)(nil)).Elem(),
  43. "PricingModelSet": reflect.TypeOf((*PricingModelSet)(nil)).Elem(),
  44. }
  45. //--------------------------------------------------------------------------
  46. // Type Helpers
  47. //--------------------------------------------------------------------------
  48. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  49. func isBinaryTag(data []byte, tag string) bool {
  50. return string(data[:len(tag)]) == tag
  51. }
  52. // appendBytes combines a and b into a new byte array
  53. func appendBytes(a []byte, b []byte) []byte {
  54. al := len(a)
  55. bl := len(b)
  56. tl := al + bl
  57. // allocate a new byte array for the combined
  58. // use native copy for speedy byte copying
  59. result := make([]byte, tl, tl)
  60. copy(result, a)
  61. copy(result[al:], b)
  62. return result
  63. }
  64. // typeToString determines the basic properties of the type, the qualifier, package path, and
  65. // type name, and returns the qualified type
  66. func typeToString(f interface{}) string {
  67. qual := ""
  68. t := reflect.TypeOf(f)
  69. if t.Kind() == reflect.Ptr {
  70. t = t.Elem()
  71. qual = "*"
  72. }
  73. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  74. }
  75. // resolveType uses the name of a type and returns the package, base type name, and whether
  76. // or not it's a pointer.
  77. func resolveType(t string) (pkg string, name string, isPtr bool) {
  78. isPtr = t[:1] == "*"
  79. if isPtr {
  80. t = t[1:]
  81. }
  82. slashIndex := strings.LastIndex(t, "/")
  83. if slashIndex >= 0 {
  84. t = t[slashIndex+1:]
  85. }
  86. parts := strings.Split(t, ".")
  87. if parts[0] == GeneratorPackageName {
  88. parts[0] = ""
  89. }
  90. pkg = parts[0]
  91. name = parts[1]
  92. return
  93. }
  94. //--------------------------------------------------------------------------
  95. // StringTable
  96. //--------------------------------------------------------------------------
  97. // StringTable maps strings to specific indices for encoding
  98. type StringTable struct {
  99. l *sync.Mutex
  100. indices map[string]int
  101. next int
  102. }
  103. // NewStringTable Creates a new StringTable instance with provided contents
  104. func NewStringTable(contents ...string) *StringTable {
  105. st := &StringTable{
  106. l: new(sync.Mutex),
  107. indices: make(map[string]int),
  108. next: len(contents),
  109. }
  110. for i, entry := range contents {
  111. st.indices[entry] = i
  112. }
  113. return st
  114. }
  115. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  116. // add the entry and return the index.
  117. func (st *StringTable) AddOrGet(s string) int {
  118. st.l.Lock()
  119. defer st.l.Unlock()
  120. if ind, ok := st.indices[s]; ok {
  121. return ind
  122. }
  123. current := st.next
  124. st.next++
  125. st.indices[s] = current
  126. return current
  127. }
  128. // ToSlice Converts the contents to a string array for encoding.
  129. func (st *StringTable) ToSlice() []string {
  130. st.l.Lock()
  131. defer st.l.Unlock()
  132. if st.next == 0 {
  133. return []string{}
  134. }
  135. sl := make([]string, st.next, st.next)
  136. for s, i := range st.indices {
  137. sl[i] = s
  138. }
  139. return sl
  140. }
  141. // ToBytes Converts the contents to a binary encoded representation
  142. func (st *StringTable) ToBytes() []byte {
  143. buff := util.NewBuffer()
  144. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  145. strs := st.ToSlice()
  146. buff.WriteInt(len(strs)) // table length
  147. for _, s := range strs {
  148. buff.WriteString(s)
  149. }
  150. return buff.Bytes()
  151. }
  152. //--------------------------------------------------------------------------
  153. // Codec Context
  154. //--------------------------------------------------------------------------
  155. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  156. // and table data
  157. type EncodingContext struct {
  158. Buffer *util.Buffer
  159. Table *StringTable
  160. }
  161. // IsStringTable returns true if the table is available
  162. func (ec *EncodingContext) IsStringTable() bool {
  163. return ec.Table != nil
  164. }
  165. // DecodingContext is a context object passed to the decoders to ensure parent objects
  166. // reuse as much data as possible
  167. type DecodingContext struct {
  168. Buffer *util.Buffer
  169. Table []string
  170. }
  171. // IsStringTable returns true if the table is available
  172. func (dc *DecodingContext) IsStringTable() bool {
  173. return len(dc.Table) > 0
  174. }
  175. //--------------------------------------------------------------------------
  176. // Binary Codec
  177. //--------------------------------------------------------------------------
  178. // BinEncoder is an encoding interface which defines a context based marshal contract.
  179. type BinEncoder interface {
  180. MarshalBinaryWithContext(*EncodingContext) error
  181. }
  182. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  183. type BinDecoder interface {
  184. UnmarshalBinaryWithContext(*DecodingContext) error
  185. }
  186. //--------------------------------------------------------------------------
  187. // NodeKey
  188. //--------------------------------------------------------------------------
  189. // MarshalBinary serializes the internal properties of this NodeKey instance
  190. // into a byte array
  191. func (target *NodeKey) MarshalBinary() (data []byte, err error) {
  192. ctx := &EncodingContext{
  193. Buffer: util.NewBuffer(),
  194. Table: nil,
  195. }
  196. e := target.MarshalBinaryWithContext(ctx)
  197. if e != nil {
  198. return nil, e
  199. }
  200. encBytes := ctx.Buffer.Bytes()
  201. return encBytes, nil
  202. }
  203. // MarshalBinaryWithContext serializes the internal properties of this NodeKey instance
  204. // into a byte array leveraging a predefined context.
  205. func (target *NodeKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  206. // panics are recovered and propagated as errors
  207. defer func() {
  208. if r := recover(); r != nil {
  209. if e, ok := r.(error); ok {
  210. err = e
  211. } else if s, ok := r.(string); ok {
  212. err = fmt.Errorf("Unexpected panic: %s", s)
  213. } else {
  214. err = fmt.Errorf("Unexpected panic: %+v", r)
  215. }
  216. }
  217. }()
  218. buff := ctx.Buffer
  219. buff.WriteUInt8(DefaultCodecVersion) // version
  220. // --- [begin][write][alias](shared.Provider) ---
  221. if ctx.IsStringTable() {
  222. a := ctx.Table.AddOrGet(string(target.Provider))
  223. buff.WriteInt(a) // write table index
  224. } else {
  225. buff.WriteString(string(target.Provider)) // write string
  226. }
  227. // --- [end][write][alias](shared.Provider) ---
  228. if ctx.IsStringTable() {
  229. b := ctx.Table.AddOrGet(target.Region)
  230. buff.WriteInt(b) // write table index
  231. } else {
  232. buff.WriteString(target.Region) // write string
  233. }
  234. if ctx.IsStringTable() {
  235. c := ctx.Table.AddOrGet(target.NodeType)
  236. buff.WriteInt(c) // write table index
  237. } else {
  238. buff.WriteString(target.NodeType) // write string
  239. }
  240. // --- [begin][write][alias](shared.UsageType) ---
  241. if ctx.IsStringTable() {
  242. d := ctx.Table.AddOrGet(string(target.UsageType))
  243. buff.WriteInt(d) // write table index
  244. } else {
  245. buff.WriteString(string(target.UsageType)) // write string
  246. }
  247. // --- [end][write][alias](shared.UsageType) ---
  248. if ctx.IsStringTable() {
  249. e := ctx.Table.AddOrGet(target.Family)
  250. buff.WriteInt(e) // write table index
  251. } else {
  252. buff.WriteString(target.Family) // write string
  253. }
  254. if ctx.IsStringTable() {
  255. f := ctx.Table.AddOrGet(target.DeviceType)
  256. buff.WriteInt(f) // write table index
  257. } else {
  258. buff.WriteString(target.DeviceType) // write string
  259. }
  260. // --- [begin][write][alias](NodePricingType) ---
  261. if ctx.IsStringTable() {
  262. g := ctx.Table.AddOrGet(string(target.PricingType))
  263. buff.WriteInt(g) // write table index
  264. } else {
  265. buff.WriteString(string(target.PricingType)) // write string
  266. }
  267. // --- [end][write][alias](NodePricingType) ---
  268. return nil
  269. }
  270. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  271. // the NodeKey type
  272. func (target *NodeKey) UnmarshalBinary(data []byte) error {
  273. var table []string
  274. buff := util.NewBufferFromBytes(data)
  275. // string table header validation
  276. if isBinaryTag(data, BinaryTagStringTable) {
  277. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  278. tl := buff.ReadInt() // table length
  279. if tl > 0 {
  280. table = make([]string, tl, tl)
  281. for i := 0; i < tl; i++ {
  282. table[i] = buff.ReadString()
  283. }
  284. }
  285. }
  286. ctx := &DecodingContext{
  287. Buffer: buff,
  288. Table: table,
  289. }
  290. err := target.UnmarshalBinaryWithContext(ctx)
  291. if err != nil {
  292. return err
  293. }
  294. return nil
  295. }
  296. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  297. // the NodeKey type
  298. func (target *NodeKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  299. // panics are recovered and propagated as errors
  300. defer func() {
  301. if r := recover(); r != nil {
  302. if e, ok := r.(error); ok {
  303. err = e
  304. } else if s, ok := r.(string); ok {
  305. err = fmt.Errorf("Unexpected panic: %s", s)
  306. } else {
  307. err = fmt.Errorf("Unexpected panic: %+v", r)
  308. }
  309. }
  310. }()
  311. buff := ctx.Buffer
  312. version := buff.ReadUInt8()
  313. if version > DefaultCodecVersion {
  314. return fmt.Errorf("Invalid Version Unmarshaling NodeKey. Expected %d or less, got %d", DefaultCodecVersion, version)
  315. }
  316. // --- [begin][read][alias](shared.Provider) ---
  317. var a string
  318. if ctx.IsStringTable() {
  319. b := buff.ReadInt() // read string index
  320. a = ctx.Table[b]
  321. } else {
  322. a = buff.ReadString() // read string
  323. }
  324. target.Provider = shared.Provider(a)
  325. // --- [end][read][alias](shared.Provider) ---
  326. var e string
  327. if ctx.IsStringTable() {
  328. f := buff.ReadInt() // read string index
  329. e = ctx.Table[f]
  330. } else {
  331. e = buff.ReadString() // read string
  332. }
  333. d := e
  334. target.Region = d
  335. var h string
  336. if ctx.IsStringTable() {
  337. k := buff.ReadInt() // read string index
  338. h = ctx.Table[k]
  339. } else {
  340. h = buff.ReadString() // read string
  341. }
  342. g := h
  343. target.NodeType = g
  344. // --- [begin][read][alias](shared.UsageType) ---
  345. var l string
  346. if ctx.IsStringTable() {
  347. m := buff.ReadInt() // read string index
  348. l = ctx.Table[m]
  349. } else {
  350. l = buff.ReadString() // read string
  351. }
  352. target.UsageType = shared.UsageType(l)
  353. // --- [end][read][alias](shared.UsageType) ---
  354. var p string
  355. if ctx.IsStringTable() {
  356. q := buff.ReadInt() // read string index
  357. p = ctx.Table[q]
  358. } else {
  359. p = buff.ReadString() // read string
  360. }
  361. o := p
  362. target.Family = o
  363. var s string
  364. if ctx.IsStringTable() {
  365. t := buff.ReadInt() // read string index
  366. s = ctx.Table[t]
  367. } else {
  368. s = buff.ReadString() // read string
  369. }
  370. r := s
  371. target.DeviceType = r
  372. // --- [begin][read][alias](NodePricingType) ---
  373. var u string
  374. var x string
  375. if ctx.IsStringTable() {
  376. y := buff.ReadInt() // read string index
  377. x = ctx.Table[y]
  378. } else {
  379. x = buff.ReadString() // read string
  380. }
  381. w := x
  382. u = w
  383. target.PricingType = NodePricingType(u)
  384. // --- [end][read][alias](NodePricingType) ---
  385. return nil
  386. }
  387. //--------------------------------------------------------------------------
  388. // NodePricing
  389. //--------------------------------------------------------------------------
  390. // MarshalBinary serializes the internal properties of this NodePricing instance
  391. // into a byte array
  392. func (target *NodePricing) MarshalBinary() (data []byte, err error) {
  393. ctx := &EncodingContext{
  394. Buffer: util.NewBuffer(),
  395. Table: nil,
  396. }
  397. e := target.MarshalBinaryWithContext(ctx)
  398. if e != nil {
  399. return nil, e
  400. }
  401. encBytes := ctx.Buffer.Bytes()
  402. return encBytes, nil
  403. }
  404. // MarshalBinaryWithContext serializes the internal properties of this NodePricing instance
  405. // into a byte array leveraging a predefined context.
  406. func (target *NodePricing) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  407. // panics are recovered and propagated as errors
  408. defer func() {
  409. if r := recover(); r != nil {
  410. if e, ok := r.(error); ok {
  411. err = e
  412. } else if s, ok := r.(string); ok {
  413. err = fmt.Errorf("Unexpected panic: %s", s)
  414. } else {
  415. err = fmt.Errorf("Unexpected panic: %+v", r)
  416. }
  417. }
  418. }()
  419. buff := ctx.Buffer
  420. buff.WriteUInt8(DefaultCodecVersion) // version
  421. buff.WriteFloat64(target.HourlyRate) // write float64
  422. return nil
  423. }
  424. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  425. // the NodePricing type
  426. func (target *NodePricing) UnmarshalBinary(data []byte) error {
  427. var table []string
  428. buff := util.NewBufferFromBytes(data)
  429. // string table header validation
  430. if isBinaryTag(data, BinaryTagStringTable) {
  431. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  432. tl := buff.ReadInt() // table length
  433. if tl > 0 {
  434. table = make([]string, tl, tl)
  435. for i := 0; i < tl; i++ {
  436. table[i] = buff.ReadString()
  437. }
  438. }
  439. }
  440. ctx := &DecodingContext{
  441. Buffer: buff,
  442. Table: table,
  443. }
  444. err := target.UnmarshalBinaryWithContext(ctx)
  445. if err != nil {
  446. return err
  447. }
  448. return nil
  449. }
  450. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  451. // the NodePricing type
  452. func (target *NodePricing) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  453. // panics are recovered and propagated as errors
  454. defer func() {
  455. if r := recover(); r != nil {
  456. if e, ok := r.(error); ok {
  457. err = e
  458. } else if s, ok := r.(string); ok {
  459. err = fmt.Errorf("Unexpected panic: %s", s)
  460. } else {
  461. err = fmt.Errorf("Unexpected panic: %+v", r)
  462. }
  463. }
  464. }()
  465. buff := ctx.Buffer
  466. version := buff.ReadUInt8()
  467. if version > DefaultCodecVersion {
  468. return fmt.Errorf("Invalid Version Unmarshaling NodePricing. Expected %d or less, got %d", DefaultCodecVersion, version)
  469. }
  470. a := buff.ReadFloat64() // read float64
  471. target.HourlyRate = a
  472. return nil
  473. }
  474. //--------------------------------------------------------------------------
  475. // PricingModelSet
  476. //--------------------------------------------------------------------------
  477. // MarshalBinary serializes the internal properties of this PricingModelSet instance
  478. // into a byte array
  479. func (target *PricingModelSet) MarshalBinary() (data []byte, err error) {
  480. ctx := &EncodingContext{
  481. Buffer: util.NewBuffer(),
  482. Table: nil,
  483. }
  484. e := target.MarshalBinaryWithContext(ctx)
  485. if e != nil {
  486. return nil, e
  487. }
  488. encBytes := ctx.Buffer.Bytes()
  489. return encBytes, nil
  490. }
  491. // MarshalBinaryWithContext serializes the internal properties of this PricingModelSet instance
  492. // into a byte array leveraging a predefined context.
  493. func (target *PricingModelSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  494. // panics are recovered and propagated as errors
  495. defer func() {
  496. if r := recover(); r != nil {
  497. if e, ok := r.(error); ok {
  498. err = e
  499. } else if s, ok := r.(string); ok {
  500. err = fmt.Errorf("Unexpected panic: %s", s)
  501. } else {
  502. err = fmt.Errorf("Unexpected panic: %+v", r)
  503. }
  504. }
  505. }()
  506. buff := ctx.Buffer
  507. buff.WriteUInt8(DefaultCodecVersion) // version
  508. // --- [begin][write][reference](time.Time) ---
  509. a, errA := target.TimeStamp.MarshalBinary()
  510. if errA != nil {
  511. return errA
  512. }
  513. buff.WriteInt(len(a))
  514. buff.WriteBytes(a)
  515. // --- [end][write][reference](time.Time) ---
  516. if ctx.IsStringTable() {
  517. b := ctx.Table.AddOrGet(string(target.SourceType))
  518. buff.WriteInt(b) // write table index
  519. } else {
  520. buff.WriteString(string(target.SourceType)) // write string
  521. }
  522. if target.NodePricing == nil {
  523. buff.WriteUInt8(uint8(0)) // write nil byte
  524. } else {
  525. buff.WriteUInt8(uint8(1)) // write non-nil byte
  526. // --- [begin][write][map](map[NodeKey]NodePricing) ---
  527. buff.WriteInt(len(target.NodePricing)) // map length
  528. for v, z := range target.NodePricing {
  529. // --- [begin][write][struct](NodeKey) ---
  530. buff.WriteInt(0) // [compatibility, unused]
  531. errB := v.MarshalBinaryWithContext(ctx)
  532. if errB != nil {
  533. return errB
  534. }
  535. // --- [end][write][struct](NodeKey) ---
  536. // --- [begin][write][struct](NodePricing) ---
  537. buff.WriteInt(0) // [compatibility, unused]
  538. errC := z.MarshalBinaryWithContext(ctx)
  539. if errC != nil {
  540. return errC
  541. }
  542. // --- [end][write][struct](NodePricing) ---
  543. }
  544. // --- [end][write][map](map[NodeKey]NodePricing) ---
  545. }
  546. if ctx.IsStringTable() {
  547. i := ctx.Table.AddOrGet(target.SourceKey)
  548. buff.WriteInt(i) // write table index
  549. } else {
  550. buff.WriteString(target.SourceKey) // write string
  551. }
  552. return nil
  553. }
  554. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  555. // the PricingModelSet type
  556. func (target *PricingModelSet) UnmarshalBinary(data []byte) error {
  557. var table []string
  558. buff := util.NewBufferFromBytes(data)
  559. // string table header validation
  560. if isBinaryTag(data, BinaryTagStringTable) {
  561. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  562. tl := buff.ReadInt() // table length
  563. if tl > 0 {
  564. table = make([]string, tl, tl)
  565. for i := 0; i < tl; i++ {
  566. table[i] = buff.ReadString()
  567. }
  568. }
  569. }
  570. ctx := &DecodingContext{
  571. Buffer: buff,
  572. Table: table,
  573. }
  574. err := target.UnmarshalBinaryWithContext(ctx)
  575. if err != nil {
  576. return err
  577. }
  578. return nil
  579. }
  580. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  581. // the PricingModelSet type
  582. func (target *PricingModelSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  583. // panics are recovered and propagated as errors
  584. defer func() {
  585. if r := recover(); r != nil {
  586. if e, ok := r.(error); ok {
  587. err = e
  588. } else if s, ok := r.(string); ok {
  589. err = fmt.Errorf("Unexpected panic: %s", s)
  590. } else {
  591. err = fmt.Errorf("Unexpected panic: %+v", r)
  592. }
  593. }
  594. }()
  595. buff := ctx.Buffer
  596. version := buff.ReadUInt8()
  597. if version > DefaultCodecVersion {
  598. return fmt.Errorf("Invalid Version Unmarshaling PricingModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  599. }
  600. // --- [begin][read][reference](time.Time) ---
  601. a := &time.Time{}
  602. b := buff.ReadInt() // byte array length
  603. c := buff.ReadBytes(b) // byte array
  604. errA := a.UnmarshalBinary(c)
  605. if errA != nil {
  606. return errA
  607. }
  608. target.TimeStamp = *a
  609. // --- [end][read][reference](time.Time) ---
  610. var e string
  611. if ctx.IsStringTable() {
  612. f := buff.ReadInt() // read string index
  613. e = ctx.Table[f]
  614. } else {
  615. e = buff.ReadString() // read string
  616. }
  617. d := e
  618. target.SourceType = PricingSourceType(d)
  619. if buff.ReadUInt8() == uint8(0) {
  620. target.NodePricing = nil
  621. } else {
  622. // --- [begin][read][map](map[NodeKey]NodePricing) ---
  623. h := buff.ReadInt() // map len
  624. g := make(map[NodeKey]NodePricing, h)
  625. for i := 0; i < h; i++ {
  626. // --- [begin][read][struct](NodeKey) ---
  627. k := &NodeKey{}
  628. buff.ReadInt() // [compatibility, unused]
  629. errB := k.UnmarshalBinaryWithContext(ctx)
  630. if errB != nil {
  631. return errB
  632. }
  633. v := *k
  634. // --- [end][read][struct](NodeKey) ---
  635. // --- [begin][read][struct](NodePricing) ---
  636. l := &NodePricing{}
  637. buff.ReadInt() // [compatibility, unused]
  638. errC := l.UnmarshalBinaryWithContext(ctx)
  639. if errC != nil {
  640. return errC
  641. }
  642. z := *l
  643. // --- [end][read][struct](NodePricing) ---
  644. g[v] = z
  645. }
  646. target.NodePricing = g
  647. // --- [end][read][map](map[NodeKey]NodePricing) ---
  648. }
  649. var m string
  650. if ctx.IsStringTable() {
  651. n := buff.ReadInt() // read string index
  652. m = ctx.Table[n]
  653. } else {
  654. m = buff.ReadString() // read string
  655. }
  656. target.SourceKey = m
  657. return nil
  658. }