FAQ
Hello there !

I'm trying to communicate my go app using goprotobuf with an existing c#
service that uses protobuf-net as serialization, but since there's no
decimal definition on protocol buffers, protobuf-net uses this
representation structure:


message Decimal {
   optional uint64 lo = 1; // the first 64 bits of the underlying value
   optional uint32 hi = 2; // the last 32 bis of the underlying value
   optional uint32 signScale = 3; // the number of decimal digits (bits
1-16), and the sign (bit 0)
}

Go code:

val := math.Float64bits(3.74)
pd.Lo = proto.Uint64(0x400deb851eb851ec) // Using 3.74 Float64bits hexa
representation
pd.Hi = proto.Uint32(0x00000000)
pd.SignScale = proto.Uint32(0x000000020)


But, the C# server side doesn't get the 3.74 :(

Any help ?

Thanks !

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael Jones at Oct 27, 2014 at 5:46 pm

    On Mon, Oct 27, 2014 at 9:41 AM, Th3x0d3r wrote:

    0x400deb851eb851ec

    What do you get?

    The significand (fraction) is 1.87 and the effective exponent is 2 so that
    could help decode your "C# gets the wrong thing" value if we new what that
    value is...



    --
    *Michael T. Jones | Chief Technology Advocate | mtj@google.com
    <mtj@google.com> | +1 650-335-5765*

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Th3x0d3r at Oct 27, 2014 at 6:32 pm
    The thing is that I'm clueless on how to generate the Lo, Hi and Sign Scale
    for the Decimal Structure. Any example would be great

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Daniel Eloff at Oct 27, 2014 at 6:52 pm
    You're trying to stuff a binary floating point number into a decimal
    floating point type. That's all wrong.

    Decimal in .NET is a decimal floating point number (base 10, not base 2
    like binary floats.) It is of the form sign * mantissa / 10^exponent where
    mantissa is a 96 bit integer, and exponent is 0-28 (effectively all
    negative, so the smallest number is 10^-28.)

    So to represent 3.74, you would store 374 in the mantissa, and use 2 for
    the exponent. If you need more than 19 digits, you can use math.big.Int for
    the mantissa, otherwise uint64 will suffice.

    Cheers,
    Dan
    On Monday, October 27, 2014 11:41:25 AM UTC-5, Th3x0d3r wrote:

    Hello there !

    I'm trying to communicate my go app using goprotobuf with an existing c#
    service that uses protobuf-net as serialization, but since there's no
    decimal definition on protocol buffers, protobuf-net uses this
    representation structure:


    message Decimal {
    optional uint64 lo = 1; // the first 64 bits of the underlying value
    optional uint32 hi = 2; // the last 32 bis of the underlying value
    optional uint32 signScale = 3; // the number of decimal digits (bits
    1-16), and the sign (bit 0)
    }

    Go code:

    val := math.Float64bits(3.74)
    pd.Lo = proto.Uint64(0x400deb851eb851ec) // Using 3.74 Float64bits hexa
    representation
    pd.Hi = proto.Uint32(0x00000000)
    pd.SignScale = proto.Uint32(0x000000020)


    But, the C# server side doesn't get the 3.74 :(

    Any help ?

    Thanks !
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Jones at Oct 27, 2014 at 6:54 pm
    Just realized this myself by looking at:
    https://code.google.com/p/protobuf-net/source/browse/trunk/protobuf-net/ProtoBcl/ProtoDecimal.cs?r=155
    On Mon, Oct 27, 2014 at 11:51 AM, Daniel Eloff wrote:

    You're trying to stuff a binary floating point number into a decimal
    floating point type. That's all wrong.

    Decimal in .NET is a decimal floating point number (base 10, not base 2
    like binary floats.) It is of the form sign * mantissa / 10^exponent
    where mantissa is a 96 bit integer, and exponent is 0-28 (effectively all
    negative, so the smallest number is 10^-28.)

    So to represent 3.74, you would store 374 in the mantissa, and use 2 for
    the exponent. If you need more than 19 digits, you can use math.big.Int
    for the mantissa, otherwise uint64 will suffice.

    Cheers,
    Dan

    On Monday, October 27, 2014 11:41:25 AM UTC-5, Th3x0d3r wrote:

    Hello there !

    I'm trying to communicate my go app using goprotobuf with an existing c#
    service that uses protobuf-net as serialization, but since there's no
    decimal definition on protocol buffers, protobuf-net uses this
    representation structure:


    message Decimal {
    optional uint64 lo = 1; // the first 64 bits of the underlying value
    optional uint32 hi = 2; // the last 32 bis of the underlying value
    optional uint32 signScale = 3; // the number of decimal digits (bits
    1-16), and the sign (bit 0)
    }

    Go code:

    val := math.Float64bits(3.74)
    pd.Lo = proto.Uint64(0x400deb851eb851ec) // Using 3.74 Float64bits hexa
    representation
    pd.Hi = proto.Uint32(0x00000000)
    pd.SignScale = proto.Uint32(0x000000020)


    But, the C# server side doesn't get the 3.74 :(

    Any help ?

    Thanks !

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    *Michael T. Jones | Chief Technology Advocate | mtj@google.com
    <mtj@google.com> | +1 650-335-5765*

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Th3x0d3r at Oct 27, 2014 at 7:06 pm
    Thanks ! , can you show some example ??

    On Monday, October 27, 2014 2:51:18 PM UTC-4, Daniel Eloff wrote:

    You're trying to stuff a binary floating point number into a decimal
    floating point type. That's all wrong.

    Decimal in .NET is a decimal floating point number (base 10, not base 2
    like binary floats.) It is of the form sign * mantissa / 10^exponent
    where mantissa is a 96 bit integer, and exponent is 0-28 (effectively all
    negative, so the smallest number is 10^-28.)

    So to represent 3.74, you would store 374 in the mantissa, and use 2 for
    the exponent. If you need more than 19 digits, you can use math.big.Int
    for the mantissa, otherwise uint64 will suffice.

    Cheers,
    Dan
    On Monday, October 27, 2014 11:41:25 AM UTC-5, Th3x0d3r wrote:

    Hello there !

    I'm trying to communicate my go app using goprotobuf with an existing c#
    service that uses protobuf-net as serialization, but since there's no
    decimal definition on protocol buffers, protobuf-net uses this
    representation structure:


    message Decimal {
    optional uint64 lo = 1; // the first 64 bits of the underlying value
    optional uint32 hi = 2; // the last 32 bis of the underlying value
    optional uint32 signScale = 3; // the number of decimal digits (bits
    1-16), and the sign (bit 0)
    }

    Go code:

    val := math.Float64bits(3.74)
    pd.Lo = proto.Uint64(0x400deb851eb851ec) // Using 3.74 Float64bits hexa
    representation
    pd.Hi = proto.Uint32(0x00000000)
    pd.SignScale = proto.Uint32(0x000000020)


    But, the C# server side doesn't get the 3.74 :(

    Any help ?

    Thanks !
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Jones at Oct 27, 2014 at 7:13 pm
    This is an unknown encoding to me beyond your emails. Perhaps there are
    tests and examples at the website I linked to. You might study those.
    On Mon, Oct 27, 2014 at 12:06 PM, Th3x0d3r wrote:

    Thanks ! , can you show some example ??


    On Monday, October 27, 2014 2:51:18 PM UTC-4, Daniel Eloff wrote:

    You're trying to stuff a binary floating point number into a decimal
    floating point type. That's all wrong.

    Decimal in .NET is a decimal floating point number (base 10, not base 2
    like binary floats.) It is of the form sign * mantissa / 10^exponent
    where mantissa is a 96 bit integer, and exponent is 0-28 (effectively all
    negative, so the smallest number is 10^-28.)

    So to represent 3.74, you would store 374 in the mantissa, and use 2 for
    the exponent. If you need more than 19 digits, you can use math.big.Int
    for the mantissa, otherwise uint64 will suffice.

    Cheers,
    Dan
    On Monday, October 27, 2014 11:41:25 AM UTC-5, Th3x0d3r wrote:

    Hello there !

    I'm trying to communicate my go app using goprotobuf with an existing c#
    service that uses protobuf-net as serialization, but since there's no
    decimal definition on protocol buffers, protobuf-net uses this
    representation structure:


    message Decimal {
    optional uint64 lo = 1; // the first 64 bits of the underlying value
    optional uint32 hi = 2; // the last 32 bis of the underlying value
    optional uint32 signScale = 3; // the number of decimal digits (bits
    1-16), and the sign (bit 0)
    }

    Go code:

    val := math.Float64bits(3.74)
    pd.Lo = proto.Uint64(0x400deb851eb851ec) // Using 3.74 Float64bits hexa
    representation
    pd.Hi = proto.Uint32(0x00000000)
    pd.SignScale = proto.Uint32(0x000000020)


    But, the C# server side doesn't get the 3.74 :(

    Any help ?

    Thanks !

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    *Michael T. Jones | Chief Technology Advocate | mtj@google.com
    <mtj@google.com> | +1 650-335-5765*

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Th3x0d3r at Oct 27, 2014 at 7:53 pm
    Thanks ! but math it's not my field, and frankly I'm quite lost, can you
    show me some how to do that ?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Jones at Oct 27, 2014 at 7:58 pm
    Daniel explained it. Try this:

    pd.Lo = 374
    pd.Hi = 0
    pd.SignScale = 4

    that (should/may/might) mean (0*(2**64)+374)/(10**2) == 374/100 == 3.74

    If that works for you, come back for more. ;-)
    On Mon, Oct 27, 2014 at 12:52 PM, Th3x0d3r wrote:

    Thanks ! but math it's not my field, and frankly I'm quite lost, can you
    show me some how to do that ?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    *Michael T. Jones | Chief Technology Advocate | mtj@google.com
    <mtj@google.com> | +1 650-335-5765*

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 27, '14 at 4:41p
activeOct 27, '14 at 7:58p
posts9
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase