Protobuf.js: Migrating from 5.0.1 To 6.3.0

Created on 27 Dec 2016  路  5Comments  路  Source: protobufjs/protobuf.js

I want to migrate from 5.0.1 To 6.3.0 , but I have an issue , There is no getter and setter in decoded object . why?

TypeError: protobuf.getName is not a function
TypeError: protobuf.getPassword is not a function

Decoded object contain both name and password

How can I have getter and setter?

question

Most helpful comment

@mj-mehdizadeh We have a similar problem. But we decided as a team to rip off the bandage and convert all call sites. A simple regex will match all \.[gs]et[A-Z].*\( and then we go through it one by one and convert. there are of course false positives but we end up checking all those call sites anyways.

All 5 comments

There are no such getter and setter functions with v6. Just set the properties instead.

If you are worried about invalid field values, there is Message.verify(myMessage) (returns null if field values are valid, otherwise a string reason why they are not) to verify them all at once.

The problem is m I my project I use getter and setter 1000+ times , How can I migrate to version 6.3.0??

You could implement custom classes that have the respective get and set functions (you could actually completely mimic v5 with this). If your protobuf definitions are rather huge, this process wouldn't be really convenient though. In this case, you could still populate your custom classes based on reflection information.

If nothing of this is an option, you should probably just stick to v5.

@mj-mehdizadeh We have a similar problem. But we decided as a team to rip off the bandage and convert all call sites. A simple regex will match all \.[gs]et[A-Z].*\( and then we go through it one by one and convert. there are of course false positives but we end up checking all those call sites anyways.

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jarvanxing picture jarvanxing  路  4Comments

spiderkeys picture spiderkeys  路  5Comments

zD98 picture zD98  路  3Comments

VitalyName picture VitalyName  路  3Comments

b1naryMan picture b1naryMan  路  4Comments