mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-08-26 09:08:34 +00:00
proto
This commit is contained in:
parent
a529ad41c0
commit
b6bd8a4330
BIN
proto_test/__pycache__/addressbook_pb2.cpython-35.pyc
Normal file
BIN
proto_test/__pycache__/addressbook_pb2.cpython-35.pyc
Normal file
Binary file not shown.
63
proto_test/add_people.py
Normal file
63
proto_test/add_people.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
# See README.txt for information and build instructions.
|
||||||
|
|
||||||
|
import addressbook_pb2
|
||||||
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_input # Python 2
|
||||||
|
except NameError:
|
||||||
|
raw_input = input # Python 3
|
||||||
|
|
||||||
|
|
||||||
|
# This function fills in a Person message based on user input.
|
||||||
|
def PromptForAddress(person):
|
||||||
|
person.id = int(raw_input("Enter person ID number: "))
|
||||||
|
person.name = raw_input("Enter name: ")
|
||||||
|
|
||||||
|
email = raw_input("Enter email address (blank for none): ")
|
||||||
|
if email != "":
|
||||||
|
person.email = email
|
||||||
|
|
||||||
|
while True:
|
||||||
|
number = raw_input("Enter a phone number (or leave blank to finish): ")
|
||||||
|
if number == "":
|
||||||
|
break
|
||||||
|
|
||||||
|
phone_number = person.phones.add()
|
||||||
|
phone_number.number = number
|
||||||
|
|
||||||
|
type = raw_input("Is this a mobile, home, or work phone? ")
|
||||||
|
if type == "mobile":
|
||||||
|
phone_number.type = addressbook_pb2.Person.MOBILE
|
||||||
|
elif type == "home":
|
||||||
|
phone_number.type = addressbook_pb2.Person.HOME
|
||||||
|
elif type == "work":
|
||||||
|
phone_number.type = addressbook_pb2.Person.WORK
|
||||||
|
else:
|
||||||
|
print("Unknown phone type; leaving as default value.")
|
||||||
|
|
||||||
|
|
||||||
|
# Main procedure: Reads the entire address book from a file,
|
||||||
|
# adds one person based on user input, then writes it back out to the same
|
||||||
|
# file.
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
address_book = addressbook_pb2.AddressBook()
|
||||||
|
|
||||||
|
# Read the existing address book.
|
||||||
|
try:
|
||||||
|
with open(sys.argv[1], "rb") as f:
|
||||||
|
address_book.ParseFromString(f.read())
|
||||||
|
except IOError:
|
||||||
|
print(sys.argv[1] + ": File not found. Creating a new file.")
|
||||||
|
|
||||||
|
# Add an address.
|
||||||
|
PromptForAddress(address_book.people.add())
|
||||||
|
|
||||||
|
# Write the new address book back to disk.
|
||||||
|
with open(sys.argv[1], "wb") as f:
|
||||||
|
f.write(address_book.SerializeToString())
|
BIN
proto_test/addpeople
Executable file
BIN
proto_test/addpeople
Executable file
Binary file not shown.
133
proto_test/addperson.go
Normal file
133
proto_test/addperson.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
pb "github.com/sibeshkar/vncproxy/proto_test/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func promptForAddress(r io.Reader) (*pb.Person, error) {
|
||||||
|
// A protocol buffer can be created like any struct.
|
||||||
|
p := &pb.Person{}
|
||||||
|
|
||||||
|
rd := bufio.NewReader(r)
|
||||||
|
fmt.Print("Enter person ID number: ")
|
||||||
|
// An int32 field in the .proto file is represented as an int32 field
|
||||||
|
// in the generated Go struct.
|
||||||
|
if _, err := fmt.Fscanf(rd, "%d\n", &p.Id); err != nil {
|
||||||
|
return p, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("Enter name: ")
|
||||||
|
name, err := rd.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return p, err
|
||||||
|
}
|
||||||
|
// A string field in the .proto file results in a string field in Go.
|
||||||
|
// We trim the whitespace because rd.ReadString includes the trailing
|
||||||
|
// newline character in its output.
|
||||||
|
p.Name = strings.TrimSpace(name)
|
||||||
|
|
||||||
|
fmt.Print("Enter email address (blank for none): ")
|
||||||
|
email, err := rd.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return p, err
|
||||||
|
}
|
||||||
|
p.Email = strings.TrimSpace(email)
|
||||||
|
|
||||||
|
for {
|
||||||
|
fmt.Print("Enter a phone number (or leave blank to finish): ")
|
||||||
|
phone, err := rd.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return p, err
|
||||||
|
}
|
||||||
|
phone = strings.TrimSpace(phone)
|
||||||
|
if phone == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// The PhoneNumber message type is nested within the Person
|
||||||
|
// message in the .proto file. This results in a Go struct
|
||||||
|
// named using the name of the parent prefixed to the name of
|
||||||
|
// the nested message. Just as with pb.Person, it can be
|
||||||
|
// created like any other struct.
|
||||||
|
pn := &pb.Person_PhoneNumber{
|
||||||
|
Number: phone,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("Is this a mobile, home, or work phone? ")
|
||||||
|
ptype, err := rd.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return p, err
|
||||||
|
}
|
||||||
|
ptype = strings.TrimSpace(ptype)
|
||||||
|
|
||||||
|
// A proto enum results in a Go constant for each enum value.
|
||||||
|
switch ptype {
|
||||||
|
case "mobile":
|
||||||
|
pn.Type = pb.Person_MOBILE
|
||||||
|
case "home":
|
||||||
|
pn.Type = pb.Person_HOME
|
||||||
|
case "work":
|
||||||
|
pn.Type = pb.Person_WORK
|
||||||
|
default:
|
||||||
|
fmt.Printf("Unknown phone type %q. Using default.\n", ptype)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A repeated proto field maps to a slice field in Go. We can
|
||||||
|
// append to it like any other slice.
|
||||||
|
p.Phones = append(p.Phones, pn)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main reads the entire address book from a file, adds one person based on
|
||||||
|
// user input, then writes it back out to the same file.
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
log.Fatalf("Usage: %s ADDRESS_BOOK_FILE\n", os.Args[0])
|
||||||
|
}
|
||||||
|
fname := os.Args[1]
|
||||||
|
|
||||||
|
// Read the existing address book.
|
||||||
|
in, err := ioutil.ReadFile(fname)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
fmt.Printf("%s: File not found. Creating new file.\n", fname)
|
||||||
|
} else {
|
||||||
|
log.Fatalln("Error reading file:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// [START marshal_proto]
|
||||||
|
book := &pb.AddressBook{}
|
||||||
|
// [START_EXCLUDE]
|
||||||
|
if err := proto.Unmarshal(in, book); err != nil {
|
||||||
|
log.Fatalln("Failed to parse address book:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add an address.
|
||||||
|
addr, err := promptForAddress(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Error with address:", err)
|
||||||
|
}
|
||||||
|
book.People = append(book.People, addr)
|
||||||
|
// [END_EXCLUDE]
|
||||||
|
|
||||||
|
// Write the new address book back to disk.
|
||||||
|
out, err := proto.Marshal(book)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Failed to encode address book:", err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(fname, out, 0644); err != nil {
|
||||||
|
log.Fatalln("Failed to write address book:", err)
|
||||||
|
}
|
||||||
|
// [END marshal_proto]
|
||||||
|
}
|
12
proto_test/addressbook.rbs
Normal file
12
proto_test/addressbook.rbs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
2
|
||||||
|
|
||||||
|
Sibesh Kar˸)sibesh96@gmail.com"
|
||||||
|
|
||||||
|
9829118530
|
||||||
|
2
|
||||||
|
Somesh Burr°ì!someshbur@gmail.com"
|
||||||
|
|
||||||
|
45566543
|
||||||
|
&
|
||||||
|
Subrat PurrŸÝèÉsubrat@sibesh.com
|
217
proto_test/addressbook_pb2.py
Normal file
217
proto_test/addressbook_pb2.py
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
# source: addressbook.proto
|
||||||
|
|
||||||
|
import sys
|
||||||
|
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||||
|
from google.protobuf import descriptor as _descriptor
|
||||||
|
from google.protobuf import message as _message
|
||||||
|
from google.protobuf import reflection as _reflection
|
||||||
|
from google.protobuf import symbol_database as _symbol_database
|
||||||
|
# @@protoc_insertion_point(imports)
|
||||||
|
|
||||||
|
_sym_db = _symbol_database.Default()
|
||||||
|
|
||||||
|
|
||||||
|
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||||
|
name='addressbook.proto',
|
||||||
|
package='protofile',
|
||||||
|
syntax='proto3',
|
||||||
|
serialized_options=_b('\n\024com.example.tutorialB\021AddressBookProtos\252\002$Google.Protobuf.Examples.AddressBook'),
|
||||||
|
serialized_pb=_b('\n\x11\x61\x64\x64ressbook.proto\x12\tprotofile\x1a\x1fgoogle/protobuf/timestamp.proto\"\x89\x02\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x05\x12\r\n\x05\x65mail\x18\x03 \x01(\t\x12-\n\x06phones\x18\x04 \x03(\x0b\x32\x1d.protofile.Person.PhoneNumber\x12\x30\n\x0clast_updated\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1aH\n\x0bPhoneNumber\x12\x0e\n\x06number\x18\x01 \x01(\t\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x1b.protofile.Person.PhoneType\"+\n\tPhoneType\x12\n\n\x06MOBILE\x10\x00\x12\x08\n\x04HOME\x10\x01\x12\x08\n\x04WORK\x10\x02\"0\n\x0b\x41\x64\x64ressBook\x12!\n\x06people\x18\x01 \x03(\x0b\x32\x11.protofile.PersonBP\n\x14\x63om.example.tutorialB\x11\x41\x64\x64ressBookProtos\xaa\x02$Google.Protobuf.Examples.AddressBookb\x06proto3')
|
||||||
|
,
|
||||||
|
dependencies=[google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_PERSON_PHONETYPE = _descriptor.EnumDescriptor(
|
||||||
|
name='PhoneType',
|
||||||
|
full_name='protofile.Person.PhoneType',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
values=[
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='MOBILE', index=0, number=0,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='HOME', index=1, number=1,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='WORK', index=2, number=2,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
],
|
||||||
|
containing_type=None,
|
||||||
|
serialized_options=None,
|
||||||
|
serialized_start=288,
|
||||||
|
serialized_end=331,
|
||||||
|
)
|
||||||
|
_sym_db.RegisterEnumDescriptor(_PERSON_PHONETYPE)
|
||||||
|
|
||||||
|
|
||||||
|
_PERSON_PHONENUMBER = _descriptor.Descriptor(
|
||||||
|
name='PhoneNumber',
|
||||||
|
full_name='protofile.Person.PhoneNumber',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='number', full_name='protofile.Person.PhoneNumber.number', index=0,
|
||||||
|
number=1, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='type', full_name='protofile.Person.PhoneNumber.type', index=1,
|
||||||
|
number=2, type=14, cpp_type=8, label=1,
|
||||||
|
has_default_value=False, default_value=0,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[],
|
||||||
|
enum_types=[
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=214,
|
||||||
|
serialized_end=286,
|
||||||
|
)
|
||||||
|
|
||||||
|
_PERSON = _descriptor.Descriptor(
|
||||||
|
name='Person',
|
||||||
|
full_name='protofile.Person',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='name', full_name='protofile.Person.name', index=0,
|
||||||
|
number=1, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='id', full_name='protofile.Person.id', index=1,
|
||||||
|
number=2, type=5, cpp_type=1, label=1,
|
||||||
|
has_default_value=False, default_value=0,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='email', full_name='protofile.Person.email', index=2,
|
||||||
|
number=3, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='phones', full_name='protofile.Person.phones', index=3,
|
||||||
|
number=4, type=11, cpp_type=10, label=3,
|
||||||
|
has_default_value=False, default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='last_updated', full_name='protofile.Person.last_updated', index=4,
|
||||||
|
number=5, type=11, cpp_type=10, label=1,
|
||||||
|
has_default_value=False, default_value=None,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[_PERSON_PHONENUMBER, ],
|
||||||
|
enum_types=[
|
||||||
|
_PERSON_PHONETYPE,
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=66,
|
||||||
|
serialized_end=331,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_ADDRESSBOOK = _descriptor.Descriptor(
|
||||||
|
name='AddressBook',
|
||||||
|
full_name='protofile.AddressBook',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='people', full_name='protofile.AddressBook.people', index=0,
|
||||||
|
number=1, type=11, cpp_type=10, label=3,
|
||||||
|
has_default_value=False, default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[],
|
||||||
|
enum_types=[
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=333,
|
||||||
|
serialized_end=381,
|
||||||
|
)
|
||||||
|
|
||||||
|
_PERSON_PHONENUMBER.fields_by_name['type'].enum_type = _PERSON_PHONETYPE
|
||||||
|
_PERSON_PHONENUMBER.containing_type = _PERSON
|
||||||
|
_PERSON.fields_by_name['phones'].message_type = _PERSON_PHONENUMBER
|
||||||
|
_PERSON.fields_by_name['last_updated'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP
|
||||||
|
_PERSON_PHONETYPE.containing_type = _PERSON
|
||||||
|
_ADDRESSBOOK.fields_by_name['people'].message_type = _PERSON
|
||||||
|
DESCRIPTOR.message_types_by_name['Person'] = _PERSON
|
||||||
|
DESCRIPTOR.message_types_by_name['AddressBook'] = _ADDRESSBOOK
|
||||||
|
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||||
|
|
||||||
|
Person = _reflection.GeneratedProtocolMessageType('Person', (_message.Message,), dict(
|
||||||
|
|
||||||
|
PhoneNumber = _reflection.GeneratedProtocolMessageType('PhoneNumber', (_message.Message,), dict(
|
||||||
|
DESCRIPTOR = _PERSON_PHONENUMBER,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.Person.PhoneNumber)
|
||||||
|
))
|
||||||
|
,
|
||||||
|
DESCRIPTOR = _PERSON,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.Person)
|
||||||
|
))
|
||||||
|
_sym_db.RegisterMessage(Person)
|
||||||
|
_sym_db.RegisterMessage(Person.PhoneNumber)
|
||||||
|
|
||||||
|
AddressBook = _reflection.GeneratedProtocolMessageType('AddressBook', (_message.Message,), dict(
|
||||||
|
DESCRIPTOR = _ADDRESSBOOK,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.AddressBook)
|
||||||
|
))
|
||||||
|
_sym_db.RegisterMessage(AddressBook)
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTOR._options = None
|
||||||
|
# @@protoc_insertion_point(module_scope)
|
40
proto_test/list_people.py
Normal file
40
proto_test/list_people.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
# See README.txt for information and build instructions.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import addressbook_pb2
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
# Iterates though all people in the AddressBook and prints info about them.
|
||||||
|
def ListPeople(address_book):
|
||||||
|
for person in address_book.people:
|
||||||
|
print("Person ID:", person.id)
|
||||||
|
print(" Name:", person.name)
|
||||||
|
if person.email != "":
|
||||||
|
print(" E-mail address:", person.email)
|
||||||
|
|
||||||
|
for phone_number in person.phones:
|
||||||
|
if phone_number.type == addressbook_pb2.Person.MOBILE:
|
||||||
|
print(" Mobile phone #:", end=" ")
|
||||||
|
elif phone_number.type == addressbook_pb2.Person.HOME:
|
||||||
|
print(" Home phone #:", end=" ")
|
||||||
|
elif phone_number.type == addressbook_pb2.Person.WORK:
|
||||||
|
print(" Work phone #:", end=" ")
|
||||||
|
print(phone_number.number)
|
||||||
|
|
||||||
|
|
||||||
|
# Main procedure: Reads the entire address book from a file and prints all
|
||||||
|
# the information inside.
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
address_book = addressbook_pb2.AddressBook()
|
||||||
|
|
||||||
|
# Read the existing address book.
|
||||||
|
with open(sys.argv[1], "rb") as f:
|
||||||
|
address_book.ParseFromString(f.read())
|
||||||
|
|
||||||
|
ListPeople(address_book)
|
BIN
proto_test/listpeople
Executable file
BIN
proto_test/listpeople
Executable file
Binary file not shown.
61
proto_test/listpeople.go
Normal file
61
proto_test/listpeople.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
pb "github.com/sibeshkar/vncproxy/proto_test/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func writePerson(w io.Writer, p *pb.Person) {
|
||||||
|
fmt.Fprintln(w, "Person ID:", p.Id)
|
||||||
|
fmt.Fprintln(w, " Name:", p.Name)
|
||||||
|
if p.Email != "" {
|
||||||
|
fmt.Fprintln(w, " E-mail address:", p.Email)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pn := range p.Phones {
|
||||||
|
switch pn.Type {
|
||||||
|
case pb.Person_MOBILE:
|
||||||
|
fmt.Fprint(w, " Mobile phone #: ")
|
||||||
|
case pb.Person_HOME:
|
||||||
|
fmt.Fprint(w, " Home phone #: ")
|
||||||
|
case pb.Person_WORK:
|
||||||
|
fmt.Fprint(w, " Work phone #: ")
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, pn.Number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func listPeople(w io.Writer, book *pb.AddressBook) {
|
||||||
|
for _, p := range book.People {
|
||||||
|
writePerson(w, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main reads the entire address book from a file and prints all the
|
||||||
|
// information inside.
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
log.Fatalf("Usage: %s ADDRESS_BOOK_FILE\n", os.Args[0])
|
||||||
|
}
|
||||||
|
fname := os.Args[1]
|
||||||
|
|
||||||
|
// [START unmarshal_proto]
|
||||||
|
// Read the existing address book.
|
||||||
|
in, err := ioutil.ReadFile(fname)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Error reading file:", err)
|
||||||
|
}
|
||||||
|
book := &pb.AddressBook{}
|
||||||
|
if err := proto.Unmarshal(in, book); err != nil {
|
||||||
|
log.Fatalln("Failed to parse address book:", err)
|
||||||
|
}
|
||||||
|
// [END unmarshal_proto]
|
||||||
|
|
||||||
|
listPeople(os.Stdout, book)
|
||||||
|
}
|
245
proto_test/proto/addressbook.pb.go
Normal file
245
proto_test/proto/addressbook.pb.go
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// source: addressbook.proto
|
||||||
|
|
||||||
|
package protofile
|
||||||
|
|
||||||
|
import (
|
||||||
|
fmt "fmt"
|
||||||
|
proto "github.com/golang/protobuf/proto"
|
||||||
|
timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
||||||
|
math "math"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||||
|
|
||||||
|
type Person_PhoneType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
Person_MOBILE Person_PhoneType = 0
|
||||||
|
Person_HOME Person_PhoneType = 1
|
||||||
|
Person_WORK Person_PhoneType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var Person_PhoneType_name = map[int32]string{
|
||||||
|
0: "MOBILE",
|
||||||
|
1: "HOME",
|
||||||
|
2: "WORK",
|
||||||
|
}
|
||||||
|
|
||||||
|
var Person_PhoneType_value = map[string]int32{
|
||||||
|
"MOBILE": 0,
|
||||||
|
"HOME": 1,
|
||||||
|
"WORK": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x Person_PhoneType) String() string {
|
||||||
|
return proto.EnumName(Person_PhoneType_name, int32(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Person_PhoneType) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_1eb1a68c9dd6d429, []int{0, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
// [START messages]
|
||||||
|
type Person struct {
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
Id int32 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
|
Phones []*Person_PhoneNumber `protobuf:"bytes,4,rep,name=phones,proto3" json:"phones,omitempty"`
|
||||||
|
LastUpdated *timestamp.Timestamp `protobuf:"bytes,5,opt,name=last_updated,json=lastUpdated,proto3" json:"last_updated,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) Reset() { *m = Person{} }
|
||||||
|
func (m *Person) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Person) ProtoMessage() {}
|
||||||
|
func (*Person) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_1eb1a68c9dd6d429, []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_Person.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *Person) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_Person.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (m *Person) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_Person.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *Person) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_Person.Size(m)
|
||||||
|
}
|
||||||
|
func (m *Person) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_Person.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_Person proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *Person) GetName() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) GetId() int32 {
|
||||||
|
if m != nil {
|
||||||
|
return m.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) GetEmail() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Email
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) GetPhones() []*Person_PhoneNumber {
|
||||||
|
if m != nil {
|
||||||
|
return m.Phones
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person) GetLastUpdated() *timestamp.Timestamp {
|
||||||
|
if m != nil {
|
||||||
|
return m.LastUpdated
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Person_PhoneNumber struct {
|
||||||
|
Number string `protobuf:"bytes,1,opt,name=number,proto3" json:"number,omitempty"`
|
||||||
|
Type Person_PhoneType `protobuf:"varint,2,opt,name=type,proto3,enum=protofile.Person_PhoneType" json:"type,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person_PhoneNumber) Reset() { *m = Person_PhoneNumber{} }
|
||||||
|
func (m *Person_PhoneNumber) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*Person_PhoneNumber) ProtoMessage() {}
|
||||||
|
func (*Person_PhoneNumber) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_1eb1a68c9dd6d429, []int{0, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person_PhoneNumber) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_Person_PhoneNumber.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *Person_PhoneNumber) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_Person_PhoneNumber.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (m *Person_PhoneNumber) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_Person_PhoneNumber.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *Person_PhoneNumber) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_Person_PhoneNumber.Size(m)
|
||||||
|
}
|
||||||
|
func (m *Person_PhoneNumber) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_Person_PhoneNumber.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_Person_PhoneNumber proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *Person_PhoneNumber) GetNumber() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Number
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Person_PhoneNumber) GetType() Person_PhoneType {
|
||||||
|
if m != nil {
|
||||||
|
return m.Type
|
||||||
|
}
|
||||||
|
return Person_MOBILE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Our address book file is just one of these.
|
||||||
|
type AddressBook struct {
|
||||||
|
People []*Person `protobuf:"bytes,1,rep,name=people,proto3" json:"people,omitempty"`
|
||||||
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
|
XXX_unrecognized []byte `json:"-"`
|
||||||
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *AddressBook) Reset() { *m = AddressBook{} }
|
||||||
|
func (m *AddressBook) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*AddressBook) ProtoMessage() {}
|
||||||
|
func (*AddressBook) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_1eb1a68c9dd6d429, []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *AddressBook) XXX_Unmarshal(b []byte) error {
|
||||||
|
return xxx_messageInfo_AddressBook.Unmarshal(m, b)
|
||||||
|
}
|
||||||
|
func (m *AddressBook) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
return xxx_messageInfo_AddressBook.Marshal(b, m, deterministic)
|
||||||
|
}
|
||||||
|
func (m *AddressBook) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_AddressBook.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *AddressBook) XXX_Size() int {
|
||||||
|
return xxx_messageInfo_AddressBook.Size(m)
|
||||||
|
}
|
||||||
|
func (m *AddressBook) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_AddressBook.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_AddressBook proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *AddressBook) GetPeople() []*Person {
|
||||||
|
if m != nil {
|
||||||
|
return m.People
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterEnum("protofile.Person_PhoneType", Person_PhoneType_name, Person_PhoneType_value)
|
||||||
|
proto.RegisterType((*Person)(nil), "protofile.Person")
|
||||||
|
proto.RegisterType((*Person_PhoneNumber)(nil), "protofile.Person.PhoneNumber")
|
||||||
|
proto.RegisterType((*AddressBook)(nil), "protofile.AddressBook")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("addressbook.proto", fileDescriptor_1eb1a68c9dd6d429) }
|
||||||
|
|
||||||
|
var fileDescriptor_1eb1a68c9dd6d429 = []byte{
|
||||||
|
// 357 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xc1, 0x4a, 0xf3, 0x40,
|
||||||
|
0x10, 0xc7, 0xbf, 0xa4, 0x69, 0xf8, 0x3a, 0x91, 0xd2, 0x2e, 0x45, 0x42, 0x45, 0x0c, 0xc5, 0x43,
|
||||||
|
0x44, 0xd8, 0x42, 0x45, 0xf0, 0xe2, 0xc1, 0x40, 0x51, 0xd1, 0xda, 0x10, 0xaa, 0x1e, 0x65, 0x63,
|
||||||
|
0xb6, 0x35, 0x34, 0xc9, 0x2e, 0xd9, 0x0d, 0xd8, 0x57, 0xf2, 0x1d, 0x7c, 0x37, 0xc9, 0x6e, 0x5a,
|
||||||
|
0x0a, 0xe2, 0x29, 0x33, 0x93, 0xdf, 0xcc, 0xfc, 0xe7, 0xbf, 0xd0, 0x27, 0x49, 0x52, 0x52, 0x21,
|
||||||
|
0x62, 0xc6, 0xd6, 0x98, 0x97, 0x4c, 0x32, 0xd4, 0x51, 0x9f, 0x65, 0x9a, 0xd1, 0xe1, 0xc9, 0x8a,
|
||||||
|
0xb1, 0x55, 0x46, 0xc7, 0xaa, 0x12, 0x57, 0xcb, 0xb1, 0x4c, 0x73, 0x2a, 0x24, 0xc9, 0xb9, 0x66,
|
||||||
|
0x47, 0xdf, 0x26, 0xd8, 0x21, 0x2d, 0x05, 0x2b, 0x10, 0x02, 0xab, 0x20, 0x39, 0x75, 0x0d, 0xcf,
|
||||||
|
0xf0, 0x3b, 0x91, 0x8a, 0x51, 0x17, 0xcc, 0x34, 0x71, 0x4d, 0xcf, 0xf0, 0xdb, 0x91, 0x99, 0x26,
|
||||||
|
0x68, 0x00, 0x6d, 0x9a, 0x93, 0x34, 0x73, 0x5b, 0x0a, 0xd2, 0x09, 0xba, 0x04, 0x9b, 0x7f, 0xb0,
|
||||||
|
0x82, 0x0a, 0xd7, 0xf2, 0x5a, 0xbe, 0x33, 0x39, 0xc6, 0x3b, 0x05, 0x58, 0x0f, 0xc7, 0x61, 0xfd,
|
||||||
|
0xff, 0xa9, 0xca, 0x63, 0x5a, 0x46, 0x0d, 0x8c, 0xae, 0xe1, 0x20, 0x23, 0x42, 0xbe, 0x55, 0x3c,
|
||||||
|
0x21, 0x92, 0x26, 0x6e, 0xdb, 0x33, 0x7c, 0x67, 0x32, 0xc4, 0x5a, 0x33, 0xde, 0x6a, 0xc6, 0x8b,
|
||||||
|
0xad, 0xe6, 0xc8, 0xa9, 0xf9, 0x67, 0x8d, 0x0f, 0x5f, 0xc0, 0xd9, 0x9b, 0x8a, 0x0e, 0xc1, 0x2e,
|
||||||
|
0x54, 0xd4, 0x1c, 0xd0, 0x64, 0x68, 0x0c, 0x96, 0xdc, 0x70, 0xaa, 0x8e, 0xe8, 0x4e, 0x8e, 0xfe,
|
||||||
|
0x90, 0xb6, 0xd8, 0x70, 0x1a, 0x29, 0x70, 0x74, 0x0e, 0x9d, 0x5d, 0x09, 0x01, 0xd8, 0xb3, 0x79,
|
||||||
|
0x70, 0xff, 0x38, 0xed, 0xfd, 0x43, 0xff, 0xc1, 0xba, 0x9b, 0xcf, 0xa6, 0x3d, 0xa3, 0x8e, 0x5e,
|
||||||
|
0xe7, 0xd1, 0x43, 0xcf, 0x1c, 0x5d, 0x81, 0x73, 0xa3, 0x1f, 0x20, 0x60, 0x6c, 0x8d, 0xce, 0xc0,
|
||||||
|
0xe6, 0x94, 0xf1, 0xac, 0x76, 0xb1, 0x76, 0xa2, 0xff, 0x6b, 0x5d, 0xd4, 0x00, 0x41, 0x08, 0x83,
|
||||||
|
0x77, 0x96, 0x63, 0xfa, 0x49, 0x72, 0x9e, 0x51, 0x2c, 0x2b, 0xc9, 0xca, 0x94, 0x64, 0x41, 0x7f,
|
||||||
|
0x6f, 0x5e, 0x58, 0x37, 0x8b, 0x2f, 0xf3, 0xf4, 0x56, 0x5b, 0x12, 0x6e, 0x2d, 0x99, 0xea, 0x2e,
|
||||||
|
0x81, 0xf7, 0xe0, 0xd8, 0x56, 0xbb, 0x2e, 0x7e, 0x02, 0x00, 0x00, 0xff, 0xff, 0x7a, 0xb3, 0x64,
|
||||||
|
0x22, 0x13, 0x02, 0x00, 0x00,
|
||||||
|
}
|
51
proto_test/proto/addressbook.proto
Normal file
51
proto_test/proto/addressbook.proto
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// See README.txt for information and build instructions.
|
||||||
|
//
|
||||||
|
// Note: START and END tags are used in comments to define sections used in
|
||||||
|
// tutorials. They are not part of the syntax for Protocol Buffers.
|
||||||
|
//
|
||||||
|
// To get an in-depth walkthrough of this file and the related examples, see:
|
||||||
|
// https://developers.google.com/protocol-buffers/docs/tutorials
|
||||||
|
|
||||||
|
// [START declaration]
|
||||||
|
syntax = "proto3";
|
||||||
|
package protofile;
|
||||||
|
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
// [END declaration]
|
||||||
|
|
||||||
|
// [START java_declaration]
|
||||||
|
option java_package = "com.example.tutorial";
|
||||||
|
option java_outer_classname = "AddressBookProtos";
|
||||||
|
// [END java_declaration]
|
||||||
|
|
||||||
|
// [START csharp_declaration]
|
||||||
|
option csharp_namespace = "Google.Protobuf.Examples.AddressBook";
|
||||||
|
// [END csharp_declaration]
|
||||||
|
|
||||||
|
// [START messages]
|
||||||
|
message Person {
|
||||||
|
string name = 1;
|
||||||
|
int32 id = 2; // Unique ID number for this person.
|
||||||
|
string email = 3;
|
||||||
|
|
||||||
|
enum PhoneType {
|
||||||
|
MOBILE = 0;
|
||||||
|
HOME = 1;
|
||||||
|
WORK = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message PhoneNumber {
|
||||||
|
string number = 1;
|
||||||
|
PhoneType type = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
repeated PhoneNumber phones = 4;
|
||||||
|
|
||||||
|
google.protobuf.Timestamp last_updated = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Our address book file is just one of these.
|
||||||
|
message AddressBook {
|
||||||
|
repeated Person people = 1;
|
||||||
|
}
|
||||||
|
// [END messages]
|
217
proto_test/proto/addressbook_pb2.py
Normal file
217
proto_test/proto/addressbook_pb2.py
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
# source: addressbook.proto
|
||||||
|
|
||||||
|
import sys
|
||||||
|
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||||
|
from google.protobuf import descriptor as _descriptor
|
||||||
|
from google.protobuf import message as _message
|
||||||
|
from google.protobuf import reflection as _reflection
|
||||||
|
from google.protobuf import symbol_database as _symbol_database
|
||||||
|
# @@protoc_insertion_point(imports)
|
||||||
|
|
||||||
|
_sym_db = _symbol_database.Default()
|
||||||
|
|
||||||
|
|
||||||
|
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||||
|
name='addressbook.proto',
|
||||||
|
package='protofile',
|
||||||
|
syntax='proto3',
|
||||||
|
serialized_options=_b('\n\024com.example.tutorialB\021AddressBookProtos\252\002$Google.Protobuf.Examples.AddressBook'),
|
||||||
|
serialized_pb=_b('\n\x11\x61\x64\x64ressbook.proto\x12\tprotofile\x1a\x1fgoogle/protobuf/timestamp.proto\"\x89\x02\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x05\x12\r\n\x05\x65mail\x18\x03 \x01(\t\x12-\n\x06phones\x18\x04 \x03(\x0b\x32\x1d.protofile.Person.PhoneNumber\x12\x30\n\x0clast_updated\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1aH\n\x0bPhoneNumber\x12\x0e\n\x06number\x18\x01 \x01(\t\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x1b.protofile.Person.PhoneType\"+\n\tPhoneType\x12\n\n\x06MOBILE\x10\x00\x12\x08\n\x04HOME\x10\x01\x12\x08\n\x04WORK\x10\x02\"0\n\x0b\x41\x64\x64ressBook\x12!\n\x06people\x18\x01 \x03(\x0b\x32\x11.protofile.PersonBP\n\x14\x63om.example.tutorialB\x11\x41\x64\x64ressBookProtos\xaa\x02$Google.Protobuf.Examples.AddressBookb\x06proto3')
|
||||||
|
,
|
||||||
|
dependencies=[google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_PERSON_PHONETYPE = _descriptor.EnumDescriptor(
|
||||||
|
name='PhoneType',
|
||||||
|
full_name='protofile.Person.PhoneType',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
values=[
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='MOBILE', index=0, number=0,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='HOME', index=1, number=1,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
_descriptor.EnumValueDescriptor(
|
||||||
|
name='WORK', index=2, number=2,
|
||||||
|
serialized_options=None,
|
||||||
|
type=None),
|
||||||
|
],
|
||||||
|
containing_type=None,
|
||||||
|
serialized_options=None,
|
||||||
|
serialized_start=288,
|
||||||
|
serialized_end=331,
|
||||||
|
)
|
||||||
|
_sym_db.RegisterEnumDescriptor(_PERSON_PHONETYPE)
|
||||||
|
|
||||||
|
|
||||||
|
_PERSON_PHONENUMBER = _descriptor.Descriptor(
|
||||||
|
name='PhoneNumber',
|
||||||
|
full_name='protofile.Person.PhoneNumber',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='number', full_name='protofile.Person.PhoneNumber.number', index=0,
|
||||||
|
number=1, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='type', full_name='protofile.Person.PhoneNumber.type', index=1,
|
||||||
|
number=2, type=14, cpp_type=8, label=1,
|
||||||
|
has_default_value=False, default_value=0,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[],
|
||||||
|
enum_types=[
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=214,
|
||||||
|
serialized_end=286,
|
||||||
|
)
|
||||||
|
|
||||||
|
_PERSON = _descriptor.Descriptor(
|
||||||
|
name='Person',
|
||||||
|
full_name='protofile.Person',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='name', full_name='protofile.Person.name', index=0,
|
||||||
|
number=1, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='id', full_name='protofile.Person.id', index=1,
|
||||||
|
number=2, type=5, cpp_type=1, label=1,
|
||||||
|
has_default_value=False, default_value=0,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='email', full_name='protofile.Person.email', index=2,
|
||||||
|
number=3, type=9, cpp_type=9, label=1,
|
||||||
|
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='phones', full_name='protofile.Person.phones', index=3,
|
||||||
|
number=4, type=11, cpp_type=10, label=3,
|
||||||
|
has_default_value=False, default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='last_updated', full_name='protofile.Person.last_updated', index=4,
|
||||||
|
number=5, type=11, cpp_type=10, label=1,
|
||||||
|
has_default_value=False, default_value=None,
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[_PERSON_PHONENUMBER, ],
|
||||||
|
enum_types=[
|
||||||
|
_PERSON_PHONETYPE,
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=66,
|
||||||
|
serialized_end=331,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_ADDRESSBOOK = _descriptor.Descriptor(
|
||||||
|
name='AddressBook',
|
||||||
|
full_name='protofile.AddressBook',
|
||||||
|
filename=None,
|
||||||
|
file=DESCRIPTOR,
|
||||||
|
containing_type=None,
|
||||||
|
fields=[
|
||||||
|
_descriptor.FieldDescriptor(
|
||||||
|
name='people', full_name='protofile.AddressBook.people', index=0,
|
||||||
|
number=1, type=11, cpp_type=10, label=3,
|
||||||
|
has_default_value=False, default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
serialized_options=None, file=DESCRIPTOR),
|
||||||
|
],
|
||||||
|
extensions=[
|
||||||
|
],
|
||||||
|
nested_types=[],
|
||||||
|
enum_types=[
|
||||||
|
],
|
||||||
|
serialized_options=None,
|
||||||
|
is_extendable=False,
|
||||||
|
syntax='proto3',
|
||||||
|
extension_ranges=[],
|
||||||
|
oneofs=[
|
||||||
|
],
|
||||||
|
serialized_start=333,
|
||||||
|
serialized_end=381,
|
||||||
|
)
|
||||||
|
|
||||||
|
_PERSON_PHONENUMBER.fields_by_name['type'].enum_type = _PERSON_PHONETYPE
|
||||||
|
_PERSON_PHONENUMBER.containing_type = _PERSON
|
||||||
|
_PERSON.fields_by_name['phones'].message_type = _PERSON_PHONENUMBER
|
||||||
|
_PERSON.fields_by_name['last_updated'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP
|
||||||
|
_PERSON_PHONETYPE.containing_type = _PERSON
|
||||||
|
_ADDRESSBOOK.fields_by_name['people'].message_type = _PERSON
|
||||||
|
DESCRIPTOR.message_types_by_name['Person'] = _PERSON
|
||||||
|
DESCRIPTOR.message_types_by_name['AddressBook'] = _ADDRESSBOOK
|
||||||
|
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||||
|
|
||||||
|
Person = _reflection.GeneratedProtocolMessageType('Person', (_message.Message,), dict(
|
||||||
|
|
||||||
|
PhoneNumber = _reflection.GeneratedProtocolMessageType('PhoneNumber', (_message.Message,), dict(
|
||||||
|
DESCRIPTOR = _PERSON_PHONENUMBER,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.Person.PhoneNumber)
|
||||||
|
))
|
||||||
|
,
|
||||||
|
DESCRIPTOR = _PERSON,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.Person)
|
||||||
|
))
|
||||||
|
_sym_db.RegisterMessage(Person)
|
||||||
|
_sym_db.RegisterMessage(Person.PhoneNumber)
|
||||||
|
|
||||||
|
AddressBook = _reflection.GeneratedProtocolMessageType('AddressBook', (_message.Message,), dict(
|
||||||
|
DESCRIPTOR = _ADDRESSBOOK,
|
||||||
|
__module__ = 'addressbook_pb2'
|
||||||
|
# @@protoc_insertion_point(class_scope:protofile.AddressBook)
|
||||||
|
))
|
||||||
|
_sym_db.RegisterMessage(AddressBook)
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTOR._options = None
|
||||||
|
# @@protoc_insertion_point(module_scope)
|
Loading…
Reference in New Issue
Block a user