[protobuf] Re: ShutdownProtobufLibrary documentation unclear for libraries

2018-12-10 Thread prostephano14

MyLibrary is a shared library

On Monday, December 10, 2018 at 8:25:35 PM UTC-8, proste...@gmail.com wrote:
>
> I am trying to call ShutdownProtobufLibrary within my library which uses 
> protobuf
>
> Now, I am worried about this scenario..
>
> MyLibrary: uses protobuf, but does not advertise about it 
>
> ProductUsingMyLibrary: Uses protobuf and MyLibrary
>
> So ProductUsingMyLibrary would use protobuf both explicitly and implicitly 
> due to MyLibrary
>
> In the scenario above, is it safe for MyLibrary to 
> call ShutdownProtobufLibrary during library unloading?
>
> From the documentation alone, it was not very clear
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] ShutdownProtobufLibrary documentation unclear for libraries

2018-12-10 Thread prostephano14
I am trying to call ShutdownProtobufLibrary within my library which uses 
protobuf

Now, I am worried about this scenario..

MyLibrary: uses protobuf, but does not advertise about it 

ProductUsingMyLibrary: Uses protobuf and MyLibrary

So ProductUsingMyLibrary would use protobuf both explicitly and implicitly 
due to MyLibrary

In the scenario above, is it safe for MyLibrary to 
call ShutdownProtobufLibrary during library unloading?

>From the documentation alone, it was not very clear

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Re: packed = true encoding in protobuf

2018-12-10 Thread Josh Humphries
Looks like you create a new person in the loop, so each person has only a
single ID. As Thomas mentioned, if you don't actually have multiple values,
the framing is just overhead.

With a single value, the encoding basically looks like so:

   - *With packed = false*: varint encoded tag, varint encoded value
   - *With packed = true*: varint encoded tag, varint encoded length value
   == 1, varint encoded value

But with multiple IDs per person, it will be smaller. With 10 values, the
encoding basically looks like so:

   - *With packed = false*: (varint encoded tag, varint encoded value) x 10
   - *With packed = true*: varint encoded tag, varint encoded length value
   == 10, (varint encoded value) x 10

The break-even point is ~2 values in the repeated field, since both packed
and unpacked would use 4 varints to represent the pair of values (though
packed may possibly be 1 byte smaller since varint encoded length of 2 will
be only one byte, where as extra varint encoded tag could possibly be >1
byte, depending on the tag value).


*Josh Humphries*
jh...@bluegosling.com


On Mon, Dec 10, 2018 at 4:03 AM  wrote:

> The code i am using is below:
>
> #include 
> #include 
> #include 
> #include "addressbook.pb.h"
>
> #define FILENAME "ashu.pb"
>
> using namespace std;
>
> AddressBook address_book;
>
> int getFileSize()
> {
> ifstream file(FILENAME, ifstream::in | ifstream::binary);
>
> if(!file.is_open())
> {
> return -1;
> }
>
> file.seekg(0, ios::end);
> int fileSize = file.tellg();
> cout << "Size - " << fileSize << endl;
> file.close();
>
> return fileSize;
> }
>
> int main()
> {
> int x,size;
> Person *p = address_book.add_people();
>
> Person::PhoneNumber* phone_number = p->add_phones();
>
> fstream out(FILENAME, ios::out | ios::binary | ios::trunc);
>
> for(int j=0;j<5000;j++)
> {
> p = address_book.add_people();
>
> p->add_id(j);
> }
>
> x = address_book.SerializeToOstream();
> out.close();
>
> size = getFileSize();
> cout << "size " << size << endl;
>
> AddressBook ad1;
> fstream in(FILENAME, ios::in | ios::binary);
> ad1.ParseFromIstream();
>
> return 0;
> }
>
> and i am using only id field of message Person. Is that the reason why i
> end up getting more size with packed.
>
> On Friday, December 7, 2018 at 12:12:04 PM UTC+5:30, ajinsi...@gmail.com
> wrote:
>>
>> I am trying to find out difference in encoded size using packed equal to
>> true and without any packed encoding. I looped a int32 variable 5000 times.
>> With packed = true, i get size as 29876 and without packed encoding, i get
>> size as 24876. I am confused why i get opposite results. As per my
>> understanding, size with packed should be less as compared to non packed.
>> Can anyone please explain what the issue is?
>> My proto file is below for non packed and for packed i modify id filed
>> as; repeated int32 id = 2[packed=true]:
>>
>> syntax = "proto2";
>> message Person {
>>   optional string name = 1;
>>   repeated int32 id = 2;
>>   optional string email = 3;
>>
>>   enum PhoneType {
>> MOBILE = 0;
>> HOME = 1;
>> WORK = 2;
>>   }
>>
>>   message PhoneNumber {
>> optional string number = 1;
>> optional PhoneType type = 2 [default = HOME];
>>   }
>>
>>   repeated PhoneNumber phones = 4;
>> }
>>
>> message AddressBook {
>>   repeated Person people = 1;
>> }
>>
> --
> 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 post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Re: packed = true encoding in protobuf

