Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
I think it's not working with absolute path.

If my imports are like this

import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";


it wont work. But if it's relative it works

import "theme_brand.proto";
import "dark_theme_config.proto";
On Saturday, February 25, 2023 at 5:42:28 AM UTC+5:30 ritesh singh wrote:

> This is resolved. Thanks.
>
> On Saturday, February 25, 2023 at 2:35:02 AM UTC+5:30 Adam Cozzette wrote:
>
>> Probably the cleanest solution would be to cd to the directory containing 
>> com/ and run protoc from there: protoc -I . --include_imports 
>> --descriptor_set_out=/dev/stdout 
>> com/google/samples/apps/nowinandroid/data/user_preferences.proto
>>
>> On Fri, Feb 24, 2023 at 11:11 AM ritesh singh  
>> wrote:
>>
>>> If i remove imports, it works fine.
>>>
>>> On Saturday, February 25, 2023 at 12:41:13 AM UTC+5:30 ritesh singh 
>>> wrote:
>>>
 It looks like this

 syntax = "proto3";

 import 
 "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
 import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";

 option java_package = 
 "com.google.samples.apps.nowinandroid.core.datastore";
 option java_multiple_files = true;

 message UserPreferences {
 reserved 2;
 repeated int32 deprecated_int_followed_topic_ids = 1;
 int32 topicChangeListVersion = 3;
 int32 authorChangeListVersion = 4;
 int32 newsResourceChangeListVersion = 6;
 repeated int32 deprecated_int_followed_author_ids = 7;
 bool has_done_int_to_string_id_migration = 8;
 repeated string deprecated_followed_topic_ids = 9;
 repeated string deprecated_followed_author_ids = 10;
 repeated string deprecated_bookmarked_news_resource_ids = 11;
 bool has_done_list_to_map_migration = 12;

 // Each map is used to store a set of string IDs. The bool has no 
 meaning, but proto3 doesn't
 // have a Set type so this is the closest we can get to a Set.
 map followed_topic_ids = 13;
 map followed_author_ids = 14;
 map bookmarked_news_resource_ids = 15;

 ThemeBrandProto theme_brand = 16;
 DarkThemeConfigProto dark_theme_config = 17;

 bool should_hide_onboarding = 18;

 bool use_dynamic_color = 19;
 }

 On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette 
 wrote:

> What do the import lines in user_preferences.proto look like? In your 
> case the import paths should point to files relative to the current 
> directory.
>
> On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  
> wrote:
>
>> I have 3 proto files in the current directory.
>>
>> user_preferences.proto imports other protos and all are available in 
>> the same directory.
>>
>> But, if i try to run this command, it throws an error. - *Imported 
>> file not found.*
>>
>>
>>
>> *protoc --include_imports --descriptor_set_out=/dev/stdout 
>> user_preferences.proto*
>> Here, I am trying to invoke protoc with --descriptor_set_out to parse 
>> the proto file and convert it into a serialized FileDescriptorSet
>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to protobuf+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
>>  
>> 
>> .
>>
> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to protobuf+u...@googlegroups.com.
>>>
>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/protobuf/93225cb4-eadc-4a71-9f89-f169043f6da7n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/e1aab6d0-746d-431a-a4ba-f884060e87cen%40googlegroups.com.


Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
This is resolved. Thanks.

On Saturday, February 25, 2023 at 2:35:02 AM UTC+5:30 Adam Cozzette wrote:

> Probably the cleanest solution would be to cd to the directory containing 
> com/ and run protoc from there: protoc -I . --include_imports 
> --descriptor_set_out=/dev/stdout 
> com/google/samples/apps/nowinandroid/data/user_preferences.proto
>
> On Fri, Feb 24, 2023 at 11:11 AM ritesh singh  wrote:
>
>> If i remove imports, it works fine.
>>
>> On Saturday, February 25, 2023 at 12:41:13 AM UTC+5:30 ritesh singh wrote:
>>
>>> It looks like this
>>>
>>> syntax = "proto3";
>>>
>>> import 
>>> "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
>>> import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";
>>>
>>> option java_package = 
>>> "com.google.samples.apps.nowinandroid.core.datastore";
>>> option java_multiple_files = true;
>>>
>>> message UserPreferences {
>>> reserved 2;
>>> repeated int32 deprecated_int_followed_topic_ids = 1;
>>> int32 topicChangeListVersion = 3;
>>> int32 authorChangeListVersion = 4;
>>> int32 newsResourceChangeListVersion = 6;
>>> repeated int32 deprecated_int_followed_author_ids = 7;
>>> bool has_done_int_to_string_id_migration = 8;
>>> repeated string deprecated_followed_topic_ids = 9;
>>> repeated string deprecated_followed_author_ids = 10;
>>> repeated string deprecated_bookmarked_news_resource_ids = 11;
>>> bool has_done_list_to_map_migration = 12;
>>>
>>> // Each map is used to store a set of string IDs. The bool has no 
>>> meaning, but proto3 doesn't
>>> // have a Set type so this is the closest we can get to a Set.
>>> map followed_topic_ids = 13;
>>> map followed_author_ids = 14;
>>> map bookmarked_news_resource_ids = 15;
>>>
>>> ThemeBrandProto theme_brand = 16;
>>> DarkThemeConfigProto dark_theme_config = 17;
>>>
>>> bool should_hide_onboarding = 18;
>>>
>>> bool use_dynamic_color = 19;
>>> }
>>>
>>> On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette 
>>> wrote:
>>>
 What do the import lines in user_preferences.proto look like? In your 
 case the import paths should point to files relative to the current 
 directory.

 On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  
 wrote:

> I have 3 proto files in the current directory.
>
> user_preferences.proto imports other protos and all are available in 
> the same directory.
>
> But, if i try to run this command, it throws an error. - *Imported 
> file not found.*
>
>
>
> *protoc --include_imports --descriptor_set_out=/dev/stdout 
> user_preferences.proto*
> Here, I am trying to invoke protoc with --descriptor_set_out to parse 
> the proto file and convert it into a serialized FileDescriptorSet
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to protobuf+u...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
>  
> 
> .
>
 -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to protobuf+u...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/protobuf/93225cb4-eadc-4a71-9f89-f169043f6da7n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/1afac4e1-e71a-40db-9540-6b69afad6ab8n%40googlegroups.com.


Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread ritesh singh
Ahh yes, thanks a lot. I was using wrong JsonFormat 
com.android.tools.idea.protobuf.util.JsonFormat

