[protobuf] Re: Enum values are siblings of their type, not children of it.

2015-12-28 Thread GoldenBull Chen
Agree. It's a bad design to use old C++ scoping rules for enum values. Even 
C++ itself has introduced enum class in C++11.

在 2015年11月10日星期二 UTC+8上午3:15:35,Teddy Zhang写道:
>
> Sorry to dig this old thread.
> I now one of the solution right now is to put the enum to different proto 
> file and put them into different package. But that doesn't really work if 
> the enums are under the same message.
>
> I would suggest add an option for c/c++, like below:
> enum Foo { 
>   option c_enum_prefix = "eFoo";
>   FIRST = 0; 
>   SECOND = 1; 
>   BOTH = 2; 
> } 
>
> And it will generate enum like below in c/c++:
> enum Foo {
> eFooFIRST = 0,
> eFooSECOND = 1,
> eFooBOTH = 2
> };
>
> This won't affect enum generation in managed language like java/c#, and it 
> won't break backward compatibility (if the option is not specified, 
> fallback to old behavior).
>
> Any comments?
>
> On Friday, August 20, 2010 at 11:12:30 AM UTC-7, alopecoid wrote:
>
>> Hi, 
>>
>> This post is about the fact that protobuf enum values use C++ scoping 
>> rules, meaning that, unlike in Java, enum values are siblings of their 
>> type, not children of it. 
>>
>> Say I have the following contrived message: 
>>
>>   message MyMessage { 
>> enum Foo { 
>>   FIRST = 0; 
>>   SECOND = 1; 
>>   BOTH = 2; 
>> } 
>> required Foo foo = 1; 
>>
>> enum Bar { 
>>   FIRST = 0; 
>>   SECOND = 1; 
>>   BOTH = 2; 
>> } 
>> required Bar bar = 2; 
>>   } 
>>
>> This wouldn't compile because the protobuf compiler recognizes the 
>> fact that for C++, the generated enum values for Foo and Bar would 
>> conflict with each other. 
>>
>> However, for Java, this wouldn't be a problem. I would like to propose 
>> that instead of "punishing" the generated Java code because of C++'s 
>> strange enum behavior (by forcing developers to rename their enum 
>> values even though they don't collide), that instead, the generated C+ 
>> + enum declarations are wrapped in their own nested namespaces? For 
>> example, something like: 
>>
>>   namespace Foo { 
>> enum Enum { 
>>   FIRST = 0; 
>>   SECOND = 1; 
>>   BOTH = 2; 
>> } 
>>   } 
>>
>>   namespace Bar { 
>> enum Enum { 
>>   FIRST = 0; 
>>   SECOND = 1; 
>>   BOTH = 2; 
>> } 
>>   } 
>>
>> At this point, the enum values would be accessed like Foo::FIRST, 
>> Bar::FIRST, etc, which would eliminate the enum value collision 
>> problem altogether, and at the same time make them appear to behave 
>> more like Java's enum scoping rules (which arguably make more sense). 
>>
>> Thoughts? 
>>
>> Thank you.
>
>

-- 
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: Enum values are siblings of their type, not children of it.

2016-01-02 Thread GoldenBull Chen

https://github.com/google/protobuf/issues/1079

在 2010年8月21日星期六 UTC+8上午2:12:30,alopecoid写道:
>
> Hi, 
>
> This post is about the fact that protobuf enum values use C++ scoping 
> rules, meaning that, unlike in Java, enum values are siblings of their 
> type, not children of it. 
>
> Say I have the following contrived message: 
>
>   message MyMessage { 
> enum Foo { 
>   FIRST = 0; 
>   SECOND = 1; 
>   BOTH = 2; 
> } 
> required Foo foo = 1; 
>
> enum Bar { 
>   FIRST = 0; 
>   SECOND = 1; 
>   BOTH = 2; 
> } 
> required Bar bar = 2; 
>   } 
>
> This wouldn't compile because the protobuf compiler recognizes the 
> fact that for C++, the generated enum values for Foo and Bar would 
> conflict with each other. 
>
> However, for Java, this wouldn't be a problem. I would like to propose 
> that instead of "punishing" the generated Java code because of C++'s 
> strange enum behavior (by forcing developers to rename their enum 
> values even though they don't collide), that instead, the generated C+ 
> + enum declarations are wrapped in their own nested namespaces? For 
> example, something like: 
>
>   namespace Foo { 
> enum Enum { 
>   FIRST = 0; 
>   SECOND = 1; 
>   BOTH = 2; 
> } 
>   } 
>
>   namespace Bar { 
> enum Enum { 
>   FIRST = 0; 
>   SECOND = 1; 
>   BOTH = 2; 
> } 
>   } 
>
> At this point, the enum values would be accessed like Foo::FIRST, 
> Bar::FIRST, etc, which would eliminate the enum value collision 
> problem altogether, and at the same time make them appear to behave 
> more like Java's enum scoping rules (which arguably make more sense). 
>
> Thoughts? 
>
> Thank you.

-- 
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] Report a bug

2016-02-20 Thread GoldenBull Chen
Welcome to the new world of C# 6 and VS2015 :)
These new syntax sugars will make your coding life easier.

2016-02-19 20:00 GMT+08:00 :

> Hi,
>
> Protobuf is a nice work which saves me a lot of time.
>
> Through my using, I find a bug as the following :
>
> In some csharp source files such
> as csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs, there are some
> codes like :
>
> throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is
>> not an enum type.");
>
>
> or
>
> string IDescriptor.FullName => Name;
>
>
> It seems that this is due to mistakes in automatic code generation.
>
> These codes cause the csharp project building failed.
>
> This bug first occurs at the submission of
>  72ec33676fd40ccfe719ace162fcf859ae9251bc.
>
> I don't know if this is the right place to report bugs. I'm sorry if not,
> can anyone tell me how to report it.
>
> Thanks.
>
> --
> 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] How can I use C++ Implementation on python3.5 / windows x64?

