tuteng opened a new pull request #5930: [Issue 5454][pulsar-client-cpp]Fix cpp 
client schema version
URL: https://github.com/apache/pulsar/pull/5930
 
 
   
   
   Fixes #5454 
   
   
   ### Motivation
   
   The current CPP client cannot correctly obtain the schema version, resulting 
in an error in parsing with java client when sending data with schema using 
python client.
   
   Test code:
   
   ```
   import pulsar
   import json
   
   from pulsar.schema import *
   
   class Test(Record):
       name = String()
       id = Integer()
   
   client = pulsar.Client('pulsar://localhost:6650');
   producer = client.create_producer('test-producer-schema', 
schema=AvroSchema(Test))
   producer.send(Test(name='Hello', id=1))
   client.close()
   ```
   
   Looking at the ParseFromArray 
https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/lib/ClientConnection.cc#L530
 function, we can find that there is a schema_version field before the 
ParseFromArray function, but after calling the ParseFromArray function, the 
schema_version field is missing.
   
   
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite
   The difference between the two functions:
   
   ```
   bool | ParseFromArray(const void * data, int size)Parse a protocol buffer 
contained in an array of bytes.
   -- | --
   bool | ParsePartialFromArray(const void * data, int size)LikeĀ 
ParseFromArray(), but accepts messages that are missing required fields.
   
   ```
   
   
   ### Modifications
   
   * Use ParsePartialFromArray replace of  ParseFromArray.
   
   ### Verifying this change
   
   Add check schema version in unit test SchemaTest
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to