[Rprotobuf-commits] r301 - / old pkg pkg/R pkg/man pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 8 09:45:06 CEST 2010


Author: romain
Date: 2010-04-08 09:45:06 +0200 (Thu, 08 Apr 2010)
New Revision: 301

Added:
   old/
   old/Makevars.in
   old/addPerson.R
   old/addPerson.Rd
   old/add_person_R.cpp
   old/addressbook.pb.cc
   old/addressbook.pb.h
   old/clear_person_R.cpp
   old/listPeople.R
   old/listPeople.Rd
   old/list_people_R.cpp
Removed:
   pkg/R/addPerson.R
   pkg/R/listPeople.R
   pkg/man/addPerson.Rd
   pkg/man/listPeople.Rd
   pkg/src/add_person_R.cpp
   pkg/src/clear_person_R.cpp
   pkg/src/list_people_R.cpp
Modified:
   pkg/configure
   pkg/configure.in
   pkg/src/Makevars.in
   pkg/src/rpc_over_http.cpp
Log:
moving old code out of the package

Added: old/Makevars.in
===================================================================
--- old/Makevars.in	                        (rev 0)
+++ old/Makevars.in	2010-04-08 07:45:06 UTC (rev 301)
@@ -0,0 +1,23 @@
+## -*- mode: makefile; -*-
+
+## Configure tells us about locations for
+## both Rcpp (ie libRcpp.so and Rcpp.h) and 
+## ProtoBuf headers and library via the variables
+PKG_CPPFLAGS=		@PKG_CPPFLAGS@
+PKG_LIBS=		@PKG_LIBS@
+
+pkg=			RProtoBuf
+
+all:			addressbook.pb.cc pkglib
+
+addressbook.pb.cc:	../inst/proto/addressbook.proto
+			protoc --cpp_out=. --proto_path=../inst/proto $<
+
+addressbook.pb.o:	addressbook.pb.cc
+			$(CXX) -c $< $(CXXPICFLAGS) $(SHLIB_CXXLDFLAGS) $(PKG_CPPFLAGS) 
+
+## The $(OBJECTS) variable is filled by R CMD ... based on all 
+## .cpp files in this directory, but we need to add addressbook.pb.o
+pkglib:			addressbook.pb.o $(OBJECTS)
+			$(SHLIB_CXXLD) -o $(SHLIB) $^ $(SHLIB_CXXLDFLAGS) $(PKG_LIBS)
+

Added: old/addPerson.R
===================================================================
--- old/addPerson.R	                        (rev 0)
+++ old/addPerson.R	2010-04-08 07:45:06 UTC (rev 301)
@@ -0,0 +1,29 @@
+
+addPerson <- function(filename, id, name, emails, phones) {
+
+    if (missing(filename))
+        filename <- system.file("examples/AddressBookFile", package="RProtoBuf")
+
+    ## call the addPerson function with required parameters
+    resList <- .Call("addPerson",
+                     list("filename"=filename, "id"=id, "name"=name),
+                     emails,
+                     phones,
+                     names(phones),
+                     package="RProtoBuf")
+
+    invisible(resList[[1]])
+}
+
+clearPerson <- function(filename, id) {
+
+    if (missing(filename))
+        filename <- system.file("examples/AddressBookFile", package="RProtoBuf")
+
+    ## call the addPerson function with required parameters
+    resList <- .Call("clearPerson",
+                     list("filename"=filename, "id"=id),
+                     package="RProtoBuf")
+
+    invisible(resList[[1]])
+}

