ProtocolBuffer for Objective-C 运行环境配置

protobuf-3.6 安装(centos7) 官网下载:https://github.com/google/protobufhttps://github.com/google/protobuf/releasesprotobuf-all-3.6.0.tar.gz官网安装手册:https://github.com/google/protobuf/blob/master/src/README.mdyum install autoconf autom... 阅读详情

原文地址:http://blog.youkuaiyun.com/marujunyy/article/details/8875964


1、下载ProtocolBuffer包(2.5版本与下面的object-c插件不兼容,建议下载2.4.1版本的):


            http://code.google.com/p/protobuf/downloads/list

     编译安装(生成的编译器protoc在/usr/local/bin目录下):


           cd protobuf-2.4.1

           ./configure
           make
           make install


2、下载Objective-C compiler for ProtocolBuffer(目前有两种类型的实现)。


    (1)、针对ProtocolBuffer2.2做修改,使最后生成的.proto文件编译器(protoc)支持Objective-C类型的文件输出。
http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers

    (2)、针对ProtocolBuffer2.3推出的plugin模式编写插件,以插件方式支持Objective-C类型的文件输出。
                      https://github.com/booyah/protobuf-objc

        我选用第二种方式,这也是Google推荐的方式。

                       git  clone  https://github.com/booyah/protobuf-objc.git

        进入该目录,并执行(生成的插件protoc-gen-objc在/usr/local/bin/目录下):


                       cd  protobuf-objc

                       ./autogen.sh
                       ./configure
                       make
                       make install


3、测试.proto文件编译


        写一个person.proto文件:

[cpp]  view plain copy
  1. message Person {  
  2.  required string name = 1;  
  3.  required int32 id = 2;  
  4.  optional string email = 3;  
  5.    
  6.  enum PhoneType {  
  7.     MOBILE = 0;  
  8.     HOME = 1;  
  9.     WORK = 2;  
  10.  }  
  11.    
  12.  message PhoneNumber {  
  13.     required string number = 1;  
  14.     optional PhoneType type = 2 [default = HOME];  
  15.  }  
  16.    
  17.  repeated PhoneNumber phone = 4;  
  18. }  


        编译该文件:

                protoc  person.proto   --objc_out=/Output/Directory/   


        protoc会使用该插件编译.proto文件,最终生成两个文件:Person.pb.h 、Person.pb.m(不支持ARC)


        如果工程中使用了ARC ,所以需要使用-fno-objc-arc来标识相关的文件不使用ARC机制:



        这个步骤通过后,说明ProtocoBuffer Compiler for Objective-C可以正常工作了。

4、在Xcode中使用ProtocolBuffer


        将步骤2中protobuf-obj/src/runtime/Classes目录导入到Xcode项目中,导入时,选中”Copy items into destination group‘s folder(if needed)“。

        导入位置选择项目根目录。导入完毕后,项目根目录下将会出现Classes目录,将该目录改名为ProtocolBuffers(注意最后的s): mv Classes ProtocolBuffers

        修改项目属性中”Build Settings-->Search Paths-->Header Search Paths”,将项目根目录“.”添加到头文件搜索路径中去。

        这样ProtocolBuffer for Objective-C的工作环境就配置好了。


5、使用


        1)、将步骤3中编译输出的Person.pb.h 和Person.pb.m添加到项目中


        2)、将Person.pb.h 中的 #import <ProtocolBuffers/ProtocolBuffers.h> 改为#import"ProtocolBuffers/ProtocolBuffers.h"


        3)、在需要使用的地方引入头文件:#import "Person.pb.h"

[cpp]  view plain copy
  1. - (void)viewDidLoad  
  2. {  
  3.     [super viewDidLoad];  
  4.     // Do any additional setup after loading the view, typically from a nib.  
  5.       
  6.     [self writeAndReadProtobuf];  
  7. }  
  8.   
  9. - (void)writeAndReadProtobuf{  
  10.     Person *person = [[[[[Person builder] setName:@"极致"]  
  11.                         setId:1]  
  12.                        setEmail:@"abc@163.com"] build];  
  13.     NSData *data = [person data];  
  14.       
  15.     NSString *docPath = [self applicationDocumentsDirectory];  
  16.     NSString *path = [docPath stringByAppendingFormat:@"/person.data"];  
  17.       
  18.     if ([data writeToFile:path atomically:YES]) {  
  19.         [self readFileWithPath:path];  
  20.     }  
  21. }  
  22.   
  23. - (NSString *)applicationDocumentsDirectory {  
  24.       
  25.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  26.     NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;  
  27.     return basePath;  
  28. }  
  29.   
  30. - (void)readFileWithPath:(NSString *)path {  
  31.       
  32.     NSData *data = [NSData dataWithContentsOfFile:path];  
  33.     Person *person = [Person parseFromData:data];  
  34.       
  35.     if (person) {  
  36.         NSLog(@"\n id %d \n name: %@ \n email: %@ \n",person.id, person.name, person.email);  
  37.     }  
  38. }  
