Skip to content

Commit

Permalink
Add parse function for an array
Browse files Browse the repository at this point in the history
This allows the remote object to be parsed into an array if that is
what it is instead of an object where the keys are index values.
  • Loading branch information
ankur22 committed Dec 15, 2023
1 parent 3bcb2e2 commit f0c5d58
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions common/remote_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,25 @@ func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPr
return string(bb)
}

func parseConsoleRemoteArrayPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) string {
arr := make([]any, 0)
if op.Overflow {
logger.Warnf("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially")
}

for _, p := range op.Properties {
val := parseConsoleRemoteObjectValue(logger, p.Type, p.Subtype, p.Value, p.ValuePreview)
arr = append(arr, val)
}

bb, err := json.Marshal(arr)
if err != nil {
logger.Errorf("parseConsoleRemoteArrayPreview", "failed to marshal array to string: %v", err)
}

return string(bb)
}

//nolint:cyclop
func parseConsoleRemoteObjectValue(
logger *log.Logger,
Expand Down

0 comments on commit f0c5d58

Please sign in to comment.