From 001a80226ac29c8a916c3435d83e9dad037a17a8 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:41:51 +0800 Subject: [PATCH] feat: add `RowConsumption` & `RowUsage` types (#625) --- core/types/gen_row_consumption_json.go | 41 ++++++++++++++++++++++++++ core/types/row_consumption.go | 15 ++++++++++ 2 files changed, 56 insertions(+) create mode 100644 core/types/gen_row_consumption_json.go create mode 100644 core/types/row_consumption.go diff --git a/core/types/gen_row_consumption_json.go b/core/types/gen_row_consumption_json.go new file mode 100644 index 0000000000..deed91700f --- /dev/null +++ b/core/types/gen_row_consumption_json.go @@ -0,0 +1,41 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package types + +import ( + "encoding/json" + "errors" +) + +// MarshalJSON marshals as JSON. +func (s SubCircuitRowUsage) MarshalJSON() ([]byte, error) { + type SubCircuitRowUsage struct { + Name string `json:"name" gencodec:"required"` + RowNumber uint64 `json:"row_number" gencodec:"required"` + } + var enc SubCircuitRowUsage + enc.Name = s.Name + enc.RowNumber = s.RowNumber + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (s *SubCircuitRowUsage) UnmarshalJSON(input []byte) error { + type SubCircuitRowUsage struct { + Name *string `json:"name" gencodec:"required"` + RowNumber *uint64 `json:"row_number" gencodec:"required"` + } + var dec SubCircuitRowUsage + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.Name == nil { + return errors.New("missing required field 'name' for SubCircuitRowUsage") + } + s.Name = *dec.Name + if dec.RowNumber == nil { + return errors.New("missing required field 'row_number' for SubCircuitRowUsage") + } + s.RowNumber = *dec.RowNumber + return nil +} diff --git a/core/types/row_consumption.go b/core/types/row_consumption.go new file mode 100644 index 0000000000..8d11479418 --- /dev/null +++ b/core/types/row_consumption.go @@ -0,0 +1,15 @@ +package types + +type RowUsage struct { + IsOk bool `json:"is_ok"` + RowNumber uint64 `json:"row_number"` + RowUsageDetails []SubCircuitRowUsage `json:"row_usage_details"` +} + +//go:generate gencodec -type SubCircuitRowUsage -out gen_row_consumption_json.go +type SubCircuitRowUsage struct { + Name string `json:"name" gencodec:"required"` + RowNumber uint64 `json:"row_number" gencodec:"required"` +} + +type RowConsumption []SubCircuitRowUsage