Skip to content

Adding SpanByte to System #109

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

Merged
merged 15 commits into from
Sep 30, 2020
Merged

Adding SpanByte to System #109

merged 15 commits into from
Sep 30, 2020

Conversation

Ellerbach
Copy link
Member

@Ellerbach Ellerbach commented Sep 30, 2020

Description

Adding SpanByte to System which is a simplified version of Span for byte. This will be used to replace byte[] in I2C, SPI and other low level operation manipulating byte buffers.

Motivation and Context

Today low level operation to transmit data to an I2C or SPI device is using raw byte buffer. This sometimes involve allocating and copying buffers. This concept of Span originally introduced with .NET Core is in short, a T[], int start and int end class. As nano Framework doesn't support generics, this is a simple implementation of Span named SpanByte.
This will be widely available and will allow to migrate native byte[] transfers to SpanByte.

How Has This Been Tested?

This has been tested with various sensors ported to nanoFramework from .NET IoT

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@nfbot
Copy link
Member

nfbot commented Sep 30, 2020

Hi @Ellerbach,

I'm nanoFramework bot.
Thank you for your contribution!

A human will be reviewing it shortly. 😉

@josesimoes
Copy link
Member

@Ellerbach on your attempt to set the language version.

According to the documentation as we are "kind of inline" with .NET Framework we should be supporting 7.3.

I've added that to the nfproj file and the build went fine: <LangVersion>7.3</LangVersion>
Except for the nullable reference type which is supposed to be available only with 8.0.

So feel free to add that one above.

@josesimoes
Copy link
Member

josesimoes commented Sep 30, 2020

@Ellerbach @krwq on a more high level look at this I was reading the documentation for the Span class and the remarks here got me thinking...

I'm starting a conversation about this on Discord.

@Ellerbach
Copy link
Member Author

Span class and the remarks here got me thinking...

The stackalloc part is removed, the pointer part as well, we are in a fully managed environment. In short, to "migrate" code from .NET Core to nanoFramework, a global replace of Span to SpanByte and from stackalloc to new will make the trick

@josesimoes
Copy link
Member

a global replace of Span to SpanByte and from stackalloc to new will make the trick

No doubts about that! My comments were more towards the overall implementation of this (. NET IoT included) and to point out these nuances that exist on smaller MCUs.

@josesimoes
Copy link
Member

@Ellerbach FYI I've just added <LangVersion>7.3</LangVersion> to the project system targets. So this will be the default from now on. It's OK to add it to mscorlib nfproj for now until that's made available on a coming VS extension release.

@Ellerbach
Copy link
Member Author

It's OK to add it to mscorlib nfproj for now until that's made available on a coming VS extension release

All works for me :-)

@josesimoes
Copy link
Member

Build is now OK with the update targets.

/// </exception>
public void CopyTo(SpanByte destination)
{
if (destination.Length < _length - _start)
Copy link

Choose a reason for hiding this comment

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

I think this should be just < _length

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

Successfully merging this pull request may close these issues.

4 participants