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

Basic reflect types for package consumers to use #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

asciifaceman
Copy link

This feature derived from conversation in go-audio/wav#20

I am using reflective types but performing no reflection, there should be no performance difference or compatibility issues, outside of projects conforming to the interface.

The intention for these changes would be for the Write() encoder function to be able to ask the type so it can utilize AsIntBuffer only when required - allowing Write() to accept the buf Interface instead of type so it can accept any type but then silently convert to int before passing it on.

This is meant to be an early step to support any type in write without actually writing any type.

@codecov-io
Copy link

codecov-io commented May 4, 2019

Codecov Report

Merging #19 into master will increase coverage by 10.2%.
The diff coverage is 45.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
+ Coverage   29.94%   40.14%   +10.2%     
==========================================
  Files           4        4              
  Lines         521      543      +22     
==========================================
+ Hits          156      218      +62     
+ Misses        346      300      -46     
- Partials       19       25       +6
Impacted Files Coverage Δ
float_buffer.go 81.25% <100%> (+0.98%) ⬆️
int_buffer.go 40% <100%> (+2.26%) ⬆️
pcm_buffer.go 18.85% <25%> (+18.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b2a6ca...eb30983. Read the comment docs.

@mattetti
Copy link
Member

mattetti commented May 4, 2019

I think that's a good approach but it also comes with a lot of challenges. The main one being that any function receiving a buffer might have to do the check and convert the date, so yo might switch back and forth many times within the processing of a file. The other issue is the allocation of lots of temporary buffers (but we can work around that issue by seeing a scratch buffer). I took a similar approach in my initial version: https://github.com/mattetti/audio/blob/master/pcm_buffer.go

The one thing I am not a fan of is to bring an entire package just to get a type lookup table. I think we'd be better off using an enum of constants here.

@asciifaceman
Copy link
Author

asciifaceman commented May 4, 2019 via email

@chfanghr
Copy link

chfanghr commented May 5, 2019

DeepEqual on two slices is an O (n) operation so it may bring a strong impact to the performance.

@asciifaceman
Copy link
Author

asciifaceman commented May 5, 2019 via email

@chfanghr
Copy link

chfanghr commented May 5, 2019

Oh sorry I didn't see that it's a test.

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