Skip to content

Commit

Permalink
Use our own json handle for decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
tolikzinovyev committed Nov 1, 2021
1 parent a5a575e commit 732f355
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
7 changes: 5 additions & 2 deletions idb/postgres/internal/encoding/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-codec/codec"

"github.com/algorand/indexer/idb"
"github.com/algorand/indexer/idb/postgres/internal/types"
)

// DecodeJSON is a function that decodes json.
var DecodeJSON = protocol.DecodeJSON
func DecodeJSON(b []byte, objptr interface{}) error {
dec := codec.NewDecoderBytes(b, jsonCodecHandle)
return dec.Decode(objptr)
}

func decodeBase64(data string) ([]byte, error) {
return base64.StdEncoding.DecodeString(data)
Expand Down
13 changes: 0 additions & 13 deletions idb/postgres/internal/encoding/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/algorand/indexer/util"
)

var jsonCodecHandle *codec.JsonHandle

// encodeJSON converts an object into JSON
func encodeJSON(obj interface{}) []byte {
var buf []byte
Expand Down Expand Up @@ -288,14 +286,3 @@ func EncodeMigrationState(state *types.MigrationState) []byte {
func EncodeAccountTotals(totals *ledgercore.AccountTotals) []byte {
return encodeJSON(totals)
}

func init() {
jsonCodecHandle = new(codec.JsonHandle)
jsonCodecHandle.ErrorIfNoField = true
jsonCodecHandle.ErrorIfNoArrayExpand = true
jsonCodecHandle.Canonical = true
jsonCodecHandle.RecursiveEmptyCheck = true
jsonCodecHandle.HTMLCharsAsIs = true
jsonCodecHandle.Indent = 0
jsonCodecHandle.MapKeyAsString = true
}
18 changes: 18 additions & 0 deletions idb/postgres/internal/encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package encoding

import (
"github.com/algorand/go-codec/codec"
)

var jsonCodecHandle *codec.JsonHandle

func init() {
jsonCodecHandle = new(codec.JsonHandle)
jsonCodecHandle.ErrorIfNoField = true
jsonCodecHandle.ErrorIfNoArrayExpand = true
jsonCodecHandle.Canonical = true
jsonCodecHandle.RecursiveEmptyCheck = true
jsonCodecHandle.HTMLCharsAsIs = true
jsonCodecHandle.Indent = 0
jsonCodecHandle.MapKeyAsString = true
}

0 comments on commit 732f355

Please sign in to comment.