Skip to content

SideChannel helpers #3596

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 11 commits into from
Mar 11, 2020
Merged

SideChannel helpers #3596

merged 11 commits into from
Mar 11, 2020

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Mar 9, 2020

Proposed change(s)

Utilities for incoming and outgoing sidechannel messages. Still requires the user to make sure fields are written in a consistent order, but means that they never have to deal with bytes or struct pack/unpack directly.

This is still a work in progress; if you think this will be useful, I can add more methods and add some actual docstrings/update the docs. Can also add similar abstractions on the C# side if they'd be helpful.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

Copy link
Contributor

@vincentpierre vincentpierre left a comment

Choose a reason for hiding this comment

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

I think an OutgoingMessage and IncomingMessage makes more sense than a byte[].

Copy link
Contributor

@awjuliani awjuliani left a comment

Choose a reason for hiding this comment

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

Ditto what Vince said. I think this abstraction makes a lot of sense.

return str;
}

public IList<float> ReadFloatArray()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not a float[]?
Not sure we need this method to be honest.

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 added it on the python side in response to @awjuliani's comment on the doc.

float[] implements the IList<float> interface; I figured it was better to be a bit more generic in case we ever wanted to change the underlying implementation.

public void SetRawBytes(byte[] data)
{
m_Stream.Seek(0, SeekOrigin.Begin);
m_Stream.Write(data, 0, data.Length);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the stream was created with an array that was larger than the one passed it, won't the stream be corrupted after this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I think m_Stream.SetLength(0) should fix this (and setting capacity as an optimization too).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a unit test and confirmed fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't you always want the capacity to be data.Length?

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 didn't want to shrink capacity if we didn't need to.

@chriselion chriselion marked this pull request as ready for review March 9, 2020 23:40
}
}

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

Put in a separate file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense, wasn't sure where to draw the line.

}
}

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

Put in separate file

@chriselion chriselion merged commit 12cd892 into master Mar 11, 2020
@delete-merged-branch delete-merged-branch bot deleted the develop-sidechannel-usability branch March 11, 2020 03:39
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants