Hi Alex,

By default, the client assumes new objects use JSON as the encoding. The
protocol buffers are only used on the wire to encode Riak's protocol. If
you want to use your own protobuffs messages, I suggest two things:

1. Decide on a `content_type` property for each of your data types and be
sure to assign that to each key as you create it. I've used
'application/pb-person' as an example below.
2. Register encoder and decoder functions [1] on the RiakClient object,
like so:

client.set_decoder('application/pb-person', Person.ParseFromString)
client.set_encoder('application/pb-person', lambda x: x.SerializeToString())

[1]
http://riak-python-client.readthedocs.org/en/latest/client.html#serialization

Cheers,


On Mon, Jun 23, 2014 at 9:19 AM, Alex De la rosa <alex.rosa....@gmail.com>
wrote:

> Hi there,
>
> I just installed RIAK 2.0 beta 1 and was playing with the Python library
> using 'pbc' (Protocol Buffers).
>
> test.py
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
> import riak
> client = riak.RiakClient(host ='127.0.0.1', http_port = 8098, pb_port =
> 8087, protocol = 'pbc')
> bucket = client.bucket('people')
>
> key = bucket.new('alex', data={"username":"Alex","age":33})
> key.store()
>
> print bucket.get('alex').encoded_data
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
>
> it works perfectly and it prints {"username": "Alex", "age": 33} as it
> should print.
>
> However, I'm not using a proto file (person.proto) and compiling it into
> binary for Python to use it... something like:
>
> person.proto
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
> message Person {
>   required string username = 1;
>   required int32 age = 2;
> }
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
>
> xxx.py
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
> import person_pb2
> person = person_pb2.Person()
> person.username = "Alex"
> person.age = 33
> data = person.SerializeToString()
>
> --------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------
>
> Am I using the 'pbc' interface wrong? however, on Riak's examples page is
> done also without the "proto" file... I'm a bit confused at the moment as
> it changed the way I normally would use Protocol Buffers.
>
> Thanks,
> Alex
>
> _______________________________________________
> riak-users mailing list
> riak-users@lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>
>


-- 
Sean Cribbs <s...@basho.com>
Software Engineer
Basho Technologies, Inc.
http://basho.com/
_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to