Skip to content

Commit

Permalink
fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Aug 7, 2023
1 parent 63b544f commit f9ef0fd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,20 @@ func (b *Blob) Namespace() share.Namespace {
}

type jsonBlob struct {
Namespace share.Namespace `json:"namespace"`
Data []byte `json:"data"`
ShareVersion uint32 `json:"share_version"`
Commitment Commitment `json:"commitment"`
Namespace share.Namespace `json:"namespace"`
// According to the Go documentation:
// Array and slice values encode as JSON arrays,
// except that []byte encodes as a base64-encoded string.
// So, this led to the incorrect representation of the `Data`.
Data string `json:"data"`
ShareVersion uint32 `json:"share_version"`
Commitment Commitment `json:"commitment"`
}

func (b *Blob) MarshalJSON() ([]byte, error) {
blob := &jsonBlob{
Namespace: b.Namespace(),
Data: b.Data,
Data: string(b.Data),
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
}
Expand All @@ -169,7 +173,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error {

b.Blob.NamespaceVersion = uint32(blob.Namespace.Version())
b.Blob.NamespaceId = blob.Namespace.ID()
b.Blob.Data = blob.Data
b.Blob.Data = []byte(blob.Data)
b.Blob.ShareVersion = blob.ShareVersion
b.Commitment = blob.Commitment
b.namespace = blob.Namespace
Expand Down

0 comments on commit f9ef0fd

Please sign in to comment.