Skip to content
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

Update Reader Value APIs to symbol token abstraction #158

Merged
merged 34 commits into from
Sep 16, 2020
Merged

Update Reader Value APIs to symbol token abstraction #158

merged 34 commits into from
Sep 16, 2020

Conversation

byronlin13
Copy link
Contributor

Issue #, if available:
#151

Description of changes:
-Update Reader API to return SymbolToken abstraction instead of string representation of Symbols.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@byronlin13 byronlin13 marked this pull request as ready for review September 14, 2020 06:56
Byron Lin added 2 commits September 14, 2020 01:12
…b.com:byronlin-bq/ion-go into Update_value_apis_to_symbol_token_abstraction
@byronlin13 byronlin13 changed the title Update value apis to symbol token abstraction WIP Update Reader Value APIs to symbol token abstraction Sep 14, 2020
name, e := in.FieldName()
if e != nil {
return p.error(read, err)
}
if name != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if name != nil && name.Text != nil { ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -38,11 +38,11 @@ func TestWriteBinaryStruct(t *testing.T) {
w.BeginStruct()
w.EndStruct()

w.Annotation("foo")
w.Annotation(SymbolToken{Text: newString("foo"), LocalSID: SymbolIDUnknown})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

func getSymbolToken(text string, sid ...int) {
  if len(sid) > 0 {
    return SymbolToken{Text: &text, LocalSID: sid)
  }
  return SymbolToken{Text: &text, LocalSID: SymbolIDUnknown)
}
....
w.Annotation(getSymbolToken("foo"))

And then use the same in other exampls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rather not do this in the test because I want the symboltoken to explicitly state the text SID so it is clear to the person reading this test

@@ -211,7 +246,7 @@ func containersEquality(this, other interface{}) bool {
default:
otherItem := other.(ionItem)
thisItem := this.(ionItem)
if thisItem.fieldName == otherItem.fieldName && thisItem.equal(otherItem) {
if thisItem.fieldName.Equal(&otherItem.fieldName) && thisItem.equal(otherItem) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&otherItem.fieldName wouldn't it be better to compare the values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently equal() function takes in a non-pointer
func (i *ionItem) equal(o ionItem) bool {

If I were to do your suggestion it would be:

	default:
		otherItem := other.(*ionItem)
		thisItem := this.(*ionItem)
		if thisItem.fieldName.Equal(&otherItem.fieldName) && thisItem.equal(*otherItem) {
			return true
		}

but it is failing right now because the value APIs arent a pointer yet

ion/integration_test.go Outdated Show resolved Hide resolved
ion/reader.go Outdated Show resolved Hide resolved
ion/readlocalsymboltable.go Show resolved Hide resolved
w.Annotation("foo")
w.Annotation("$bar")
w.Annotation(".baz")
w.Annotation(SymbolToken{Text: newString("foo"), LocalSID: SymbolIDUnknown})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, but if you think it makes it more readable you can use helper method for these like the suggestion on binarywriter_test

ion/unmarshal.go Outdated Show resolved Hide resolved
ion/unmarshal.go Outdated Show resolved Hide resolved
ion/unmarshal.go Outdated Show resolved Hide resolved
ion/unmarshal.go Outdated Show resolved Hide resolved
ion/reader.go Outdated Show resolved Hide resolved
ion/reader.go Outdated Show resolved Hide resolved
ion/reader.go Outdated Show resolved Hide resolved
ion/symboltable.go Outdated Show resolved Hide resolved
ion/tokenizer.go Outdated Show resolved Hide resolved
ion/unmarshal.go Show resolved Hide resolved
Comment on lines 377 to 379
for _, a := range an {
if a == "embedded_documents" {
if a.Text != nil && *a.Text == "embedded_documents" {
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, doesn't this need to be the first annotation? (Rather than anywhere in the annotations list?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ion test data files have 'embedded_documents' annotation by itself, it makes sense that it should be the first annotation, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants