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

Accessing raw data in ISnmpData #88

Open
nickaein opened this issue Sep 4, 2018 · 4 comments
Open

Accessing raw data in ISnmpData #88

nickaein opened this issue Sep 4, 2018 · 4 comments
Labels

Comments

@nickaein
Copy link

nickaein commented Sep 4, 2018

The extension ToBytes provided in SnmpDataExtension does this, but it apparently includes the data-type bytes too. For instance, for an IPAddress datatype it returns 6 bytes instead of 4.

It would be nice if ISnmpData interface expose a function like GetRaw to let the user access the underyling raw bytes without type.

@nickaein
Copy link
Author

nickaein commented Sep 4, 2018

For instance for value of 255.255.0.0 I get:

{ 0x40, 0x04, 0xFF, 0xFF, 0x00, 0x00 }

Apparently 0x40 is type for IpAddress and 0x04 specifies value length. As a workaround one could ignore the first two bytes.

@lextm
Copy link
Collaborator

lextm commented Sep 4, 2018

It is not a standard API yet, but some ISnmpData derived types have a GetRaw method, which exposes the raw bytes.

Your workaround might not work in all cases, as the length bytes can be more than one.

@lextm lextm added the question label Sep 4, 2018
@nickaein
Copy link
Author

nickaein commented Sep 4, 2018

Thanks for extremely fast response!

It is not a standard API yet

Does that you mean keeping the current API as is to avoid any unexpected breaking change?

If someone add GetRaw to ISnmpData interface and implement it for derived types in sharpsnmplib would that be OK? Or there is more obstacles than that?

Does sharpsnmplib follows a particular API? I suspected this because the ToBytes method is implemented as extension method in SnmpDataExtension instead of directly implementing it inside ISnmpData.

some ISnmpData derived types have a GetRaw method, which exposes the raw bytes.

Thats' correct, but still for each case one has to cast to ISnmpData to corresponding derived type based on TypeCode.

Another solution could be adding GetRaw() as an extension method.

Your workaround might not work in all cases

I was afraid of that.

@lextm
Copy link
Collaborator

lextm commented Sep 4, 2018

There is no plan to fix the API for current 9.x/10.x releases.

I am investigating Microsoft's latest API additions (Span and System.IO.Pipelines), so the next major release 11.x should contain significant API surface changes, where GetRaw is very likely to be exposed as part of ISnmpData.

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

No branches or pull requests

2 participants