Method: Cod::ProtocolBuffersSerializer#en
- Defined in:
- lib/cod/protocol_buffers_serializer.rb
#en(obj) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cod/protocol_buffers_serializer.rb', line 31 def en(obj) sio = ProtocolBuffers.bin_sio # Assuming that obj is a protocol buffers message object, this should # work: klass_name = obj.class.name buffer = obj.to_s Varint.encode(sio, klass_name.size) sio.write(klass_name) Varint.encode(sio, buffer.size) sio.write(buffer) sio.string end |