OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

illegal token 'Expected' when trying to use a protocol buffer in a react native program

  • Thread starter Thread starter CuriousCoder
  • Start date Start date
C

CuriousCoder

Guest
I am trying to write a simple app that utilizes the GTFS (General/Goodle Transit Feed Specification) to retrieve alerts regarding conditions on the road. I have managed to get the code snippet which I am working with to work with vanilla js and typescript, but so far I have not managed to get it to work with react native, which is specifically what I would need it to work with. Below is a snippet of the code that I use at the moment (that works with ts and js)

Code:
      const url = CONSTANTS.API_URL;
  
  
      protobuf.load('protocol.proto', (err, root) => {
      if (err) {
          throw err;
      }
  
      const TransitRealtime = root.lookupType('transit_realtime.FeedMessage');
      fetch(url)
          .then(response => response.arrayBuffer())
          .then(buffer => {
          const message = TransitRealtime.decode(new Uint8Array(buffer));
          const object = TransitRealtime.toObject(message, {
              longs: String,
              enums: String,
              bytes: String,
          });
          console.log(object.entity[1].alert.headerText);
          console.log(object.entity[1].alert.descriptionText);
          })
          .catch(error => {
          console.error('There was a problem with the fetch operation:', error);
          });
      });

My react-native project uses .js as the file format.

I have the default GTFS protocol .proto file located in android/app/src/main/assets at the moment and the code should be able to access it (I tried to use RNFS to read and display the contents in console which worked fine).

The baffling thing to me is that the word 'Expected' does not exists anywhere in my whole workspace. This is also my first time using protocol buffers. I use protobufjs to handle them.

<p>I am trying to write a simple app that utilizes the GTFS (General/Goodle Transit Feed Specification) to retrieve alerts regarding conditions on the road. I have managed to get the code snippet which I am working with to work with vanilla js and typescript, but so far I have not managed to get it to work with react native, which is specifically what I would need it to work with. Below is a snippet of the code that I use at the moment (that works with ts and js)</p>
<pre><code> const url = CONSTANTS.API_URL;


protobuf.load('protocol.proto', (err, root) => {
if (err) {
throw err;
}

const TransitRealtime = root.lookupType('transit_realtime.FeedMessage');
fetch(url)
.then(response => response.arrayBuffer())
.then(buffer => {
const message = TransitRealtime.decode(new Uint8Array(buffer));
const object = TransitRealtime.toObject(message, {
longs: String,
enums: String,
bytes: String,
});
console.log(object.entity[1].alert.headerText);
console.log(object.entity[1].alert.descriptionText);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
});
</code></pre>
<p>My react-native project uses .js as the file format.</p>
<p>I have the default GTFS protocol .proto file located in android/app/src/main/assets at the moment and the code should be able to access it (I tried to use RNFS to read and display the contents in console which worked fine).</p>
<p>The baffling thing to me is that the word 'Expected' does not exists anywhere in my whole workspace. This is also my first time using protocol buffers. I use protobufjs to handle them.</p>
 

Latest posts

H
Replies
0
Views
1
habrewning
H
Top