Skip to content

Implement visitFloat32, visitFloat64String for Byte/Short/Int/Long/Float/Double/Char - #358

Merged
htmldoug merged 3 commits into
com-lihaoyi:masterfrom
htmldoug:float32
Jul 14, 2021
Merged

htmldoug merged 3 commits into
com-lihaoyi:masterfrom
htmldoug:float32

Conversation

@htmldoug

Copy link
Copy Markdown
Collaborator

Fixes #354.

@htmldoug
htmldoug requested a review from lihaoyi July 14, 2021 00:22
@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

@htmldoug looks good, feel free to merge

@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

@htmldoug could we add a unit test too? just to make sure this is fixing what we it should be fixing

@htmldoug

Copy link
Copy Markdown
Collaborator Author

Sure. Tests found visitFloat64String missing, too. JsVisitor isn't on the classpath here, so I just copy-pasted. If that's okay with you, it's merge-ready.

@htmldoug htmldoug changed the title Implement visitFloat32 for Byte/Short/Int/Long/Float/Double Implement visitFloat32 for Byte/Short/Int/Long/Float/Double/Char/BigDecimal Jul 14, 2021
@htmldoug htmldoug changed the title Implement visitFloat32 for Byte/Short/Int/Long/Float/Double/Char/BigDecimal Implement visitFloat32 for Byte/Short/Int/Long/Float/Double/Char Jul 14, 2021
@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

looks good to me

@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

Not sure if the copypaste code can easily be moved into some private helper function, but if it can that would help DRY things up a bit

@htmldoug

Copy link
Copy Markdown
Collaborator Author

Refactored out a NumericReader. protected is the right visibility, I guess?

@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

Seems good enough. This repo isn't particularly strict about visibility anyway. Feel free to merge

@lihaoyi

lihaoyi commented Jul 14, 2021 •

Copy link
Copy Markdown
Member

TBH I'd have put the logic into a static helper function somewhere that the various readers call from their override of visitFloat64String, rather than a trait that the various readers extend. That seems like it would be a lot simpler, reduce the depth of the inheritance hierarchies, and make the logic easier to reuse if someone else wants to call it in odd places.

We do a lot of fancy trait cake stuff in the repo but I like static functions where we can get away with then

@htmldoug

Copy link
Copy Markdown
Collaborator Author

I agree in principle, although it's a little tricky since they need to delegate to other instance methods.

Would either of these approaches be better?

def helper(s: String): (String, Int, Int) = ???

// each Reader:
def visitFloat64String(s: String, index: Int): T = {
  val (s, decIndex, expIndex) = helper(s)
  visitFloat64StringParts(s, decIndex, expIndex, index)
}
def helper[T](s: String, visitFloat64StringParts: (String, Int, Int) => T): T = ???

// each Reader:
def visitFloat64String(s: String, index: Int) = helper(s, visitFloat64StringParts(_, _, _, index))

@htmldoug htmldoug changed the title Implement visitFloat32 for Byte/Short/Int/Long/Float/Double/Char Implement visitFloat32, visitFloat64String for Byte/Short/Int/Long/Float/Double/Char Jul 14, 2021
@htmldoug htmldoug changed the title Implement visitFloat32, visitFloat64String for Byte/Short/Int/Long/Float/Double/Char Implement visitFloat32, visitFloat64String for Byte/Short/Int/Long/Float/Double/Char Jul 14, 2021
@lihaoyi

lihaoyi commented Jul 14, 2021

Copy link
Copy Markdown
Member

Oh if a static helper is tricky lets just go with the trait then

@htmldoug
htmldoug merged commit e7e0a2a into com-lihaoyi:master Jul 14, 2021
@htmldoug
htmldoug deleted the float32 branch September 13, 2021 22:03
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.

MessagePack Float32 reading error

2 participants