<jupyter_start><jupyter_text>protobuf. Installation and Python3 support ++ Protocol Buffers is a way to serialize structured data into a binary stream in a fast and efficient manager.++ Machine communication, RPC(remote procedure calls) 1. First of all $ sudo apt-get install autoconf automake libtool $ wget https://github.com/google/protobuf/releases/tag/v3.5.1$ cd protobuf folder $ ./autogen.sh $ ./configure $ make $ make check $ make install -- Protobuf cannot find shared libraries?++ $ sudo ldconfig Check protoc available for you from command line ++ protoc (standing for Protocol buffers compiler)$ protoc --version OR Install protobuf Make sure you grab the latest version$ curl -OL https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zipUnzip$ unzip protoc-3.2.0-linux-x86_64.zip -d protoc3Move protoc to /usr/local/bin/$ sudo mv protoc3/bin/* /usr/local/bin/Move protoc3/include to /usr/local/include/$ sudo mv protoc3/include/* /usr/local/include/Optional: change owner$ sudo chwon [user] /usr/local/bin/protoc$ sudo chwon -R [user] /usr/local/include/google 2. Protocol Buffers Basics: Python++ Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data. 3. Compiling Your Protocol Buffers ++ $ protoc -I ./SRC_DIR --python_out ./DST_DIR ./SRC_DIR/addressbook.proto  --python_out option - ++ This generates addressbook_pb2.py in your specified destination directory ++ Python protocol buffer compiler doesn't generate your data access code for your directly<jupyter_code># Protocol bufferes are a language-neutral, platform-neutral, extensible mechanism of serializing structured data
# example a person.proto file 
!cat proto_SRC_DIR/addressbook.proto
from proto_DST_DIR import addressbook_pb2

person = addressbook_pb2.Person()
person.name = '<NAME>'
person.id = 20180314
person.email = '<EMAIL>'
person.PhoneNumber.number = '15083000888'
person.PhoneNumber.type = 0

# write the protobuf stream on a binary file on disk 
with open('person.bin', 'wb') as f:
    f.write(person.SerializeToString())

!cat person.bin    

# read the data back to Python 
with open('person.bin', 'rb') as f:
    person = addressbook_pb2.Person()
    person.ParseFromString(f.read())
    print('\nperson.name',person.name)
    print('person.id', person.id)
    print('person.email', person.email)<jupyter_output><NAME>���	<EMAIL>
person.name <NAME>
person.id 20180314
person.email <EMAIL>
{'fraction_non_alphanumeric': 0.1095392077607114, 'fraction_numerical': 0.024252223120452707, 'mean_word_length': 4.676605504587156, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '649758', 'license': 'MIT', 'n_tokens_mistral': 782, 'n_tokens_neox': 737, 'n_words': 246, 'path': 'Protocol Buffer - protobuf.ipynb', 'repo_name': 'Chyi341152/chyi-book', 'size': '2552'}