2018-12-10 Thread ajinsight444
The code i am using is below:

#include 
#include 
#include 
#include "addressbook.pb.h"

#define FILENAME "ashu.pb"

using namespace std;

AddressBook address_book;

int getFileSize()
{
ifstream file(FILENAME, ifstream::in | ifstream::binary);

if(!file.is_open())
{
return -1;
}

file.seekg(0, ios::end);
int fileSize = file.tellg();
cout << "Size - " << fileSize << endl;
file.close();

return fileSize;
}

int main()
{
int x,size;
Person *p = address_book.add_people();
   
Person::PhoneNumber* phone_number = p->add_phones();

fstream out(FILENAME, ios::out | ios::binary | ios::trunc);

for(int j=0;j<5000;j++)
{  
p = address_book.add_people();

p->add_id(j);
}

x = address_book.SerializeToOstream();
out.close();

size = getFileSize();
cout << "size " << size << endl;

AddressBook ad1; 
fstream in(FILENAME, ios::in | ios::binary);
ad1.ParseFromIstream();

return 0;
}

and i am using only id field of message Person. Is that the reason why i 
end up getting more size with packed.

On Friday, December 7, 2018 at 12:12:04 PM UTC+5:30, ajinsi...@gmail.com 
wrote:
>
> I am trying to find out difference in encoded size using packed equal to 
> true and without any packed encoding. I looped a int32 variable 5000 times. 
> With packed = true, i get size as 29876 and without packed encoding, i get 
> size as 24876. I am confused why i get opposite results. As per my 
> understanding, size with packed should be less as compared to non packed. 
> Can anyone please explain what the issue is?
> My proto file is below for non packed and for packed i modify id filed as; 
> repeated int32 id = 2[packed=true]:
>
> syntax = "proto2";
> message Person {
>   optional string name = 1;
>   repeated int32 id = 2;
>   optional string email = 3;
>
>   enum PhoneType {
> MOBILE = 0;
> HOME = 1;
> WORK = 2;
>   }
>
>   message PhoneNumber {
> optional string number = 1;
> optional PhoneType type = 2 [default = HOME];
>   }
>
>   repeated PhoneNumber phones = 4;
> }
>
> message AddressBook {
>   repeated Person people = 1;
> }
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Re: packed = true encoding in protobuf

2018-12-10 Thread ajinsight444


On Friday, December 7, 2018 at 12:12:04 PM UTC+5:30, ajinsi...@gmail.com 
wrote:
>
> I am trying to find out difference in encoded size using packed equal to 
> true and without any packed encoding. I looped a int32 variable 5000 times. 
> With packed = true, i get size as 29876 and without packed encoding, i get 
> size as 24876. I am confused why i get opposite results. As per my 
> understanding, size with packed should be less as compared to non packed. 
> Can anyone please explain what the issue is?
> My proto file is below for non packed and for packed i modify id filed as; 
> repeated int32 id = 2[packed=true]:
>
> syntax = "proto2";
> message Person {
>   optional string name = 1;
>   repeated int32 id = 2;
>   optional string email = 3;
>
>   enum PhoneType {
> MOBILE = 0;
> HOME = 1;
> WORK = 2;
>   }
>
>   message PhoneNumber {
> optional string number = 1;
> optional PhoneType type = 2 [default = HOME];
>   }
>
>   repeated PhoneNumber phones = 4;
> }
>
> message AddressBook {
>   repeated Person people = 1;
> }
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.