On Saturday, February 25, 2023 at 3:47:43 AM UTC+5:30 Adam Cozzette wrote:

> Once you have the DynamicMessage, you can use the JsonFormat API the same 
> way you would use it with ordinary messages.
>
> On Fri, Feb 24, 2023 at 1:52 PM ritesh singh  wrote:
>
>> Thanks, any leads on generating json at run time using dynamicMessage. 
>> Any existing api util if you can point me to.
>>
>> On Saturday, February 25, 2023 at 2:44:14 AM UTC+5:30 Adam Cozzette wrote:
>>
>>> I think DynamicMessage is the right approach since you need to work with 
>>> proto files that are only known at run time. This will also allow you to 
>>> generate JSON.
>>>
>>> On Fri, Feb 24, 2023 at 11:19 AM ritesh singh  
>>> wrote:
>>>

 Or if there's a better different approach instead of relying on 
 FileDescriptorSet and DynamicMessage - considering i have access to only 
 .pb (generate by proto-lite) or .proto file.
 On Saturday, February 25, 2023 at 12:46:44 AM UTC+5:30 ritesh singh 
 wrote:

> Thanks Adam, so basically i am writing an Intellij plugin for Android 
> Studio. 
> The plugin will just take the .pb file and .proto file, run the protoc 
> compiler, generate FileDescriptorSet for proto and create a 
> DynamicMessage 
> using generated fileDescriptorSet and .pb.
>
> I was wondering if there a way to generate the json schema, as in 
> key-value pair. As we know, lite version doesn't include fileds, is it 
> possible to do it at run-time, as in extract keys in any phase?
>
> On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette 
> wrote:
>
>> A serialized protocol buffer doesn't include any type information, so 
>> before you can parse one you have to know in advance which type you're 
>> expecting. If you want to be prepared to accept either A or B, then a 
>> good 
>> solution is to put both types inside a oneof in a parent message, and 
>> then 
>> just parse the parent message normally.
>>
>> It doesn't matter which protobuf implementation created the .pb file, 
>> since all implementations use the same wire format.
>>
>> That is true that the Java lite implementation doesn't support 
>> reflection and doesn't include descriptors, so it cannot serialize 
>> protos 
>> to JSON. If you can stick to the binary format then that would be ideal 
>> since that format is useable everywhere.
>>
>> On Thu, Feb 23, 2023 at 5:33 PM ritesh singh  
>> wrote:
>>
>>> Also does it matter if .pb was created using proto lite and android 
>>> end.
>>>
>>> I believe the lite version doesn't store fields, so converting it to 
>>> json using proto-util won't work and i need to make use of reflection.
>>>
>>> On Fri, 24 Feb, 2023, 6:54 am ritesh singh,  
>>> wrote:
>>>
 Thanks Adam. I will give it a shot. I thought of using *protoc*  
 compiler, but what if my proto file contains nested messages




 *message A {  B b = 1}*
 *message B {*
 *}*


 After running *protoc *on the proto file, it will generate 2 java 
 classes. I won't know which generated class to use against my .pb 
 file, as 
 my plugin is only aware of .pb and .proto file.

 Please correct me, if am wrong.
 On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette 
 wrote:

> I suspect that your code is getting an error because it's trying 
> to parse a .proto file as a serialized protocol buffer. (This won't 
> work 
> since .proto files use a text representation very different from the 
> standard protobuf binary format.) Probably the best way to fix this 
> problem 
> would be to invoke protoc with --descriptor_set_out to parse the 
> proto file 
> and convert it into a serialized FileDescriptorSet. A 
> FileDescriptorSet is 
> just a protocol buffer, so once you have it in that form you can 
> easily 
> parse it like you would parse any other serialized proto.
>
> On Thu, Feb 23, 2023 at 4:59 PM ritesh singh  
> wrote:
>
>> Hello, 
>>
>> I am working on creating a Android Studio plugin for proto data 
>> store.
>> Android uses proto-lite, my current approach, i get the .pb file 
>> and .proto file and use the same in intellij plugin to deserialise 
>> it.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *val psiFile = 
>> PsiManager.getInstance(project).findFile(protoFile) val 
>> protoFileContent = 

Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread 'Adam Cozzette' via Protocol Buffers
Once you have the DynamicMessage, you can use the JsonFormat API the same
way you would use it with ordinary messages.

On Fri, Feb 24, 2023 at 1:52 PM ritesh singh  wrote:

> Thanks, any leads on generating json at run time using dynamicMessage. Any
> existing api util if you can point me to.
>
> On Saturday, February 25, 2023 at 2:44:14 AM UTC+5:30 Adam Cozzette wrote:
>
>> I think DynamicMessage is the right approach since you need to work with
>> proto files that are only known at run time. This will also allow you to
>> generate JSON.
>>
>> On Fri, Feb 24, 2023 at 11:19 AM ritesh singh 
>> wrote:
>>
>>>
>>> Or if there's a better different approach instead of relying on
>>> FileDescriptorSet and DynamicMessage - considering i have access to only
>>> .pb (generate by proto-lite) or .proto file.
>>> On Saturday, February 25, 2023 at 12:46:44 AM UTC+5:30 ritesh singh
>>> wrote:
>>>
 Thanks Adam, so basically i am writing an Intellij plugin for Android
 Studio.
 The plugin will just take the .pb file and .proto file, run the protoc
 compiler, generate FileDescriptorSet for proto and create a DynamicMessage
 using generated fileDescriptorSet and .pb.

 I was wondering if there a way to generate the json schema, as in
 key-value pair. As we know, lite version doesn't include fileds, is it
 possible to do it at run-time, as in extract keys in any phase?

 On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette
 wrote:

