Skip to content

Commit

Permalink
cmd/octsdb: Support map[string]interface{value:x} in []interface{}
Browse files Browse the repository at this point in the history
This is the special case for simple value types that just have a single
"value" attribute, but now within a slice.

Change-Id: Ie631f0cd4c154b95f72f1ba3ceef051ff991b35d
  • Loading branch information
alexaliu committed Apr 29, 2020
1 parent 0b5ff22 commit 1940253
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/octsdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ func parseValue(update *pb.Update) []interface{} {
value[i] = v
case json.Number:
value[i] = parseNumber(val, update)
case map[string]interface{}:
if num, ok := val["value"].(json.Number); ok && len(val) == 1 {
value[i] = parseNumber(num, update)
}
default:
// If any value is not a number, skip it.
glog.Infof("Element %d: %v is %T, not json.Number", i, val, val)
glog.V(3).Infof("Element %d: %v is %T, not json.Number", i, val, val)
continue
}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/octsdb/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestParseValue(t *testing.T) { // Because parsing JSON sucks.
int64(0),
int64(math.MinInt64)},
},
{`[1,{"value":9},5,7,9]`, []interface{}{int64(1), int64(9), int64(5), int64(7), int64(9)}},
}
for i, tcase := range testcases {
actual := parseValue(&pb.Update{
Expand Down

0 comments on commit 1940253

Please sign in to comment.