3

I'm trying to use saxophone for parsing json to protobuf message on the fly, and want to avoid creating string instances for each response.

For that i need to create Bytes instance from InputStream (that is provided from apache http entity).

I'm digging sources for a while but cant find way to do that... any suggestions?

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
vach
  • 10,571
  • 12
  • 68
  • 106
  • Hi vach, please share some of your code, without code, people are likely to skip your question. – Jaap Nov 02 '15 at 14:13
  • will do next time, for now i have the solution besides question is quite self explanatory, take any inputstream and turn it into Bytes to use in openhft projects... – vach Nov 05 '15 at 09:57

1 Answers1

3

There is two ways you can do this.

// reuse a string builder if the String cannot be pooled easily
stringBuilder.setLength(0);
bytes.parseUTF(stringBuilder, StopCharTesters.ALL);

or you can use the built in String pool

String s = bytes.parseUTF(StopCharTesters.ALL);

This will work well if there is a relative small number of possible Strings (at least most of the time)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Thanks Peter, is there some kind of a guide to general purpose projects like wire or bytes? I've just getting started with these awesome libs but i'm figuring out things looking at tests and generally reading source... – vach Nov 02 '15 at 17:14
  • 1
    Wire has basic docs https://github.com/OpenHFT/Chronicle-Wire but Bytes needs much more https://github.com/OpenHFT/Chronicle-Bytes I am more than happy to answer questions and accept pull requests for improved docs. – Peter Lawrey Nov 02 '15 at 17:22