Giter VIP home page Giter VIP logo

Comments (3)

barbeau avatar barbeau commented on June 28, 2024

@nzphoenix Good question! So there are several questions here, and I'll try to answer them to the best of my knowledge.

When looking at the gtfs-realtime.proto file, field names use underscores like active_period in Alert or current_stop_sequence in VehiclePosition.

Yes - this is the canonical way to represent field names in Protocol Buffer .proto files, with message names in CamelCase. See https://developers.google.com/protocol-buffers/docs/style#message_and_field_names.

However, to use the nodejs bindings (I haven't checked the others), it requires all attributes to be in camelCase and this applies for both input and output, so you get activePeriod and currentStopSequence.

This differs depending on the programming language and protocol buffer compiler used to generate the bindings. If you look at the above link, using the official Google compiler C++ uses snake_case and Java uses camelCase.

It also means the example code here for nodejs doesn't work and should actually be entity.tripUpdate?

I haven't used the NodeJS bindings myself, but I just added another commit (9354c50) to test this, and it looks like you're right - this test passes for me in IntelliJ:

assert.equal(vehicle.trip.tripId, "t0")

So the notation to access the trip ID variable is camelCase for NodeJS, and we should fix the example - please let me know if you can confirm that the above test (or a similar one also testing camelCase access) works for you.

We use fromObject to convert a JSON GTFS-RT representation into Protobuf, and this was developed using underscores in field names. We can pass the data through a converter to change to camelCase, but wondering if I am missing something here? Shouldn't documentation (linked above) either refer to fields in camelCase or the bindings use underscores for both input/output?

The primary use case for Protocol Buffers is writing to binary and then parsing from binary, in which case you don't have an intermediate text format at all - this is how I'm used to using Protocol Buffers. The only case where I've used the text functions is to transform the binary into something human readable to see the contents - but in this case the naming convention doesn't matter because I'm not using it as something machine readable. Unlike the binary format, I'm not sure if the generated text format is standardized across different protocol buffer compilers and languages. I'd welcome feedback from anyone else that has more information about this.

from gtfs-realtime-bindings.

jameslinjl avatar jameslinjl commented on June 28, 2024

According to Google's documentation, Proto3 supports a canonical encoding in JSON, which can be used for serializing protobuf data into a JSON as a text-based format that can also be handled by all other languages that support Proto3. However, the GTFS-RT spec uses Proto2 syntax rather than Proto3, which means that (as far as I'm aware... and as far as I can find in the official documentation) you can't reliably depend on transferring this Proto2 data by use of JSON serialization helper methods.

from gtfs-realtime-bindings.

isabelle-dr avatar isabelle-dr commented on June 28, 2024

Closing this issue, the question has been answered. Thanks @jameslinjl and @barbeau !

from gtfs-realtime-bindings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.