Added: old/addPerson.Rd
===================================================================
--- old/addPerson.Rd	                        (rev 0)
+++ old/addPerson.Rd	2010-04-08 07:45:06 UTC (rev 301)
@@ -0,0 +1,49 @@
+\name{addPerson}
+\alias{addPerson}
+\alias{clearPerson}
+\title{Add or remove another person to the the address book example for ProtoBuf}
+\description{
+  This function provides another simple example for using
+  ProtoBuf generated accessor functions to store ProtoBuf data from R in
+  the \code{addPerson} function. For completeness, \code{clearPerson}
+  also allows to remove a person given an id.
+}
+\usage{
+  addPerson(filename, id, name, emails, phones)
+  clearPerson(filename, id)
+}
+\arguments{
+  \item{filename}{complete path to a binary addressbook written in
+    function built from the addressbook.proto description; an example
+    file is used is no argument is supplied}
+  \item{id}{numeric id of the person record}
+  \item{name}{first and last name as a character string}
+  \item{emails}{character vector of emails addressess, can be zero}
+  \item{phones}{named character vector of phone numbers, can be zero;
+    with names one of 'work', 'home' or 'mobile'}
+}
+\value{A status code of zero is returned on completion..
+}
+\details{
+  This function provides an implementation of the \code{add_person.cc} example
+  provided with the ProtoBuf compiler.
+
+  Protocol Buffers is a serialization format with an interface
+  description language developed by Google. The original Google implementation
+  for C++, Java and Python is available under the BSD license at
+  \url{http://code.google.com/p/protobuf/}. A good description of
+  Protocol Buffers is available at
+  \url{http://en.wikipedia.org/wiki/Protocol_Buffers}. 
+
+  This function is a first attempt of exporting binary data R into 
+  ProtoBuf files.
+}
+\author{Romain Francois and Dirk Eddelbuettel for the R package; Google for Protocal Buffers.}
+\examples{
+\dontrun{
+  addPerson(system.file("examples/AddressBookFile", package="RProtoBuf"),
+            7, "James Bond", "james at bond.com", c("home"="(123) 456-7890", "work"="(222) 333-4455"))
+  clearPerson(system.file("examples/AddressBookFile", package="RProtoBuf"), 3)
+}
+}
+

Added: old/add_person_R.cpp
===================================================================
--- old/add_person_R.cpp	                        (rev 0)
+++ old/add_person_R.cpp	2010-04-08 07:45:06 UTC (rev 301)
@@ -0,0 +1,111 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+
+// add_person_R.cpp -- R wrapper / version for add_person.cc example
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+#include "addressbook.pb.h"
+
+#include <Rcpp.h>		
+
+RcppExport SEXP addPerson(SEXP paramSEXP, SEXP emailsSEXP, 
+			  SEXP phonesSEXP, SEXP typesSEXP) {
+
+    SEXP rl = R_NilValue;
+    char* exceptionMesg = NULL;
+    
+    try {
+
+	RcppParams params(paramSEXP);      // parameter from R based on parms
+	std::string filename = params.getStringValue("filename");
+	std::cout << "File is " << filename << std::endl;
+
+	RcppResultSet rs;
+
+	// Verify that the version of the library that we linked against is
+	// compatible with the version of the headers we compiled against.
+	GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+	tutorial::AddressBook address_book;
+
+	// Read the existing address book.
+	std::fstream input(filename.c_str(), std::ios::in | std::ios::binary);
+	if (!address_book.ParseFromIstream(&input)) {
+	    throw std::range_error("add_people_R.cpp: file " + filename + 
+				   " failed to parse as address book.");
+	}
+
+	tutorial::Person *person = address_book.add_person();
+
+	// Add an address.
+	//PromptForAddress(address_book.add_person());
+	int id = params.getIntValue("id");
+	person->set_id(id);
+	std::cout << "Id is " << id << std::endl;
+	
+	std::string name = params.getStringValue("name");
+	person->set_name(name);
+	std::cout << "Name is " << name << std::endl;
+
+	RcppStringVector emails(emailsSEXP);    // vector of strings
+	for (int i=0; i<emails.size(); i++) {
+	    person->set_email(emails(i));
+	    std::cout << "Email is " << emails(i) << std::endl;
+	}
+
+	RcppStringVector numbers(phonesSEXP); 	// vector of strings
+	RcppStringVector types(typesSEXP);      // vector of strings
+	if (numbers.size() != types.size()) {
+	    throw std::range_error("add_people_R.cpp: phone numbers and types " 
+				   "disagree on length.");
+	}
+
+	for (int i=0; i<numbers.size(); i++) {
+
+	    tutorial::Person::PhoneNumber* phone_number = person->add_phone();
+	    phone_number->set_number(numbers(i));
+	    std::cout << "Nb is " << numbers(i) << std::endl;
+	    
+	    std::string type = types(i);
+	    if (type == "mobile") {
+		phone_number->set_type(tutorial::Person::MOBILE);
+	    } else if (type == "home") {
+		phone_number->set_type(tutorial::Person::HOME);
+	    } else if (type == "work") {
+		phone_number->set_type(tutorial::Person::WORK);
+	    } else {
+		Rf_warning("Unknown phone type.  Using default.");
+	    }
+
+
+	}
+
+	// Write the new address book back to disk.
+	std::fstream output(filename.c_str(), 
+			    std::ios::out | std::ios::trunc | std::ios::binary);
+	if (!address_book.SerializeToOstream(&output)) {
+	    throw std::range_error("add_people_R.cpp: file " + filename + 
+				   " could not be written to for address book.");
+	}
+
+	// Optional:  Delete all global objects allocated by libprotobuf.
+	//google::protobuf::ShutdownProtobufLibrary();
+	
+	rs.add("status", 0);
+    
+        rl = rs.getReturnList();
+
+    } catch(std::exception& ex) {
+        exceptionMesg = copyMessageToR(ex.what());
+    } catch(...) {
+        exceptionMesg = copyMessageToR("unknown reason");
+    }
+  
+    if (exceptionMesg != NULL)
+        Rf_error(exceptionMesg);
+    
+    return rl;
+}

Added: old/addressbook.pb.cc
===================================================================
--- old/addressbook.pb.cc	                        (rev 0)
+++ old/addressbook.pb.cc	2010-04-08 07:45:06 UTC (rev 301)
@@ -0,0 +1,1112 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+
+#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
+#include "addressbook.pb.h"
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/wire_format_lite_inl.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/reflection_ops.h>
+#include <google/protobuf/wire_format.h>
+// @@protoc_insertion_point(includes)
+
+namespace tutorial {
+
+namespace {
+
+const ::google::protobuf::Descriptor* Person_descriptor_ = NULL;
+const ::google::protobuf::internal::GeneratedMessageReflection*
+  Person_reflection_ = NULL;
+const ::google::protobuf::Descriptor* Person_PhoneNumber_descriptor_ = NULL;
+const ::google::protobuf::internal::GeneratedMessageReflection*
+  Person_PhoneNumber_reflection_ = NULL;
+const ::google::protobuf::EnumDescriptor* Person_PhoneType_descriptor_ = NULL;
+const ::google::protobuf::Descriptor* AddressBook_descriptor_ = NULL;
+const ::google::protobuf::internal::GeneratedMessageReflection*
+  AddressBook_reflection_ = NULL;
+const ::google::protobuf::ServiceDescriptor* EchoService_descriptor_ = NULL;
+
+}  // namespace
+
+
+void protobuf_AssignDesc_addressbook_2eproto() {
+  protobuf_AddDesc_addressbook_2eproto();
+  const ::google::protobuf::FileDescriptor* file =
+    ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
+      "addressbook.proto");
+  GOOGLE_CHECK(file != NULL);
+  Person_descriptor_ = file->message_type(0);
+  static const int Person_offsets_[4] = {
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, name_),
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, id_),
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, email_),
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, phone_),
+  };
+  Person_reflection_ =
+    new ::google::protobuf::internal::GeneratedMessageReflection(
+      Person_descriptor_,
+      Person::default_instance_,
+      Person_offsets_,
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, _has_bits_[0]),
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, _unknown_fields_),
+      -1,
+      ::google::protobuf::DescriptorPool::generated_pool(),
+      ::google::protobuf::MessageFactory::generated_factory(),
+      sizeof(Person));
+  Person_PhoneNumber_descriptor_ = Person_descriptor_->nested_type(0);
+  static const int Person_PhoneNumber_offsets_[2] = {
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person_PhoneNumber, number_),
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person_PhoneNumber, type_),
+  };
+  Person_PhoneNumber_reflection_ =
+    new ::google::protobuf::internal::GeneratedMessageReflection(
+      Person_PhoneNumber_descriptor_,
+      Person_PhoneNumber::default_instance_,
+      Person_PhoneNumber_offsets_,
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person_PhoneNumber, _has_bits_[0]),
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person_PhoneNumber, _unknown_fields_),
+      -1,
+      ::google::protobuf::DescriptorPool::generated_pool(),
+      ::google::protobuf::MessageFactory::generated_factory(),
+      sizeof(Person_PhoneNumber));
+  Person_PhoneType_descriptor_ = Person_descriptor_->enum_type(0);
+  AddressBook_descriptor_ = file->message_type(1);
+  static const int AddressBook_offsets_[1] = {
+    GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AddressBook, person_),
+  };
+  AddressBook_reflection_ =
+    new ::google::protobuf::internal::GeneratedMessageReflection(
+      AddressBook_descriptor_,
+      AddressBook::default_instance_,
+      AddressBook_offsets_,
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AddressBook, _has_bits_[0]),
+      GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AddressBook, _unknown_fields_),
+      -1,
+      ::google::protobuf::DescriptorPool::generated_pool(),
+      ::google::protobuf::MessageFactory::generated_factory(),
+      sizeof(AddressBook));
+  EchoService_descriptor_ = file->service(0);
+}
+
+namespace {
+
+GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
+inline void protobuf_AssignDescriptorsOnce() {
+  ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
+                 &protobuf_AssignDesc_addressbook_2eproto);
+}
+
+void protobuf_RegisterTypes(const ::std::string&) {
+  protobuf_AssignDescriptorsOnce();
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
+    Person_descriptor_, &Person::default_instance());
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
+    Person_PhoneNumber_descriptor_, &Person_PhoneNumber::default_instance());
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
+    AddressBook_descriptor_, &AddressBook::default_instance());
+}
+
+}  // namespace
+
+void protobuf_ShutdownFile_addressbook_2eproto() {
+  delete Person::default_instance_;
+  delete Person_reflection_;
+  delete Person_PhoneNumber::default_instance_;
+  delete Person_PhoneNumber_reflection_;
+  delete AddressBook::default_instance_;
+  delete AddressBook_reflection_;
+}
+
+void protobuf_AddDesc_addressbook_2eproto() {
+  static bool already_here = false;
+  if (already_here) return;
+  already_here = true;
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
+    "\n\021addressbook.proto\022\010tutorial\"\332\001\n\006Person"
+    "\022\014\n\004name\030\001 \002(\t\022\n\n\002id\030\002 \002(\005\022\r\n\005email\030\003 \001("
+    "\t\022+\n\005phone\030\004 \003(\0132\034.tutorial.Person.Phone"
+    "Number\032M\n\013PhoneNumber\022\016\n\006number\030\001 \002(\t\022.\n"
+    "\004type\030\002 \001(\0162\032.tutorial.Person.PhoneType:"
+    "\004HOME\"+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\010\n\004HOME\020\001"
+    "\022\010\n\004WORK\020\002\"/\n\013AddressBook\022 \n\006person\030\001 \003("
+    "\0132\020.tutorial.Person29\n\013EchoService\022*\n\004Ec"
+    "ho\022\020.tutorial.Person\032\020.tutorial.PersonB)"
+    "\n\024com.example.tutorialB\021AddressBookProto"
+    "s", 401);
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
+    "addressbook.proto", &protobuf_RegisterTypes);
+  Person::default_instance_ = new Person();
+  Person_PhoneNumber::default_instance_ = new Person_PhoneNumber();
+  AddressBook::default_instance_ = new AddressBook();
+  Person::default_instance_->InitAsDefaultInstance();
+  Person_PhoneNumber::default_instance_->InitAsDefaultInstance();
+  AddressBook::default_instance_->InitAsDefaultInstance();
+  ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_addressbook_2eproto);
+}
+
+// Force AddDescriptors() to be called at static initialization time.
+struct StaticDescriptorInitializer_addressbook_2eproto {
+  StaticDescriptorInitializer_addressbook_2eproto() {
+    protobuf_AddDesc_addressbook_2eproto();
+  }
+} static_descriptor_initializer_addressbook_2eproto_;
+
+
+// ===================================================================
+
+const ::google::protobuf::EnumDescriptor* Person_PhoneType_descriptor() {
+  protobuf_AssignDescriptorsOnce();
+  return Person_PhoneType_descriptor_;
+}
+bool Person_PhoneType_IsValid(int value) {
+  switch(value) {
+    case 0:
+    case 1:
+    case 2:
+      return true;
+    default:
+      return false;
+  }
+}
+
+#ifndef _MSC_VER
+const Person_PhoneType Person::MOBILE;
+const Person_PhoneType Person::HOME;
+const Person_PhoneType Person::WORK;
+const Person_PhoneType Person::PhoneType_MIN;
+const Person_PhoneType Person::PhoneType_MAX;
+const int Person::PhoneType_ARRAYSIZE;
+#endif  // _MSC_VER
+const ::std::string Person_PhoneNumber::_default_number_;
+#ifndef _MSC_VER
+const int Person_PhoneNumber::kNumberFieldNumber;
+const int Person_PhoneNumber::kTypeFieldNumber;
+#endif  // !_MSC_VER
+
+Person_PhoneNumber::Person_PhoneNumber()
+  : ::google::protobuf::Message() {
+  SharedCtor();
+}
+
+void Person_PhoneNumber::InitAsDefaultInstance() {
+}
+
+Person_PhoneNumber::Person_PhoneNumber(const Person_PhoneNumber& from)
+  : ::google::protobuf::Message() {
+  SharedCtor();
+  MergeFrom(from);
+}
+
+void Person_PhoneNumber::SharedCtor() {
+  _cached_size_ = 0;
+  number_ = const_cast< ::std::string*>(&_default_number_);
+  type_ = 1;
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+Person_PhoneNumber::~Person_PhoneNumber() {
+  SharedDtor();
+}
+
+void Person_PhoneNumber::SharedDtor() {
+  if (number_ != &_default_number_) {
+    delete number_;
+  }
+  if (this != default_instance_) {
+  }
+}
+
+void Person_PhoneNumber::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* Person_PhoneNumber::descriptor() {
+  protobuf_AssignDescriptorsOnce();
+  return Person_PhoneNumber_descriptor_;
+}
+
+const Person_PhoneNumber& Person_PhoneNumber::default_instance() {
+  if (default_instance_ == NULL) protobuf_AddDesc_addressbook_2eproto();  return *default_instance_;
+}
+
+Person_PhoneNumber* Person_PhoneNumber::default_instance_ = NULL;
+
+Person_PhoneNumber* Person_PhoneNumber::New() const {
+  return new Person_PhoneNumber;
+}
+
+void Person_PhoneNumber::Clear() {
+  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    if (_has_bit(0)) {
+      if (number_ != &_default_number_) {
+        number_->clear();
+      }
+    }
+    type_ = 1;
+  }
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->Clear();
+}
+
+bool Person_PhoneNumber::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
+  ::google::protobuf::uint32 tag;
+  while ((tag = input->ReadTag()) != 0) {
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // required string number = 1;
+      case 1: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_number()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+            this->number().data(), this->number().length(),
+            ::google::protobuf::internal::WireFormat::PARSE);
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectTag(16)) goto parse_type;
+        break;
+      }
+      
+      // optional .tutorial.Person.PhoneType type = 2 [default = HOME];
+      case 2: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
+         parse_type:
+          int value;
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
+                 input, &value)));
+          if (::tutorial::Person_PhoneType_IsValid(value)) {
+            set_type(static_cast< ::tutorial::Person_PhoneType >(value));
+          } else {
+            mutable_unknown_fields()->AddVarint(2, value);
+          }
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectAtEnd()) return true;
+        break;
+      }
+      
+      default: {
+      handle_uninterpreted:
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+          return true;
+        }
+        DO_(::google::protobuf::internal::WireFormat::SkipField(
+              input, tag, mutable_unknown_fields()));
+        break;
+      }
+    }
+  }
+  return true;
+#undef DO_
+}
+
+void Person_PhoneNumber::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // required string number = 1;
+  if (_has_bit(0)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->number().data(), this->number().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    ::google::protobuf::internal::WireFormatLite::WriteString(
+      1, this->number(), output);
+  }
+  
+  // optional .tutorial.Person.PhoneType type = 2 [default = HOME];
+  if (_has_bit(1)) {
+    ::google::protobuf::internal::WireFormatLite::WriteEnum(
+      2, this->type(), output);
+  }
+  
+  if (!unknown_fields().empty()) {
+    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+        unknown_fields(), output);
+  }
+}
+
+::google::protobuf::uint8* Person_PhoneNumber::SerializeWithCachedSizesToArray(
+    ::google::protobuf::uint8* target) const {
+  // required string number = 1;
+  if (_has_bit(0)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->number().data(), this->number().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        1, this->number(), target);
+  }
+  
+  // optional .tutorial.Person.PhoneType type = 2 [default = HOME];
+  if (_has_bit(1)) {
+    target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
+      2, this->type(), target);
+  }
+  
+  if (!unknown_fields().empty()) {
+    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+        unknown_fields(), target);
+  }
+  return target;
+}
+
+int Person_PhoneNumber::ByteSize() const {
+  int total_size = 0;
+  
+  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    // required string number = 1;
+    if (has_number()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::StringSize(
+          this->number());
+    }
+    
+    // optional .tutorial.Person.PhoneType type = 2 [default = HOME];
+    if (has_type()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::EnumSize(this->type());
+    }
+    
+  }
+  if (!unknown_fields().empty()) {
+    total_size +=
+      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+        unknown_fields());
+  }
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = total_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void Person_PhoneNumber::MergeFrom(const ::google::protobuf::Message& from) {
+  GOOGLE_CHECK_NE(&from, this);
+  const Person_PhoneNumber* source =
+    ::google::protobuf::internal::dynamic_cast_if_available<const Person_PhoneNumber*>(
+      &from);
+  if (source == NULL) {
+    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
+  } else {
+    MergeFrom(*source);
+  }
+}
+
+void Person_PhoneNumber::MergeFrom(const Person_PhoneNumber& from) {
+  GOOGLE_CHECK_NE(&from, this);
+  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    if (from._has_bit(0)) {
+      set_number(from.number());
+    }
+    if (from._has_bit(1)) {
+      set_type(from.type());
+    }
+  }
+  mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+}
+
+void Person_PhoneNumber::CopyFrom(const ::google::protobuf::Message& from) {
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+void Person_PhoneNumber::CopyFrom(const Person_PhoneNumber& from) {
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool Person_PhoneNumber::IsInitialized() const {
+  if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false;
+  
+  return true;
+}
+
+void Person_PhoneNumber::Swap(Person_PhoneNumber* other) {
+  if (other != this) {
+    std::swap(number_, other->number_);
+    std::swap(type_, other->type_);
+    std::swap(_has_bits_[0], other->_has_bits_[0]);
+    _unknown_fields_.Swap(&other->_unknown_fields_);
+    std::swap(_cached_size_, other->_cached_size_);
+  }
+}
+
+::google::protobuf::Metadata Person_PhoneNumber::GetMetadata() const {
+  protobuf_AssignDescriptorsOnce();
+  ::google::protobuf::Metadata metadata;
+  metadata.descriptor = Person_PhoneNumber_descriptor_;
+  metadata.reflection = Person_PhoneNumber_reflection_;
+  return metadata;
+}
+
+
+// -------------------------------------------------------------------
+
+const ::std::string Person::_default_name_;
+const ::std::string Person::_default_email_;
+#ifndef _MSC_VER
+const int Person::kNameFieldNumber;
+const int Person::kIdFieldNumber;
+const int Person::kEmailFieldNumber;
+const int Person::kPhoneFieldNumber;
+#endif  // !_MSC_VER
+
+Person::Person()
+  : ::google::protobuf::Message() {
+  SharedCtor();
+}
+
+void Person::InitAsDefaultInstance() {
+}
+
+Person::Person(const Person& from)
+  : ::google::protobuf::Message() {
+  SharedCtor();
+  MergeFrom(from);
+}
+
+void Person::SharedCtor() {
+  _cached_size_ = 0;
+  name_ = const_cast< ::std::string*>(&_default_name_);
+  id_ = 0;
+  email_ = const_cast< ::std::string*>(&_default_email_);
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+Person::~Person() {
+  SharedDtor();
+}
+
+void Person::SharedDtor() {
+  if (name_ != &_default_name_) {
+    delete name_;
+  }
+  if (email_ != &_default_email_) {
+    delete email_;
+  }
+  if (this != default_instance_) {
+  }
+}
+
+void Person::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* Person::descriptor() {
+  protobuf_AssignDescriptorsOnce();
+  return Person_descriptor_;
+}
+
+const Person& Person::default_instance() {
+  if (default_instance_ == NULL) protobuf_AddDesc_addressbook_2eproto();  return *default_instance_;
+}
+
+Person* Person::default_instance_ = NULL;
+
+Person* Person::New() const {
+  return new Person;
+}
+
+void Person::Clear() {
+  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    if (_has_bit(0)) {
+      if (name_ != &_default_name_) {
+        name_->clear();
+      }
+    }
+    id_ = 0;
+    if (_has_bit(2)) {
+      if (email_ != &_default_email_) {
+        email_->clear();
+      }
+    }
+  }
+  phone_.Clear();
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->Clear();
+}
+
+bool Person::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
+  ::google::protobuf::uint32 tag;
+  while ((tag = input->ReadTag()) != 0) {
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // required string name = 1;
+      case 1: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_name()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+            this->name().data(), this->name().length(),
+            ::google::protobuf::internal::WireFormat::PARSE);
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectTag(16)) goto parse_id;
+        break;
+      }
+      
+      // required int32 id = 2;
+      case 2: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
+         parse_id:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
+                 input, &id_)));
+          _set_bit(1);
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectTag(26)) goto parse_email;
+        break;
+      }
+      
+      // optional string email = 3;
+      case 3: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
+         parse_email:
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_email()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+            this->email().data(), this->email().length(),
+            ::google::protobuf::internal::WireFormat::PARSE);
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectTag(34)) goto parse_phone;
+        break;
+      }
+      
+      // repeated .tutorial.Person.PhoneNumber phone = 4;
+      case 4: {
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
+         parse_phone:
+          DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
+                input, add_phone()));
+        } else {
+          goto handle_uninterpreted;
+        }
+        if (input->ExpectTag(34)) goto parse_phone;
+        if (input->ExpectAtEnd()) return true;
+        break;
+      }
+      
+      default: {
+      handle_uninterpreted:
+        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+          return true;
+        }
+        DO_(::google::protobuf::internal::WireFormat::SkipField(
+              input, tag, mutable_unknown_fields()));
+        break;
+      }
+    }
+  }
+  return true;
+#undef DO_
+}
+
+void Person::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // required string name = 1;
+  if (_has_bit(0)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->name().data(), this->name().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    ::google::protobuf::internal::WireFormatLite::WriteString(
+      1, this->name(), output);
+  }
+  
+  // required int32 id = 2;
+  if (_has_bit(1)) {
+    ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->id(), output);
+  }
+  
+  // optional string email = 3;
+  if (_has_bit(2)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->email().data(), this->email().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    ::google::protobuf::internal::WireFormatLite::WriteString(
+      3, this->email(), output);
+  }
+  
+  // repeated .tutorial.Person.PhoneNumber phone = 4;
+  for (int i = 0; i < this->phone_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
+      4, this->phone(i), output);
+  }
+  
+  if (!unknown_fields().empty()) {
+    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+        unknown_fields(), output);
+  }
+}
+
+::google::protobuf::uint8* Person::SerializeWithCachedSizesToArray(
+    ::google::protobuf::uint8* target) const {
+  // required string name = 1;
+  if (_has_bit(0)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->name().data(), this->name().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        1, this->name(), target);
+  }
+  
+  // required int32 id = 2;
+  if (_has_bit(1)) {
+    target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->id(), target);
+  }
+  
+  // optional string email = 3;
+  if (_has_bit(2)) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
+      this->email().data(), this->email().length(),
+      ::google::protobuf::internal::WireFormat::SERIALIZE);
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        3, this->email(), target);
+  }
+  
+  // repeated .tutorial.Person.PhoneNumber phone = 4;
+  for (int i = 0; i < this->phone_size(); i++) {
+    target = ::google::protobuf::internal::WireFormatLite::
+      WriteMessageNoVirtualToArray(
+        4, this->phone(i), target);
+  }
+  
+  if (!unknown_fields().empty()) {
+    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+        unknown_fields(), target);
+  }
+  return target;
+}
+
+int Person::ByteSize() const {
+  int total_size = 0;
+  
+  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    // required string name = 1;
+    if (has_name()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::StringSize(
+          this->name());
+    }
+    
+    // required int32 id = 2;
+    if (has_id()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(
+          this->id());
+    }
+    
+    // optional string email = 3;
+    if (has_email()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::StringSize(
+          this->email());
+    }
+    
+  }
+  // repeated .tutorial.Person.PhoneNumber phone = 4;
+  total_size += 1 * this->phone_size();
+  for (int i = 0; i < this->phone_size(); i++) {
+    total_size +=
+      ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
+        this->phone(i));
+  }
+  
+  if (!unknown_fields().empty()) {
+    total_size +=
+      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+        unknown_fields());
+  }
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rprotobuf -r 301


More information about the Rprotobuf-commits mailing list