From 0151d3804d5560b36480a6bf5ba484d4eb402160 Mon Sep 17 00:00:00 2001 From: laser Date: Fri, 20 Sep 2019 13:43:54 -0700 Subject: [PATCH] feat(json): provide JSON marshal/unmashal functions for debugging --- bindings.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bindings.go b/bindings.go index f787814..d9bc25e 100644 --- a/bindings.go +++ b/bindings.go @@ -53,6 +53,20 @@ func (s *SortedSectorInfo) Values() []SectorInfo { return s.f } +// MarshalJSON JSON-encodes and serializes the SortedSectorInfo. +func (s SortedSectorInfo) MarshalJSON() ([]byte, error) { + return json.Marshal(s.f) +} + +// UnmarshalJSON parses the JSON-encoded byte slice and stores the result in the +// value pointed to by s.f. Note that this method allows for construction of a +// SortedSectorInfo which violates its invariant (that its SectorInfo are sorted +// in some defined way). Callers should take care to never provide a byte slice +// which would violate this invariant. +func (s *SortedSectorInfo) UnmarshalJSON(b []byte) error { + return json.Unmarshal(b, &s.f) +} + type SectorInfo struct { SectorID uint64 CommR [CommitmentBytesLen]byte