/protobuf-pyb

Automatically exported from code.google.com/p/protobuf-pyb

Primary LanguagePython

pyb
---

pyb -- Main interface.

  Load a pyb.DescriptorSet.  Create types.  Then use the types to decode byte
  strings.

  TODO: Need encoding.  Create a type.  Then call encode() on it to create a
  byte string.

For Poly, I think I need another interface.  No types!

  Takes a Dict.
  And then a schema.
  
  db = pyb.DescriptorSet.FromBinary('addressbook.desc.encoded')
  address_book_pb = db.AllTypes()

  address_book_pb.AddressBook.FromDict(
    { person: [
        { name: "Andy",
          email: "andy@foo.com"
          phone: [
            { number: "123-345-5655"
              type: "MOBILE"
            },
            { number: "123-345-5655"
              type: "WORK"
            },
          ]
        },
        { name: "Bob",
          email: "bob@foo.com"
        }
      ]
    })


  # Hm, there already is a ToDict() thing.  Is that what you want?  Maybe better
  # to minimize it.

  a = address_book_pb.AddressBook()
  d = a.ToDict()
  # d is now { "person": }

  The thing is that in Poly I don't care about internal Python types.  It could
  be a simpler interface like:

  desc_set = pyb.DescriptorSet("addressbook.desc.encoded")

  dict = desc_set.decode("address_book.Person", "some binary data")

  encoded = desc_set.encode("address_book.Person", { "foo": 1 })

  Do you need the whole Python type tree?  It might not be that bad I guess.

  Otherwise it calls decoding.DecodePart in the constructor, which does all this
  setaddr BS.  You don't need that.  Just fork decoding.py (again).  And write
  encoding.py.


raw_decode.py -- Decode without a schema.  Move to bin/?

pyb_tool.py -- Command line tool.  Maybe move to bin/


TODO
----

- encoding of messages -- somewhat DONE
  - encoding needs to check REQUIRED fields!  We can create invalid messages now
- enum decoding and encoding 
- Tests: copy golden message from protobuf repository