x-cubed / event-store-client

JS client library for connecting to Event Store over TCP/IP
The Unlicense
71 stars 24 forks source link

StoredEvent data and others received as Buffer #39

Closed mariobittencourt closed 4 years ago

mariobittencourt commented 4 years ago

Hi, I am using this library to interface with the event store 5.0.8.

I am able to write to the streams and by checking in the web interface I can see the contents correctly, such as the event type and the data.

But when I subscribe, I see that some fields are returned as Buffer. Example of a console.log of one event retrieved shows

{
  streamId: '$ce-mystream',
  eventNumber: 54,
  eventId: 'bad6ce85-edff-4c13-a6fa-63c7f755257a',
  eventType: '$>',
  isJson: false,
  created: 2020-05-10T19:40:23.166Z,
  data: <Buffer ...

I could not find how to have access to the original value

x-cubed commented 4 years ago

Hi Mario,

The Buffer API is described at: https://nodejs.org/api/buffer.html

If the data you're dealing with is text, you can call toString() on the Buffer object to decode the bytes from UTF-8 to a string.

If you're dealing with binary data, you can use the values() function to get an iterator that returns each byte, or you can use the .read*() methods to read the bytes as integers, etc.

mariobittencourt commented 4 years ago

Hi, thanks for the quick reply. I am reading from a stream created from a standard category projection, so I have individual streams called something-**** so it creates a $ce-something.

the eventType appears as '$>' and the data, after toString shows something like 2@something-45c343fc-4051-468c-baf3-eefe052595be which is the order and stream name of the origin event.

I wonder if I am doing something wrong on this case. In this case, is there a way to navigate to the actual event content directly ?

mariobittencourt commented 4 years ago

Hi, @x-cubed nevermind. the settings resolve link tos was set to false. By setting to true I am receiving the original event as expected.