[ 
https://issues.apache.org/jira/browse/TINKERPOP-3277?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18098539#comment-18098539
 ] 

ASF GitHub Bot commented on TINKERPOP-3277:
-------------------------------------------

Cole-Greer commented on PR #3540:
URL: https://github.com/apache/tinkerpop/pull/3540#issuecomment-5061221703

   VOTE +1




> gremlin-go can't serialize zero in bigdecimal/biginteger
> --------------------------------------------------------
>
>                 Key: TINKERPOP-3277
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3277
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: go
>    Affects Versions: 3.7.6, 3.8.1
>            Reporter: Ken Hu
>            Priority: Minor
>
> Caveat: I haven't fully verified this, just something AI told me when I was 
> writing the "model" tests for gremlin-go. Just putting here so it can be 
> checked later.
> Gremlin-Go serializes zero BigInteger as a GraphBinary length of 0 with no 
> bytes. Java expects a valid two’s-complement BigInteger byte array, where 
> zero is encoded as length 1 with byte 0x00. When Java reads Go’s zero-length 
> form, new BigInteger(new byte[0]) throws NumberFormatException, so Java 
> servers cannot read zero BigInteger values sent by Go.
> The same affects BigDecimal when its unscaled value is zero, because that 
> unscaled value is serialized as a BigInteger.
> {code:java}
> func TestZeroBigIntegerGraphBinaryV1Bytes(t *testing.T) {
>       var buffer bytes.Buffer
>       got, err := bigIntWriter(*big.NewInt(0), &buffer, nil)
>       if err != nil {
>               t.Fatal(err)
>       }
>       want := []byte{0x00, 0x00, 0x00, 0x01, 0x00}
>       if !bytes.Equal(got, want) {
>               t.Fatalf("zero BigInteger bytes = % x, want % x", got, want)
>       }
>   }
>   Current output:
>   00 00 00 00
>   Expected output:
>   00 00 00 01 00
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to