protobuf-php / protobuf

PHP implementation of Google's Protocol Buffers
MIT License
236 stars 29 forks source link

Null character when serializeToJsonString is called on message #23

Closed zajca closed 2 years ago

zajca commented 2 years ago

I found weird behavior, when I serialize message to json at the end there is null character \u0000. I can't figure out why this is happening, in the end I'm sending this to temporal and deserializing on worker where it fails with Cannot decode json string

I have reproduce this here: https://github.com/keboola/php-storage-driver-teradata/blob/746eb8f0b7ea7d1facc4041cf5d671999a5a581c/test.php this is only object where encountered this https://github.com/keboola/php-storage-driver-teradata/blob/zajca-kbc-2874/proto/table.proto#L199

git clone https://github.com/keboola/php-storage-driver-teradata.git
git checkout -b zajca-kbc-2874
composer install
php test.php

This is output when I run this script (note the end):

'{"credentials":{"@type":"type.googleapis.com/keboola.storageDriver.credentials.GenericBackendCredentials","host":"xxx","principal":"xxx","secret":"xxx","meta":{"@type":"type.googleapis.com/keboola.storageDriver.credentials.GenericBackendCredentials.TeradataCredentialsMeta","database":"xxx"}},"command":{"@type":"type.googleapis.com/keboola.storageDriver.command.table.TableImportFromFileCommand","formatTypeOptions":{"@type":"type.googleapis.com/keboola.storageDriver.command.table.TableImportFromFileCommand.CsvTypeOptions","columnsNames":["id","name","city","sex"],"delimiter":",","enclosure":"\\"","compression":"GZIP"},"filePath":{"root":"xxx","path":"xxx","fileName":"xxx"},"fileCredentials":{"@type":"type.googleapis.com/keboola.storageDriver.command.table.ImportExportShared.S3Credentials","key":"xxx","secret":"xxx","region":"eu-central-1"},"destination":{"path":["xxx"],"tableName":"xxx"},"importOptions":{"timestampColumn":"_timestamp","numberOfIgnoredLines":1,"dedupType":"INSERT_DUPLICATES"},"meta":{"@type":"type.googleapis.com/keboola.storageDriver.command.table.TableImportFromFileCommand.TeradataTableImportMeta"}}}' . "\0" . ''

This is what I see in debuger in my app: image

FabioBatSilva commented 2 years ago

Looks like you are using google/protobuf not protobuf-php/protobuf

zajca commented 2 years ago

Ah sorry, I missed correct repo.