-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #issue 42. add num for each key and sort keys by num. make sure keys in map can be sorted. #50
Open
pettershao-ragilenetworks
wants to merge
2
commits into
sonic-net:master
Choose a base branch
from
pettershao-ragilenetworks:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fixes #issue 42. add num for each key and sort keys by num. make sure keys in map can be sorted. #50
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- ./github.com/jipanyang/gnxi/utils/xpath/xpath.go 2022-10-25 16:16:00.239783329 +0800 | ||
+++ ./github.com/jipanyang/gnxi/utils/xpath/xpath.go 2022-10-25 15:56:18.336168598 +0800 | ||
@@ -20,6 +20,7 @@ | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
+ "strconv" | ||
) | ||
|
||
var ( | ||
@@ -135,9 +136,10 @@ | ||
// For example, given | ||
// "[k1=v1][k2=v2]", | ||
// this API returns | ||
-// map[string]string{"k1": "v1", "k2": "v2"}. | ||
+// map[string]string{"[0]k1": "v1", "[1]k2": "v2"}. | ||
func parseKeyValueString(str string) (map[string]string, error) { | ||
keyValuePairs := make(map[string]string) | ||
+ var num int = 0 | ||
// begin marks the beginning of a key-value pair. | ||
begin := 0 | ||
// end marks the end of a key-value pair. | ||
@@ -170,7 +172,10 @@ | ||
// Recover escaped '[' and ']'. | ||
val = strings.Replace(val, `\]`, `]`, -1) | ||
val = strings.Replace(val, `\[`, `[`, -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find! |
||
- keyValuePairs[key] = val | ||
+// keyValuePairs[key] = val | ||
+ key_with_num := "[" + strconv.Itoa(num) + "]" + key | ||
+ keyValuePairs[key_with_num] = val | ||
+ num++ | ||
begin = end + 1 | ||
} | ||
end++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ import ( | |
"context" | ||
"log/syslog" | ||
"github.com/Azure/sonic-mgmt-common/translib/tlerr" | ||
|
||
"strconv" | ||
"sort" | ||
) | ||
|
||
var ( | ||
|
@@ -80,6 +81,9 @@ func ConvertToURI(prefix *gnmipb.Path, path *gnmipb.Path, req *string) error { | |
elems := fullPath.GetElem() | ||
*req = "/" | ||
|
||
num_key_map := make(map[int]string) | ||
key_val_map := make(map[string]string) | ||
|
||
if elems != nil { | ||
/* Iterate through elements. */ | ||
for i, elem := range elems { | ||
|
@@ -94,8 +98,33 @@ func ConvertToURI(prefix *gnmipb.Path, path *gnmipb.Path, req *string) error { | |
/* If keys are present , process the keys. */ | ||
if key != nil { | ||
for k, v := range key { | ||
log.V(6).Infof("elem : %#v %#v", k, v) | ||
*req += "[" + k + "=" + v + "]" | ||
if strings.Contains(k, "[") && strings.Contains(k, "]") { | ||
num_str := k[strings.Index(k, "[") + 1 : strings.Index(k, "]")] | ||
key_del_num := k[strings.Index(k, "]") + 1 : len(k)] | ||
num, err := strconv.Atoi(num_str) | ||
if err != nil { | ||
return err | ||
} | ||
num_key_map[num] = key_del_num | ||
key_val_map[key_del_num] = v | ||
} else { | ||
log.V(6).Infof("elem : %#v %#v", k, v) | ||
*req += "[" + k + "=" + v + "]" | ||
} | ||
} | ||
|
||
if len(num_key_map) != 0 { | ||
log.V(6).Infof("num_key_map : %#v", num_key_map) | ||
log.V(6).Infof("key_val_map : %#v", key_val_map) | ||
|
||
var num_list []int | ||
for num_key_map_k := range num_key_map { | ||
num_list = append(num_list, num_key_map_k) | ||
} | ||
sort.Ints(num_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be already sorted? |
||
for _, num_list_v := range num_list { | ||
*req += "[" + num_key_map[num_list_v] + "=" + key_val_map[num_key_map[num_list_v]] + "]" | ||
} | ||
} | ||
|
||
/* Append "/" after all keys are processed. */ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about compatibility?
If we add num for each key, other GNMI client can't communicate with SONiC telemetry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope of this numbering within parameters of a path element.
@pettershao-ragilenetworks -- please correct my statement if needed.