xiijima / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
0 stars 0 forks source link

Add functionality to load protobuf schema from Reader #139

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently class 'ProtoUtil' has methods for loading schema from a File, URL and 
generic InputStream. It would be nice to allow loading from java.io.Reader 
and/or from String that contains schema.
One use case is that of testing (to include Schema inline as String), but for 
my use case I want to allow passing in a String or Reader as external protobuf 
schena source.

Original issue reported on code.google.com by tsaloranta@gmail.com on 16 Jan 2013 at 4:32

GoogleCodeExporter commented 8 years ago
FWIW I think change itself is simple, given that ANTLR exposes various 
alternative input sources. I can submit a patch if that would simplify addition.

Original comment by tsaloranta@gmail.com on 16 Jan 2013 at 4:33

GoogleCodeExporter commented 8 years ago
Note: a related question is that of resolving imports. I don't know what 
currently happens when source other than File is specified: I guess two obvious 
possibilities are an error, or use of current working directory.
I think it would be nice to allow specifying alternate base directory.

Original comment by tsaloranta@gmail.com on 16 Jan 2013 at 4:35

GoogleCodeExporter commented 8 years ago
done @rev 1590.

If you want strict protobuf compatibility, set these properties:
-Dproto_path=your/basedir -Dproto_search_strategy=1

1 = lookups to be done on filesystem only.
2 = filesystem and classpath

In most cases, I use 2.

Original comment by david.yu...@gmail.com on 16 Jan 2013 at 8:14

GoogleCodeExporter commented 8 years ago
Thank you for the quick fix!

For me (1) might work best usually, although I could expose (2) as well.

I think I can just verify to see how relative paths are resolved, in absence of 
File as baseline. I would guess it is indeed the current directory, but should 
be easy to check.

As background, this is related to my experimental work on writing protobuf 
backend implementation for Jackson (which I mentioned in email earlier). Not 
much work done yet, but seems very much doable.
One thing I need to figure out is how users would indicate root level message 
type to use; my reading of protobuf documentation suggested that it's defined 
by caller using generated classes usually. But I'll need to see if I missed 
something obvious (like type id in data format).

Original comment by tsaloranta@gmail.com on 16 Jan 2013 at 6:26