> A serialized protocol buffer doesn't include any type information, so
> before you can parse one you have to know in advance which type you're
> expecting. If you want to be prepared to accept either A or B, then a good
> solution is to put both types inside a oneof in a parent message, and then
> just parse the parent message normally.
>
> It doesn't matter which protobuf implementation created the .pb file,
> since all implementations use the same wire format.
>
> That is true that the Java lite implementation doesn't support
> reflection and doesn't include descriptors, so it cannot serialize protos
> to JSON. If you can stick to the binary format then that would be ideal
> since that format is useable everywhere.
>
> On Thu, Feb 23, 2023 at 5:33 PM ritesh singh 
> wrote:
>
>> Also does it matter if .pb was created using proto lite and android
>> end.
>>
>> I believe the lite version doesn't store fields, so converting it to
>> json using proto-util won't work and i need to make use of reflection.
>>
>> On Fri, 24 Feb, 2023, 6:54 am ritesh singh, 
>> wrote:
>>
>>> Thanks Adam. I will give it a shot. I thought of using *protoc*
>>> compiler, but what if my proto file contains nested messages
>>>
>>>
>>>
>>>
>>> *message A {  B b = 1}*
>>> *message B {*
>>> *}*
>>>
>>>
>>> After running *protoc *on the proto file, it will generate 2 java
>>> classes. I won't know which generated class to use against my .pb file, 
>>> as
>>> my plugin is only aware of .pb and .proto file.
>>>
>>> Please correct me, if am wrong.
>>> On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette
>>> wrote:
>>>
 I suspect that your code is getting an error because it's trying to
 parse a .proto file as a serialized protocol buffer. (This won't work 
 since
 .proto files use a text representation very different from the standard
 protobuf binary format.) Probably the best way to fix this problem 
 would be
 to invoke protoc with --descriptor_set_out to parse the proto file and
 convert it into a serialized FileDescriptorSet. A FileDescriptorSet is 
 just
 a protocol buffer, so once you have it in that form you can easily 
 parse it
 like you would parse any other serialized proto.

 On Thu, Feb 23, 2023 at 4:59 PM ritesh singh 
 wrote:

> Hello,
>
> I am working on creating a Android Studio plugin for proto data
> store.
> Android uses proto-lite, my current approach, i get the .pb file
> and .proto file and use the same in intellij plugin to deserialise it.
>
>
>
>
>
>
>
>
>
>
>
>
> *val psiFile = PsiManager.getInstance(project).findFile(protoFile)
> val protoFileContent = psiFile!!.text val fileDescriptorProto:
> DescriptorProtos.FileDescriptorProto =
> DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
> val fileDescriptor =
> Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, 
> arrayOfNulls(0))
> val messageDescriptor = fileDescriptor.messageTypes[0] val buffer =
> 

Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread ritesh singh
Thanks, any leads on generating json at run time using dynamicMessage. Any 
existing api util if you can point me to.

On Saturday, February 25, 2023 at 2:44:14 AM UTC+5:30 Adam Cozzette wrote:

> I think DynamicMessage is the right approach since you need to work with 
> proto files that are only known at run time. This will also allow you to 
> generate JSON.
>
> On Fri, Feb 24, 2023 at 11:19 AM ritesh singh  wrote:
>
>>
>> Or if there's a better different approach instead of relying on 
>> FileDescriptorSet and DynamicMessage - considering i have access to only 
>> .pb (generate by proto-lite) or .proto file.
>> On Saturday, February 25, 2023 at 12:46:44 AM UTC+5:30 ritesh singh wrote:
>>
>>> Thanks Adam, so basically i am writing an Intellij plugin for Android 
>>> Studio. 
>>> The plugin will just take the .pb file and .proto file, run the protoc 
>>> compiler, generate FileDescriptorSet for proto and create a DynamicMessage 
>>> using generated fileDescriptorSet and .pb.
>>>
>>> I was wondering if there a way to generate the json schema, as in 
>>> key-value pair. As we know, lite version doesn't include fileds, is it 
>>> possible to do it at run-time, as in extract keys in any phase?
>>>
>>> On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette 
>>> wrote:
>>>
 A serialized protocol buffer doesn't include any type information, so 
 before you can parse one you have to know in advance which type you're 
 expecting. If you want to be prepared to accept either A or B, then a good 
 solution is to put both types inside a oneof in a parent message, and then 
 just parse the parent message normally.

 It doesn't matter which protobuf implementation created the .pb file, 
 since all implementations use the same wire format.

 That is true that the Java lite implementation doesn't support 
 reflection and doesn't include descriptors, so it cannot serialize protos 
 to JSON. If you can stick to the binary format then that would be ideal 
 since that format is useable everywhere.

 On Thu, Feb 23, 2023 at 5:33 PM ritesh singh  
 wrote:

> Also does it matter if .pb was created using proto lite and android 
> end.
>
> I believe the lite version doesn't store fields, so converting it to 
> json using proto-util won't work and i need to make use of reflection.
>
> On Fri, 24 Feb, 2023, 6:54 am ritesh singh,  
> wrote:
>
>> Thanks Adam. I will give it a shot. I thought of using *protoc*  
>> compiler, but what if my proto file contains nested messages
>>
>>
>>
>>
>> *message A {  B b = 1}*
>> *message B {*
>> *}*
>>
>>
>> After running *protoc *on the proto file, it will generate 2 java 
>> classes. I won't know which generated class to use against my .pb file, 
>> as 
>> my plugin is only aware of .pb and .proto file.
>>
>> Please correct me, if am wrong.
>> On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette 
>> wrote:
>>
>>> I suspect that your code is getting an error because it's trying to 
>>> parse a .proto file as a serialized protocol buffer. (This won't work 
>>> since 
>>> .proto files use a text representation very different from the standard 
>>> protobuf binary format.) Probably the best way to fix this problem 
>>> would be 
>>> to invoke protoc with --descriptor_set_out to parse the proto file and 
>>> convert it into a serialized FileDescriptorSet. A FileDescriptorSet is 
>>> just 
>>> a protocol buffer, so once you have it in that form you can easily 
>>> parse it 
>>> like you would parse any other serialized proto.
>>>
>>> On Thu, Feb 23, 2023 at 4:59 PM ritesh singh  
>>> wrote:
>>>
 Hello, 

 I am working on creating a Android Studio plugin for proto data 
 store.
 Android uses proto-lite, my current approach, i get the .pb file 
 and .proto file and use the same in intellij plugin to deserialise it.












 *val psiFile = PsiManager.getInstance(project).findFile(protoFile) 
 val protoFileContent = psiFile!!.text val fileDescriptorProto: 
 DescriptorProtos.FileDescriptorProto = 
 DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
  
 val fileDescriptor = 
 Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, 
 arrayOfNulls(0)) 
 val messageDescriptor = fileDescriptor.messageTypes[0] val buffer = 
 pbFile.contentsToByteArray() val messageBuilder: 
 DynamicMessage.Builder = 
 DynamicMessage.newBuilder(messageDescriptor) 
 messageBuilder.mergeFrom(buffer) val message = messageBuilder.build() 
 val 
 text: String = 

Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
Thanks Adam.

This how my code looks like