输出打印的结果如下:

              

遇到的问题:


          在执行 ./autogen.sh时出现错误:   
./autogen.sh: line 10: autoreconf: command not found

          

          解决办法:需要安装automake和autoconf:


                      brew install automake

                      brew install autoconf 

brew command not found:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" 


Script used to build Google Protobuf 2.5.0 for use with Xcode 5 / iOS 7. Builds all supported architectures and produces a universal binary static library.


Third-Party Add-ons for Protocol Buffers


【protobuf】protobuf-2.4.1 兼容objective c插件的版本 protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台。google 提供了三种语言的实现:java、c++ 和 python,每一种实现都包含了相应语言的编译器以及库文件。由于它是一种二进制的格式,比使用 xml 进行数据交换快许多。可以把它用于分布式应用之间的数据通信或者异构环境下的数据交换。作为一种效率和兼容性都很优秀的二进制数据传输格式,可以用于诸如网络传输、配置文件、数据存储等诸多领域。 立即下载

相关推荐

服务器基础知识介绍

服务器,不仅仅是一台高性能计算机,更是网络的核心节点,承担着网络服务的责任。然而,相较于普通计算机,服务器对于稳定性、安全性和性能等方面提出了更高的要求,这使得它们在数字化浪潮中傲然独立。在硬件成本结构中,CPU和芯片组占据约50%的成本,内存占15%,外部存储占10%,其余硬件约占25%。服务器的逻辑结构与普通计算机相似,但由于其需要提供高性能计算,对稳定性、可靠性、安全性、可扩展性和可管理性的要求更高。服务器的分类多种多样,根据产品形式可分为塔式服务器、机架服务器、刀片服务器和机柜服务器。

m0_73576645的博客 1882

Object-C编译的Protobuf

因工作需要,要编译Object-C可用的Protocbuf,开始查资料, http://www.cnblogs.com/uniy/archive/2011/12/21/2296405.html 结果执行完 A. 下载Protocol Buffers将下载解压后的文件存放至Applications目录下,进到ProtocolBuffers-2.2.0-Source目录看看会发现 有个src目录...

weixin_30636089的博客 167

告别卡顿!OBS Studio最佳录制参数设置指南(适合游戏/网课/会议场景)

本文提供OBS Studio录制参数优化指南,针对游戏、网课及会议三大场景,详细解析帧率、码率与编码器设置。重点推荐利用硬件编码器(如NVENC)实现游戏录制零卡顿,并分享清晰稳定的网课录制与长时间会议录制配置方案,助你告别视频卡顿与音画不同步问题。

e4f5g6h7的博客 1333

centos7安装protocol buffer

centos7安装protocol buffer 因为搭建go环境需要使用protoc,所以记录一下对于protoc的安装记录: 是用wget下载protobuf包 wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.0/protobuf-all-3.10.0.tar.gz tar zvxf pr...

虹少侠的博客 1157

Codesys电子凸轮实战:从机械替代到虚轴设计的5个关键步骤

本文详细介绍了Codesys电子凸轮技术在运动控制领域的实战应用,从机械替代到虚轴设计的5个关键步骤。通过电子凸轮技术,操作员可以快速调整切割模式,显著提升产线效率。文章还探讨了虚轴架构、CAM表设计、动态耦合技巧及调试避坑指南,为工业自动化领域提供了实用的解决方案。

tech5的博客 767

元数据及数据仓库相关概念

文章目录元数据(metadata)的概念Data about Data定义技术元数据业务元数据总结数据仓库ODS简单的理解为 Operational Data Store, 运营数据仓储 数据整合层(也叫做数据缓冲层)EDW简单理解为 Enterprise Data Warehouse, 企业数据仓库ODS与EDW之间的差异使用角色数据来源数据获取性能和及时性数据架构数据共享能力数据系统提供应用数...

frone的专栏 3137

记一次protobuf编译成objectC过程 For ios开发

相关文档说明: 官方文档:https://grpc.io/docs/tutorials/basic/objective-c.html 阿里云讨论:https://www.aliyun.com/jiaocheng/ios_1410.html?spm=5176.100033.2.8.Ij2Pzr 简书ios-grpc集成:https://www.jianshu.com/p/f33091df088...

Carry_Jey 2334

【Diffusion分割】医学图像分割中去噪扩散技术

