docs icon indicating copy to clipboard operation
docs copied to clipboard

What about `short`/`Int16`?

Open StingyJack opened this issue 4 years ago • 7 comments

So many other int types here but not an int16


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

StingyJack avatar May 01 '21 19:05 StingyJack

Hi @StingyJack, thank you for reaching out.

gRPC/Protobuf doesn't support 16-bits integer. For the list of supported scalar value types, please refer Scalar Value Types - Protobuf Language Guide (proto3) or Supported Scalar Value Types

sughosneo avatar May 03 '21 10:05 sughosneo

To add to reply above, protobuf uses a variable length encoding for integers. Assuming your goal was to optimize the wire transmission, forcing a smaller width integer isn't needed.

shirhatti avatar May 03 '21 18:05 shirhatti

This document describes the difference in type systems and offers suggestions for other primitive types but it does not cover short/int16.

Data lost from a narrowing conversion is the concern. I don't always have control over the existing model types. Best I can come up with is when the model property is a short and the incoming value is > short.MaxValue to throw an exception. Curious to hear about alternative approaches.

StingyJack avatar May 03 '21 18:05 StingyJack

Data lost from a narrowing conversion is the concern. I don't always have control over the existing model types. Best I can come up with is when the model property is a short and the incoming value is > short.MaxValue to throw an exception. Curious to hear about alternative approaches.

I was about to suggest something along those lines. @JamesNK anything to add?

shirhatti avatar May 03 '21 18:05 shirhatti

Considering the original issue is answered and it's open for a very long, this can be closed now.

erjain avatar Sep 16 '22 13:09 erjain

@erjain - This was opened to get the documentation updated to include the appropriate advice. Its not a support issue that can be resolved when a solution can be given.

StingyJack avatar Sep 17 '22 20:09 StingyJack

Sure @StingyJack. Hi @JamesNK, any suggestions?

erjain avatar Sep 19 '22 08:09 erjain

Closing this issue, as it relates to an eBook that has since been archived. For more information, see:

  • Issue: #38774
  • Pull request: #38775

IEvangelist avatar Jan 17 '24 17:01 IEvangelist