* fun decodeProto(protoFile: VirtualFile) { try { val fileDescriptorSet = 
generateFileDescriptorSet(protoFile) val fileDescriptor: 
Descriptors.FileDescriptor = parseFileDescriptorSet(fileDescriptorSet) val 
dynamicMessage:DynamicMessage = 
DynamicMessage.parseFrom(fileDescriptor.messageTypes[0],pbFile.inputStream.readBytes())
 
println(TextFormat.printToString(dynamicMessage)) }catch (ex:Exception){ 
ex.printStackTrace() } } private fun generateFileDescriptorSet(protoFile: 
VirtualFile): ByteArray { val protocCommand = "protoc 
-I=${protoFile.parent} --include_imports --descriptor_set_out=/dev/stdout 
${protoFile.path}" val outputStream = ByteArrayOutputStream() val process = 
Runtime.getRuntime().exec(protocCommand) 
process.inputStream.copyTo(outputStream) process.waitFor() return 
outputStream.toByteArray() } private fun 
parseFileDescriptorSet(fileDescriptorSetBytes: ByteArray): 
Descriptors.FileDescriptor { val fileDescriptorSet = 
DescriptorProtos.FileDescriptorSet.parseFrom(fileDescriptorSetBytes) val 
fileDescriptors = fileDescriptorSet.fileList.map { 
Descriptors.FileDescriptor.buildFrom(it, 
arrayOf()) }.toTypedArray() return 
Descriptors.FileDescriptor.buildFrom( fileDescriptorSet.fileList.first(), 
fileDescriptors ) }*
I was wondering if there is an existing api, which will convert the 
*DynamicMessage 
*to json.

Also, in other thread you mentioned, it's better to use *cd *to fix import 
issues, 
probably do cd here *val protocCommand = "protoc -I=${protoFile.parent} 
--include_imports --descriptor_set_out=/dev/stdout ${protoFile.path}" *and 
then run the command.


Thanks a lot!
On Saturday, February 25, 2023 at 2:35:02 AM UTC+5:30 Adam Cozzette wrote:

> Probably the cleanest solution would be to cd to the directory containing 
> com/ and run protoc from there: protoc -I . --include_imports 
> --descriptor_set_out=/dev/stdout 
> com/google/samples/apps/nowinandroid/data/user_preferences.proto
>
> On Fri, Feb 24, 2023 at 11:11 AM ritesh singh  wrote:
>
>> If i remove imports, it works fine.
>>
>> On Saturday, February 25, 2023 at 12:41:13 AM UTC+5:30 ritesh singh wrote:
>>
>>> It looks like this
>>>
>>> syntax = "proto3";
>>>
>>> import 
>>> "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
>>> import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";
>>>
>>> option java_package = 
>>> "com.google.samples.apps.nowinandroid.core.datastore";
>>> option java_multiple_files = true;
>>>
>>> message UserPreferences {
>>> reserved 2;
>>> repeated int32 deprecated_int_followed_topic_ids = 1;
>>> int32 topicChangeListVersion = 3;
>>> int32 authorChangeListVersion = 4;
>>> int32 newsResourceChangeListVersion = 6;
>>> repeated int32 deprecated_int_followed_author_ids = 7;
>>> bool has_done_int_to_string_id_migration = 8;
>>> repeated string deprecated_followed_topic_ids = 9;
>>> repeated string deprecated_followed_author_ids = 10;
>>> repeated string deprecated_bookmarked_news_resource_ids = 11;
>>> bool has_done_list_to_map_migration = 12;
>>>
>>> // Each map is used to store a set of string IDs. The bool has no 
>>> meaning, but proto3 doesn't
>>> // have a Set type so this is the closest we can get to a Set.
>>> map followed_topic_ids = 13;
>>> map followed_author_ids = 14;
>>> map bookmarked_news_resource_ids = 15;
>>>
>>> ThemeBrandProto theme_brand = 16;
>>> DarkThemeConfigProto dark_theme_config = 17;
>>>
>>> bool should_hide_onboarding = 18;
>>>
>>> bool use_dynamic_color = 19;
>>> }
>>>
>>> On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette 
>>> wrote:
>>>
 What do the import lines in user_preferences.proto look like? In your 
 case the import paths should point to files relative to the current 
 directory.

 On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  
 wrote:

> I have 3 proto files in the current directory.
>
> user_preferences.proto imports other protos and all are available in 
> the same directory.
>
> But, if i try to run this command, it throws an error. - *Imported 
> file not found.*
>
>
>
> *protoc --include_imports --descriptor_set_out=/dev/stdout 
> user_preferences.proto*
> Here, I am trying to invoke protoc with --descriptor_set_out to parse 
> the proto file and convert it into a serialized FileDescriptorSet
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to protobuf+u...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
>  
> 
> .
>

Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread 'Adam Cozzette' via Protocol Buffers
I think DynamicMessage is the right approach since you need to work with
proto files that are only known at run time. This will also allow you to
generate JSON.

On Fri, Feb 24, 2023 at 11:19 AM ritesh singh 
wrote:

>
> Or if there's a better different approach instead of relying on
> FileDescriptorSet and DynamicMessage - considering i have access to only
> .pb (generate by proto-lite) or .proto file.
> On Saturday, February 25, 2023 at 12:46:44 AM UTC+5:30 ritesh singh wrote:
>
>> Thanks Adam, so basically i am writing an Intellij plugin for Android
>> Studio.
>> The plugin will just take the .pb file and .proto file, run the protoc
>> compiler, generate FileDescriptorSet for proto and create a DynamicMessage
>> using generated fileDescriptorSet and .pb.
>>
>> I was wondering if there a way to generate the json schema, as in
>> key-value pair. As we know, lite version doesn't include fileds, is it
>> possible to do it at run-time, as in extract keys in any phase?
>>
>> On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette
>> wrote:
>>
>>> A serialized protocol buffer doesn't include any type information, so
>>> before you can parse one you have to know in advance which type you're
>>> expecting. If you want to be prepared to accept either A or B, then a good
>>> solution is to put both types inside a oneof in a parent message, and then
>>> just parse the parent message normally.
>>>
>>> It doesn't matter which protobuf implementation created the .pb file,
>>> since all implementations use the same wire format.
>>>
>>> That is true that the Java lite implementation doesn't support
>>> reflection and doesn't include descriptors, so it cannot serialize protos
>>> to JSON. If you can stick to the binary format then that would be ideal
>>> since that format is useable everywhere.
>>>
>>> On Thu, Feb 23, 2023 at 5:33 PM ritesh singh 
>>> wrote:
>>>
 Also does it matter if .pb was created using proto lite and android end.

 I believe the lite version doesn't store fields, so converting it to
 json using proto-util won't work and i need to make use of reflection.

 On Fri, 24 Feb, 2023, 6:54 am ritesh singh, 
 wrote:

> Thanks Adam. I will give it a shot. I thought of using *protoc*
> compiler, but what if my proto file contains nested messages
>
>
>
>
> *message A {  B b = 1}*
> *message B {*
> *}*
>
>
> After running *protoc *on the proto file, it will generate 2 java
> classes. I won't know which generated class to use against my .pb file, as
> my plugin is only aware of .pb and .proto file.
>
> Please correct me, if am wrong.
> On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette
> wrote:
>
>> I suspect that your code is getting an error because it's trying to
>> parse a .proto file as a serialized protocol buffer. (This won't work 
>> since
>> .proto files use a text representation very different from the standard
>> protobuf binary format.) Probably the best way to fix this problem would 
>> be
>> to invoke protoc with --descriptor_set_out to parse the proto file and
>> convert it into a serialized FileDescriptorSet. A FileDescriptorSet is 
>> just
>> a protocol buffer, so once you have it in that form you can easily parse 
>> it
>> like you would parse any other serialized proto.
>>
>> On Thu, Feb 23, 2023 at 4:59 PM ritesh singh 
>> wrote:
>>
>>> Hello,
>>>
>>> I am working on creating a Android Studio plugin for proto data
>>> store.
>>> Android uses proto-lite, my current approach, i get the .pb file and
>>> .proto file and use the same in intellij plugin to deserialise it.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *val psiFile = PsiManager.getInstance(project).findFile(protoFile)
>>> val protoFileContent = psiFile!!.text val fileDescriptorProto:
>>> DescriptorProtos.FileDescriptorProto =
>>> DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
>>> val fileDescriptor =
>>> Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, 
>>> arrayOfNulls(0))
>>> val messageDescriptor = fileDescriptor.messageTypes[0] val buffer =
>>> pbFile.contentsToByteArray() val messageBuilder: DynamicMessage.Builder 
>>> =
>>> DynamicMessage.newBuilder(messageDescriptor)
>>> messageBuilder.mergeFrom(buffer) val message = messageBuilder.build() 
>>> val
>>> text: String = TextFormat.printToString(message)*
>>>
>>> Above code is throwing error in parsing step,* Protocol message tag
>>> had invalid wire type.*
>>>
>>> Thanks in advance.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it,

Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread 'Adam Cozzette' via Protocol Buffers
Probably the cleanest solution would be to cd to the directory containing
com/ and run protoc from there: protoc -I . --include_imports
--descriptor_set_out=/dev/stdout
com/google/samples/apps/nowinandroid/data/user_preferences.proto

On Fri, Feb 24, 2023 at 11:11 AM ritesh singh 
wrote:

> If i remove imports, it works fine.
>
> On Saturday, February 25, 2023 at 12:41:13 AM UTC+5:30 ritesh singh wrote:
>
>> It looks like this
>>
>> syntax = "proto3";
>>
>> import
>> "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
>> import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";
>>
>> option java_package =
>> "com.google.samples.apps.nowinandroid.core.datastore";
>> option java_multiple_files = true;
>>
>> message UserPreferences {
>> reserved 2;
>> repeated int32 deprecated_int_followed_topic_ids = 1;
>> int32 topicChangeListVersion = 3;
>> int32 authorChangeListVersion = 4;
>> int32 newsResourceChangeListVersion = 6;
>> repeated int32 deprecated_int_followed_author_ids = 7;
>> bool has_done_int_to_string_id_migration = 8;
>> repeated string deprecated_followed_topic_ids = 9;
>> repeated string deprecated_followed_author_ids = 10;
>> repeated string deprecated_bookmarked_news_resource_ids = 11;
>> bool has_done_list_to_map_migration = 12;
>>
>> // Each map is used to store a set of string IDs. The bool has no
>> meaning, but proto3 doesn't
>> // have a Set type so this is the closest we can get to a Set.
>> map followed_topic_ids = 13;
>> map followed_author_ids = 14;
>> map bookmarked_news_resource_ids = 15;
>>
>> ThemeBrandProto theme_brand = 16;
>> DarkThemeConfigProto dark_theme_config = 17;
>>
>> bool should_hide_onboarding = 18;
>>
>> bool use_dynamic_color = 19;
>> }
>>
>> On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette
>> wrote:
>>
>>> What do the import lines in user_preferences.proto look like? In your
>>> case the import paths should point to files relative to the current
>>> directory.
>>>
>>> On Fri, Feb 24, 2023 at 9:40 AM ritesh singh 
>>> wrote:
>>>
 I have 3 proto files in the current directory.

 user_preferences.proto imports other protos and all are available in
 the same directory.

 But, if i try to run this command, it throws an error. - *Imported
 file not found.*



 *protoc --include_imports --descriptor_set_out=/dev/stdout
 user_preferences.proto*
 Here, I am trying to invoke protoc with --descriptor_set_out to parse
 the proto file and convert it into a serialized FileDescriptorSet

 --
 You received this message because you are subscribed to the Google
 Groups "Protocol Buffers" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to protobuf+u...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
 
 .

>>> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/93225cb4-eadc-4a71-9f89-f169043f6da7n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr6bRKxHhbC2LTQmU%2BBmffXOg4fAWcrGurBrSNF_XJJyMQ%40mail.gmail.com.


Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread ritesh singh

Or if there's a better different approach instead of relying on 
FileDescriptorSet and DynamicMessage - considering i have access to only 
.pb (generate by proto-lite) or .proto file.
On Saturday, February 25, 2023 at 12:46:44 AM UTC+5:30 ritesh singh wrote:

> Thanks Adam, so basically i am writing an Intellij plugin for Android 
> Studio. 
> The plugin will just take the .pb file and .proto file, run the protoc 
> compiler, generate FileDescriptorSet for proto and create a DynamicMessage 
> using generated fileDescriptorSet and .pb.
>
> I was wondering if there a way to generate the json schema, as in 
> key-value pair. As we know, lite version doesn't include fileds, is it 
> possible to do it at run-time, as in extract keys in any phase?
>
> On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette wrote:
>
>> A serialized protocol buffer doesn't include any type information, so 
>> before you can parse one you have to know in advance which type you're 
>> expecting. If you want to be prepared to accept either A or B, then a good 
>> solution is to put both types inside a oneof in a parent message, and then 
>> just parse the parent message normally.
>>
>> It doesn't matter which protobuf implementation created the .pb file, 
>> since all implementations use the same wire format.
>>
>> That is true that the Java lite implementation doesn't support reflection 
>> and doesn't include descriptors, so it cannot serialize protos to JSON. If 
>> you can stick to the binary format then that would be ideal since that 
>> format is useable everywhere.
>>
>> On Thu, Feb 23, 2023 at 5:33 PM ritesh singh  wrote:
>>
>>> Also does it matter if .pb was created using proto lite and android end.
>>>
>>> I believe the lite version doesn't store fields, so converting it to 
>>> json using proto-util won't work and i need to make use of reflection.
>>>
>>> On Fri, 24 Feb, 2023, 6:54 am ritesh singh,  wrote:
>>>
 Thanks Adam. I will give it a shot. I thought of using *protoc*  
 compiler, but what if my proto file contains nested messages




 *message A {  B b = 1}*
 *message B {*
 *}*


 After running *protoc *on the proto file, it will generate 2 java 
 classes. I won't know which generated class to use against my .pb file, as 
 my plugin is only aware of .pb and .proto file.

 Please correct me, if am wrong.
 On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette wrote:

> I suspect that your code is getting an error because it's trying to 
> parse a .proto file as a serialized protocol buffer. (This won't work 
> since 
> .proto files use a text representation very different from the standard 
> protobuf binary format.) Probably the best way to fix this problem would 
> be 
> to invoke protoc with --descriptor_set_out to parse the proto file and 
> convert it into a serialized FileDescriptorSet. A FileDescriptorSet is 
> just 
> a protocol buffer, so once you have it in that form you can easily parse 
> it 
> like you would parse any other serialized proto.
>
> On Thu, Feb 23, 2023 at 4:59 PM ritesh singh  
> wrote:
>
>> Hello, 
>>
>> I am working on creating a Android Studio plugin for proto data store.
>> Android uses proto-lite, my current approach, i get the .pb file and 
>> .proto file and use the same in intellij plugin to deserialise it.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *val psiFile = PsiManager.getInstance(project).findFile(protoFile) 
>> val protoFileContent = psiFile!!.text val fileDescriptorProto: 
>> DescriptorProtos.FileDescriptorProto = 
>> DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
>>  
>> val fileDescriptor = 
>> Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, 
>> arrayOfNulls(0)) 
>> val messageDescriptor = fileDescriptor.messageTypes[0] val buffer = 
>> pbFile.contentsToByteArray() val messageBuilder: DynamicMessage.Builder 
>> = 
>> DynamicMessage.newBuilder(messageDescriptor) 
>> messageBuilder.mergeFrom(buffer) val message = messageBuilder.build() 
>> val 
>> text: String = TextFormat.printToString(message)*
>>
>> Above code is throwing error in parsing step,* Protocol message tag 
>> had invalid wire type.*
>>
>> Thanks in advance.
>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to protobuf+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/protobuf/7fe3a019-e846-4792-8d8a-1655a2d93975n%40googlegroups.com
>>  
>> 

Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread ritesh singh
Thanks Adam, so basically i am writing an Intellij plugin for Android 
Studio. 
The plugin will just take the .pb file and .proto file, run the protoc 
compiler, generate FileDescriptorSet for proto and create a DynamicMessage 
using generated fileDescriptorSet and .pb.

I was wondering if there a way to generate the json schema, as in key-value 
pair. As we know, lite version doesn't include fileds, is it possible to do 
it at run-time, as in extract keys in any phase?

On Saturday, February 25, 2023 at 12:30:54 AM UTC+5:30 Adam Cozzette wrote:

> A serialized protocol buffer doesn't include any type information, so 
> before you can parse one you have to know in advance which type you're 
> expecting. If you want to be prepared to accept either A or B, then a good 
> solution is to put both types inside a oneof in a parent message, and then 
> just parse the parent message normally.
>
> It doesn't matter which protobuf implementation created the .pb file, 
> since all implementations use the same wire format.
>
> That is true that the Java lite implementation doesn't support reflection 
> and doesn't include descriptors, so it cannot serialize protos to JSON. If 
> you can stick to the binary format then that would be ideal since that 
> format is useable everywhere.
>
> On Thu, Feb 23, 2023 at 5:33 PM ritesh singh  wrote:
>
>> Also does it matter if .pb was created using proto lite and android end.
>>
>> I believe the lite version doesn't store fields, so converting it to json 
>> using proto-util won't work and i need to make use of reflection.
>>
>> On Fri, 24 Feb, 2023, 6:54 am ritesh singh,  wrote:
>>
>>> Thanks Adam. I will give it a shot. I thought of using *protoc*  
>>> compiler, but what if my proto file contains nested messages
>>>
>>>
>>>
>>>
>>> *message A {  B b = 1}*
>>> *message B {*
>>> *}*
>>>
>>>
>>> After running *protoc *on the proto file, it will generate 2 java 
>>> classes. I won't know which generated class to use against my .pb file, as 
>>> my plugin is only aware of .pb and .proto file.
>>>
>>> Please correct me, if am wrong.
>>> On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette wrote:
>>>
 I suspect that your code is getting an error because it's trying to 
 parse a .proto file as a serialized protocol buffer. (This won't work 
 since 
 .proto files use a text representation very different from the standard 
 protobuf binary format.) Probably the best way to fix this problem would 
 be 
 to invoke protoc with --descriptor_set_out to parse the proto file and 
 convert it into a serialized FileDescriptorSet. A FileDescriptorSet is 
 just 
 a protocol buffer, so once you have it in that form you can easily parse 
 it 
 like you would parse any other serialized proto.

 On Thu, Feb 23, 2023 at 4:59 PM ritesh singh  
 wrote:

> Hello, 
>
> I am working on creating a Android Studio plugin for proto data store.
> Android uses proto-lite, my current approach, i get the .pb file and 
> .proto file and use the same in intellij plugin to deserialise it.
>
>
>
>
>
>
>
>
>
>
>
>
> *val psiFile = PsiManager.getInstance(project).findFile(protoFile) val 
> protoFileContent = psiFile!!.text val fileDescriptorProto: 
> DescriptorProtos.FileDescriptorProto = 
> DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
>  
> val fileDescriptor = 
> Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, 
> arrayOfNulls(0)) 
> val messageDescriptor = fileDescriptor.messageTypes[0] val buffer = 
> pbFile.contentsToByteArray() val messageBuilder: DynamicMessage.Builder = 
> DynamicMessage.newBuilder(messageDescriptor) 
> messageBuilder.mergeFrom(buffer) val message = messageBuilder.build() val 
> text: String = TextFormat.printToString(message)*
>
> Above code is throwing error in parsing step,* Protocol message tag 
> had invalid wire type.*
>
> Thanks in advance.
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to protobuf+u...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/protobuf/7fe3a019-e846-4792-8d8a-1655a2d93975n%40googlegroups.com
>  
> 
> .
>
 -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to protobuf+u...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> 

Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
If i remove imports, it works fine.