扩散模型(DPM)在图像生成方面表现出了卓越的性能,其性能往往优于其他生成模型。自其问世以来,强大的噪声-图像去噪管道已被扩展到各种判别任务中,包括图像分割。在医学成像中,图像往往是大型三维扫描图像,由于内存消耗大、迭代采样过程耗时,使用 DPM 对一幅图像进行分割的效率极低。在这项工作中,我们提出了一种(LDSeg),可在潜空间中执行扩散,用于医学影像分割。我们。潜空间条件扩散不仅能确保对多标签对象进行精确的 n-D 图像分割,还能缓解基于 DPM 的传统分割法的主要潜在问题:(。

qq_43583311的博客 1171

ProtocolBuffer for Objective-C 运行环境配置及使用

一 、前言最近要做一个新的项目需要用到Google的Protocol Buffer,所以最近两天一直在学习这个。在网上看了很多人写的相关博客,发现他们写的配置环境的步骤不尽相同,并且不需要那么复杂,所以就想写一篇最新的文章。 配置环境:mac OS 10.11.1 本文若有叙述错误之处,欢迎指点。二 、Protocol Buffer简介Protocolbuffer(简称Protobuf或PB)

Xcoder_的专栏 828

后摄模块辐射超标整改

某行车记录仪在EMI测试中出现辐射超标问题,通过模块剥离法定位到后摄模块的Ethernet数据线为噪声源。深入检查发现TYPE-C延长线屏蔽层未有效接地,形成辐射泄漏通道。整改措施包括加强屏蔽层360°接地、使用导电布改善连接处屏蔽等,最终使辐射降至EN55032 Class B限值以内。案例揭示了高速信号延长线中屏蔽连续性的重要性,建议设计阶段就重视连接器屏蔽设计和共模干扰抑制。

硬核科技 255

手把手教你完成YOLOv9 PyQt5目标检测界面搭建,实现图片检测、视频检测、摄像头检测,可用于大论文凑工作量或毕设必备,全网最详细教程

目标检测是计算机视觉中的重要任务,广泛应用于安防监控、自动驾驶、智能家居等领域。YOLO系列模型由于其高效的检测速度和较高的准确率,成为目标检测任务的首选算法之一。本项目结合 YOLOv9与 PyQt5,构建了一个图形化界面,便于用户进行目标检测的操作和展示,实现对图片、视频和摄像头的实时目标检测,不仅可以用于大论文的工作量展示,还可以作为毕业设计。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2657

ProtocolBuffer for Objective-C Mac运行环境配置

  上班第4天,上司让我研究Google的Protocol Buffer,对于我这个小白来说这是一大难题。结合了一下网上资料,用了几个小时的时间,终于搞明白了。做个笔记,也当做资料给大家分享一下。   什么是Protocol Buffer?Protocolbuffer(简称Protobuf或PB)是由Google推出的一种数据交换格式,它独立于语言,独立于平台。它是一种二进制格式,转换效率特别快...

weixin_30425949的博客 122

【C2000系列DSP的Bootloader详解】实现过程、流程图与示例代码

C2000 Bootloader 的核心逻辑可概括为 “初始化→选模式→加载程序→校验→跳转” 五步。对于小白来说,无需纠结底层寄存器配置(驱动库已封装),重点理解 “启动流程” 和 “数据传输 + 校验” 的核心思想即可。 通过本文的流程图和示例代码,相信你已经掌握了 C2000 Bootloader 的核心原理。实际开发中,可基于 TI 提供的 Bootloader 示例(C2000Ware 中自带)进行修改,快速适配自己的硬件和应用场景。

昔时扬尘处 371

ProtocolBuffer for Objective-C 运行环境配置[转]

1,下载ProtocolBuffer包,并按照包中根目录下README.txt安装。 http://code.google.com/intl/zh-CN/apis/protocolbuffers/ 当前最新版本2.4.1 最后make install后,会生成编译器protoc,并拷贝到/usr/local/bin目录下。   2,下载Objective-C compiler ...

lcdxwhj2003的专栏 106

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ProtocolBuffer for Objective-C 运行环境配置(真正测试过的)

还未完成验证,只是作为纪录,后续有时间完善 1、下载ProtocolBuffer包(2.5版本与下面的object-c插件不兼容,建议下载2.4.1版本的):              http://code.google.com/intl/zh-CN/apis/protocolbuffers/      编译安装(生成的编译器protoc在/usr/local/bin目

muyu114的专栏 2249

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

上一篇: 适配iOS7开发
下一篇: iOS 后台运行NSTimer
ios_developer
博客等级 码龄14年 1粉丝 4原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值