Skip to content

Commit

Permalink
gtfs-rt-bindings@4 ✅
Browse files Browse the repository at this point in the history
gtfs-rt-bindings@4 uses [Protobuf.js](https://github.com/protobufjs/protobuf.js), whereas gtfs-rt-bindings@3 uses [protocol-buffers](https://github.com/mafintosh/protocol-buffers) & [protocol-buffers-encodings](https://github.com/mafintosh/protocol-buffers-encodings). It seems that they encode the same data differently.

see also derhuerst/gtfs-rt-bindings@71ac301
  • Loading branch information
derhuerst committed Oct 7, 2021
1 parent 9a3489b commit fde2f7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
11 changes: 7 additions & 4 deletions lib/entities-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const schema = require('gtfs-rt-bindings/schema.json')
const schema = require('gtfs-rt-bindings/gtfs-realtime.schema.json')
const {varint} = require('protocol-buffers-encodings')
const {FeedEntity, FeedHeader, FeedMessage} = require('gtfs-rt-bindings')

Expand Down Expand Up @@ -46,7 +46,8 @@ const createEntitiesStore = (ttl, timestamp) => {
// todo: use sth more memory-efficient than closures?
timers.set(id, setTimeout(del, ttl, id))

const data = FeedEntity.encode(entity)
FeedEntity.verify(entity)
const data = FeedEntity.encode(entity).finish()
datas.set(id, data)

const field = encodeField(
Expand All @@ -73,11 +74,13 @@ const createEntitiesStore = (ttl, timestamp) => {
const ids = Array.from(timers.keys())
const chunks = new Array(2 + ids.length * 2)

const header = chunks[1] = FeedHeader.encode({
const rawHeader = {
gtfs_realtime_version: '2.0',
incrementality: FeedHeader.Incrementality.FULL_DATASET,
timestamp: timestamp(),
})
}
FeedHeader.verify(rawHeader)
const header = chunks[1] = FeedHeader.encode(rawHeader).finish()
const headerField = chunks[0] = encodeField(
FEED_MSG_HEADER,
LENGTH_DELIMITED,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node": ">=14"
},
"dependencies": {
"gtfs-rt-bindings": "^3.1.0",
"gtfs-rt-bindings": "^4.0.0",
"protocol-buffers-encodings": "^1.1.0"
},
"devDependencies": {
Expand Down
31 changes: 16 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const header = {

const feedMsgEqual = (store, entities) => {
const actual = store.asFeedMessage()
const expected = FeedMessage.encode({header, entity: entities})
const expected = FeedMessage.encode({header, entity: entities}).finish()
bufEqual(actual, expected)
}

Expand Down Expand Up @@ -104,20 +104,21 @@ pump(
bufEqual(full.asFeedMessage(), Buffer.from(
`\
0a090a03322e301000180112520a0132224d0a1b0a15317c36343436367c317c38367\
c31323033323032302a026e36421212105520416c742d4d617269656e646f7266120a\
0d66665042159a9951413a0c39303030303030313231303620011289020a01331a830\
20a1b0a15317c32353434357c327c38367c31323033323032302a026e331a1a0a0534\
303831331211552057697474656e62657267706c61747a121c220c393030303030303\
53033303112001a08080010b8b1abf3052800122c220c393030303030303233333534\
120c08c4ffffff0f10c0bfabf3051a0c08c4ffffff0f10c0bfabf3052800122c220c3\
93030303030303233323033120c08c4ffffff0f10fcbfabf3051a0c08c4ffffff0f10\
fcbfabf3052800122c220c393030303030303233323034120c08c4ffffff0f10f4c0a\
bf3051a0c08c4ffffff0f10f4c0abf30528001220220c393030303030303536313031\
120c08c4ffffff0f10b0c1abf3051a002800124f0a0134224a0a1c0a15317c3634353\
1327c317c38367c31323033323032302a036e3138420e120c55204d6f6872656e7374\
722e120a0d6666524215666656413a0c3930303030303030353230352002122c0a013\
522270a070a0274312a014142100a066275732d31321206427573203132120a0da470\
9d3f158fc21540`,
c31323033323032302a026e36120a0d66665042159a99514120013a0c393030303030\
303132313036421212105520416c742d4d617269656e646f726612ac020a01331aa60\
20a1b0a15317c32353434357c327c38367c31323033323032302a026e33121c12001a\
08080010b8b1abf305220c39303030303030353033303128001236121108c4fffffff\
fffffffff0110c0bfabf3051a1108c4ffffffffffffffff0110c0bfabf305220c3930\
3030303030323333353428001236121108c4ffffffffffffffff0110fcbfabf3051a1\
108c4ffffffffffffffff0110fcbfabf305220c393030303030303233323033280012\
36121108c4ffffffffffffffff0110f4c0abf3051a1108c4ffffffffffffffff0110f\
4c0abf305220c39303030303030323332303428001225121108c4ffffffffffffffff\
0110b0c1abf3051a00220c39303030303030353631303128001a1a0a0534303831331\
211552057697474656e62657267706c61747a124f0a0134224a0a1c0a15317c363435\
31327c317c38367c31323033323032302a036e3138120a0d666652421566665641200\
23a0c393030303030303035323035420e120c55204d6f6872656e7374722e122c0a01\
3522270a070a0274312a0141120a0da4709d3f158fc2154042100a066275732d31321\
206427573203132`,
'hex'
))
ok(Number.isInteger(full.timeModified()), 'invalid full.timeModified()')
Expand Down

0 comments on commit fde2f7a

Please sign in to comment.