On Saturday, February 25, 2023 at 12:41:13 AM UTC+5:30 ritesh singh wrote:

> It looks like this
>
> syntax = "proto3";
>
> import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto"
> ;
> import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";
>
> option java_package = 
> "com.google.samples.apps.nowinandroid.core.datastore";
> option java_multiple_files = true;
>
> message UserPreferences {
> reserved 2;
> repeated int32 deprecated_int_followed_topic_ids = 1;
> int32 topicChangeListVersion = 3;
> int32 authorChangeListVersion = 4;
> int32 newsResourceChangeListVersion = 6;
> repeated int32 deprecated_int_followed_author_ids = 7;
> bool has_done_int_to_string_id_migration = 8;
> repeated string deprecated_followed_topic_ids = 9;
> repeated string deprecated_followed_author_ids = 10;
> repeated string deprecated_bookmarked_news_resource_ids = 11;
> bool has_done_list_to_map_migration = 12;
>
> // Each map is used to store a set of string IDs. The bool has no meaning, 
> but proto3 doesn't
> // have a Set type so this is the closest we can get to a Set.
> map followed_topic_ids = 13;
> map followed_author_ids = 14;
> map bookmarked_news_resource_ids = 15;
>
> ThemeBrandProto theme_brand = 16;
> DarkThemeConfigProto dark_theme_config = 17;
>
> bool should_hide_onboarding = 18;
>
> bool use_dynamic_color = 19;
> }
>
> On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette wrote:
>
>> What do the import lines in user_preferences.proto look like? In your 
>> case the import paths should point to files relative to the current 
>> directory.
>>
>> On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  wrote:
>>
>>> I have 3 proto files in the current directory.
>>>
>>> user_preferences.proto imports other protos and all are available in the 
>>> same directory.
>>>
>>> But, if i try to run this command, it throws an error. - *Imported file 
>>> not found.*
>>>
>>>
>>>
>>> *protoc --include_imports --descriptor_set_out=/dev/stdout 
>>> user_preferences.proto*
>>> Here, I am trying to invoke protoc with --descriptor_set_out to parse 
>>> the proto file and convert it into a serialized FileDescriptorSet
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to protobuf+u...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/93225cb4-eadc-4a71-9f89-f169043f6da7n%40googlegroups.com.


Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
It looks like this

syntax = "proto3";

import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";

option java_package = "com.google.samples.apps.nowinandroid.core.datastore";
option java_multiple_files = true;

message UserPreferences {
reserved 2;
repeated int32 deprecated_int_followed_topic_ids = 1;
int32 topicChangeListVersion = 3;
int32 authorChangeListVersion = 4;
int32 newsResourceChangeListVersion = 6;
repeated int32 deprecated_int_followed_author_ids = 7;
bool has_done_int_to_string_id_migration = 8;
repeated string deprecated_followed_topic_ids = 9;
repeated string deprecated_followed_author_ids = 10;
repeated string deprecated_bookmarked_news_resource_ids = 11;
bool has_done_list_to_map_migration = 12;

// Each map is used to store a set of string IDs. The bool has no meaning, 
but proto3 doesn't
// have a Set type so this is the closest we can get to a Set.
map followed_topic_ids = 13;
map followed_author_ids = 14;
map bookmarked_news_resource_ids = 15;

ThemeBrandProto theme_brand = 16;
DarkThemeConfigProto dark_theme_config = 17;

bool should_hide_onboarding = 18;

bool use_dynamic_color = 19;
}

On Saturday, February 25, 2023 at 12:34:51 AM UTC+5:30 Adam Cozzette wrote:

> What do the import lines in user_preferences.proto look like? In your case 
> the import paths should point to files relative to the current directory.
>
> On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  wrote:
>
>> I have 3 proto files in the current directory.
>>
>> user_preferences.proto imports other protos and all are available in the 
>> same directory.
>>
>> But, if i try to run this command, it throws an error. - *Imported file 
>> not found.*
>>
>>
>>
>> *protoc --include_imports --descriptor_set_out=/dev/stdout 
>> user_preferences.proto*
>> Here, I am trying to invoke protoc with --descriptor_set_out to parse the 
>> proto file and convert it into a serialized FileDescriptorSet
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to protobuf+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/6194a065-e0be-4fb4-a1f6-a26f109ff5a4n%40googlegroups.com.


Re: [protobuf] Proto File not found while running protoc

2023-02-24 Thread 'Adam Cozzette' via Protocol Buffers
What do the import lines in user_preferences.proto look like? In your case
the import paths should point to files relative to the current directory.

On Fri, Feb 24, 2023 at 9:40 AM ritesh singh  wrote:

> I have 3 proto files in the current directory.
>
> user_preferences.proto imports other protos and all are available in the
> same directory.
>
> But, if i try to run this command, it throws an error. - *Imported file
> not found.*
>
>
>
> *protoc --include_imports --descriptor_set_out=/dev/stdout
> user_preferences.proto*
> Here, I am trying to invoke protoc with --descriptor_set_out to parse the
> proto file and convert it into a serialized FileDescriptorSet
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr5A%2Bz3Y40rhair7kC6Kd1gEeGg8zFwoSygHrnD1LBqn4g%40mail.gmail.com.


Re: [protobuf] Protocol message tag had invalid wire type.

2023-02-24 Thread 'Adam Cozzette' via Protocol Buffers
A serialized protocol buffer doesn't include any type information, so
before you can parse one you have to know in advance which type you're
expecting. If you want to be prepared to accept either A or B, then a good
solution is to put both types inside a oneof in a parent message, and then
just parse the parent message normally.

It doesn't matter which protobuf implementation created the .pb file, since
all implementations use the same wire format.

That is true that the Java lite implementation doesn't support reflection
and doesn't include descriptors, so it cannot serialize protos to JSON. If
you can stick to the binary format then that would be ideal since that
format is useable everywhere.

On Thu, Feb 23, 2023 at 5:33 PM ritesh singh  wrote:

> Also does it matter if .pb was created using proto lite and android end.
>
> I believe the lite version doesn't store fields, so converting it to json
> using proto-util won't work and i need to make use of reflection.
>
> On Fri, 24 Feb, 2023, 6:54 am ritesh singh, 
> wrote:
>
>> Thanks Adam. I will give it a shot. I thought of using *protoc*
>> compiler, but what if my proto file contains nested messages
>>
>>
>>
>>
>> *message A {  B b = 1}*
>> *message B {*
>> *}*
>>
>>
>> After running *protoc *on the proto file, it will generate 2 java
>> classes. I won't know which generated class to use against my .pb file, as
>> my plugin is only aware of .pb and .proto file.
>>
>> Please correct me, if am wrong.
>> On Friday, February 24, 2023 at 6:42:05 AM UTC+5:30 Adam Cozzette wrote:
>>
>>> I suspect that your code is getting an error because it's trying to
>>> parse a .proto file as a serialized protocol buffer. (This won't work since
>>> .proto files use a text representation very different from the standard
>>> protobuf binary format.) Probably the best way to fix this problem would be
>>> to invoke protoc with --descriptor_set_out to parse the proto file and
>>> convert it into a serialized FileDescriptorSet. A FileDescriptorSet is just
>>> a protocol buffer, so once you have it in that form you can easily parse it
>>> like you would parse any other serialized proto.
>>>
>>> On Thu, Feb 23, 2023 at 4:59 PM ritesh singh 
>>> wrote:
>>>
 Hello,

 I am working on creating a Android Studio plugin for proto data store.
 Android uses proto-lite, my current approach, i get the .pb file and
 .proto file and use the same in intellij plugin to deserialise it.












 *val psiFile = PsiManager.getInstance(project).findFile(protoFile) val
 protoFileContent = psiFile!!.text val fileDescriptorProto:
 DescriptorProtos.FileDescriptorProto =
 DescriptorProtos.FileDescriptorProto.parseFrom(protoFileContent.byteInputStream())
 val fileDescriptor =
 Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, arrayOfNulls(0))
 val messageDescriptor = fileDescriptor.messageTypes[0] val buffer =
 pbFile.contentsToByteArray() val messageBuilder: DynamicMessage.Builder =
 DynamicMessage.newBuilder(messageDescriptor)
 messageBuilder.mergeFrom(buffer) val message = messageBuilder.build() val
 text: String = TextFormat.printToString(message)*

 Above code is throwing error in parsing step,* Protocol message tag
 had invalid wire type.*

 Thanks in advance.

 --
 You received this message because you are subscribed to the Google
 Groups "Protocol Buffers" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to protobuf+u...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/protobuf/7fe3a019-e846-4792-8d8a-1655a2d93975n%40googlegroups.com
 
 .

>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to protobuf+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/protobuf/5042e4c5-2643-4587-812a-730206f14424n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/CABaCSzEG%2B19VhXjsYJpphbxA%2B3s7mAmUSiDF_Kmkkr5_Y0A%3Dsg%40mail.gmail.com
> 

[protobuf] Better plugin support for cmake builds

2023-02-24 Thread Li He
Hi protobuf community members,

I had an idea about some improvements for the protobuf cmake file 
.
 
It was discussed over a recent merge request 
. 
I agree with Brad King's comment about moving this to the upstream code 
base but before I send it out, just want to get a sense whether I am on the 
right track. Right now, the function generate_protobuf is intended to be 
used like this:

protobuf_generate(
  OUT_VAR helloworld_proto
  PROTOS helloworld.proto
  LANGUAGE cpp
)
protobuf_generate(
  OUT_VAR helloworld_grpc
  PROTOS helloworld.proto
  LANGUAGE grpc
  PLUGIN "protoc-gen-grpc=${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
)

It seems for each grpc proto file, we will need two calls, so I want to 
make it also support

protobuf_generate(
  OUT_VAR helloworld_proto
  PLUGIN_OUT_VAR helloworld_gprc
  PROTOS helloworld.proto
  LANGUAGE cpp
  PLUGIN "protoc-gen-grpc=${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  GENERATE_EXTENSIONS .pb.h .pb.cc .grpc.pb.h .grpc.pb.cc
)

Let me know if this would be a good change to make and I am happy to send 
out a pull request.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/9d44ccc8-3dd4-42bb-b5bd-f71217c7ba57n%40googlegroups.com.


[protobuf] Re: protoc can't import proto file in the same directory

2023-02-24 Thread ritesh singh
Hi Vetch, 

Were you able to fix it?

On Monday, August 8, 2022 at 7:10:04 AM UTC+5:30 Vetch wrote:

> I copied all the files in https://github.com/helium/proto/tree/master/src 
> to my local machine, when i try to generate code for my golang project, 
> protoc throw some error.
>
> protoc --version: libprotoc 3.21.4, downloaded from github
> language i am using: Go
>
> steps to reproduce:
>
> *working path*:
> $ pwd 
> /c/User/Desktop/test/src
>
> *proto files in this path*:
> $ ls 
> blockchain_block.proto 
> blockchain_block_v1.proto 
> blockchain_txn.proto  ..
>
> *protoc cmd i tried*:
>
> $ protoc --go_out=/c/User/Desktop/Helium/hnt/ ./blockchain_block.proto
> $ protoc --proto_path=. --go_out=/c/User/Desktop/Helium/hnt/ 
> ./blockchain_block.proto
> $ protoc --proto_path=/c/User/Desktop/test/src 
> --go_out=/c/User/Desktop/Helium/hnt/ 
> /c/User/Desktop/test/src/blockchain_block.proto
>
> *protoc output:*
>
> blockchain_block_v1.proto:21:12: "blockchain_txn" is not defined. 
> blockchain_block.proto:4:1: Import "blockchain_block_v1.proto" was not 
> found or had errors. blockchain_block.proto:7:17: "blockchain_block_v1" is 
> not defined.
>
> I can compile most proto file in 
> https://github.com/helium/proto/tree/master/src, except for 
> *blockchain_block.proto* and *blockchain_block_v1.proto*. 
> How do i fix this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/c0c44d70-3f92-4ae0-a2e7-c639f82bbb2fn%40googlegroups.com.


[protobuf] Proto File not found while running protoc

2023-02-24 Thread ritesh singh
I have 3 proto files in the current directory.

user_preferences.proto imports other protos and all are available in the 
same directory.

But, if i try to run this command, it throws an error. - *Imported file not 
found.*



*protoc --include_imports --descriptor_set_out=/dev/stdout 
user_preferences.proto*
Here, I am trying to invoke protoc with --descriptor_set_out to parse the 
proto file and convert it into a serialized FileDescriptorSet

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com.