2016-03-01 Thread GoldenBull Chen
My envrionment:

   - windows 10 x64
   - python 3.5 x64
   - Visual Studio 2015 sp1

Is there any "click-next-next-finish" way to enable the C++ Implementation 
feature or should I build protobuf from source code? If latter, shall I 
build python from source code too?

-- 
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] Is it possible to map an existing db table to an existing protobuf class in sqlalchemy?

2016-04-12 Thread GoldenBull Chen
I have an existing table in Oracle:

CREATE TABLE test_tbl
(
   id NUMBER,
   name   VARCHAR2 (100),
   valNUMBER,
   CONSTRAINT test_tbl_pk PRIMARY KEY (id)
);
-


In python, I tried to load the table using sqlalchemy, and everything works 
fine:

---

# -*- encoding: utf8 -*-

from pbtest_pb2 import *
from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData()

tbl = Table('TEST_TBL', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(100)),
Column('val', Numeric),
)


class TestType2(object):
pass


t = TestType2 # note here, mapped to a custom class

mapper(t, tbl)
engine = create_engine('oracle+cx_oracle://user:passwd@machine/orcl')
Session = sessionmaker(bind=engine)
session = Session()
for i in session.query(t):
print(i.id, i.name, i.val)

---



And here is the corresponding protobuf definition:
-
syntax = "proto3";


message TestType
{
  int32 id = 1;
  string name = 2;
  double val = 3;
}

-



Now I want to re-use the class generated by proto compiler, so I change the 
class used in mapping:
-

t = TestType # now mapped to the generated class

-


Then the piece of code failed with error:

-

Traceback (most recent call last):
  File "D:/test/pbtest.py", line 22, in 
mapper(t, tbl)
  File "", line 2, in mapper
  File "C:\Anaconda2\lib\site-packages\sqlalchemy\orm\mapper.py", line 629, in 
__init__
self._configure_pks()
  File "C:\Anaconda2\lib\site-packages\sqlalchemy\orm\mapper.py", line 1223, in 
_configure_pks
(self, self.mapped_table.description))
sqlalchemy.exc.ArgumentError: Mapper Mapper|TestType|TEST_TBL could not 
assemble any primary key columns for mapped table 'TEST_TBL'
-


Is it possible to reuse the generated class with sqlalchemy?

-- 
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] Is it possible to map an existing db table to an existing protobuf class in sqlalchemy?

2016-04-16 Thread GoldenBull Chen
no, I didn't dive into sqlalchemy to read the source code

2016-04-16 6:41 GMT+08:00 Bo Yang :

> Do you know what kind of interface the custom class needs to provide in
> order to use sqlalchemy?
>
> On Tue, Apr 12, 2016 at 8:57 PM GoldenBull Chen 
> wrote:
>
>> I have an existing table in Oracle:
>> 
>> CREATE TABLE test_tbl
>> (
>>id NUMBER,
>>name   VARCHAR2 (100),
>>valNUMBER,
>>CONSTRAINT test_tbl_pk PRIMARY KEY (id)
>> );
>> -
>>
>>
>> In python, I tried to load the table using sqlalchemy, and everything works 
>> fine:
>>
>> ---
>>
>> # -*- encoding: utf8 -*-
>>
>> from pbtest_pb2 import *
>> from sqlalchemy import *
>> from sqlalchemy.orm import *
>>
>> metadata = MetaData()
>>
>> tbl = Table('TEST_TBL', metadata,
>> Column('id', Integer, primary_key=True),
>> Column('name', String(100)),
>> Column('val', Numeric),
>> )
>>
>>
>> class TestType2(object):
>> pass
>>
>>
>> t = TestType2 # note here, mapped to a custom class
>>
>> mapper(t, tbl)
>> engine = create_engine('oracle+cx_oracle://user:passwd@machine/orcl')
>> Session = sessionmaker(bind=engine)
>> session = Session()
>> for i in session.query(t):
>> print(i.id, i.name, i.val)
>>
>> ---
>>
>>
>>
>> And here is the corresponding protobuf definition:
>> -
>> syntax = "proto3";
>>
>>
>> message TestType
>> {
>>   int32 id = 1;
>>   string name = 2;
>>   double val = 3;
>> }
>>
>> -
>>
>>
>>
>> Now I want to re-use the class generated by proto compiler, so I change
>> the class used in mapping:
>> -
>>
>> t = TestType # now mapped to the generated class
>>
>> -
>>
>>
>> Then the piece of code failed with error:
>>
>> -
>>
>> Traceback (most recent call last):
>>   File "D:/test/pbtest.py", line 22, in 
>> mapper(t, tbl)
>>   File "", line 2, in mapper
>>   File "C:\Anaconda2\lib\site-packages\sqlalchemy\orm\mapper.py", line 629, 
>> in __init__
>> self._configure_pks()
>>   File "C:\Anaconda2\lib\site-packages\sqlalchemy\orm\mapper.py", line 1223, 
>> in _configure_pks
>> (self, self.mapped_table.description))
>> sqlalchemy.exc.ArgumentError: Mapper Mapper|TestType|TEST_TBL could not 
>> assemble any primary key columns for mapped table 'TEST_TBL'
>> -
>>
>>
>> Is it possible to reuse the generated class with sqlalchemy?
>>
>> --
>> 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.