Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rails から Protobuf を使いたくなった話
Search
Hazumi Ichijo
September 20, 2018
Programming
2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rails から Protobuf を使いたくなった話
銀座Rails#1
https://ginza-rails.connpass.com/event/97820/
Hazumi Ichijo
September 20, 2018
More Decks by Hazumi Ichijo
See All by Hazumi Ichijo
RailsとRidgepoleの マイグレを120倍早くする
hazumirr
0
420
CIを整備してメンテナンスを生成AIに任せる
hazumirr
0
1.5k
病院の情報フローを理解して、 予約〜会計の見え方が変わった話
hazumirr
1
1.9k
Rubyのコード削除したい時 僕がやること
hazumirr
0
280
テーブル駆動テストと状態
hazumirr
5
2.2k
オンラインテストしようと思った その日に開始できる環境を目指して
hazumirr
0
1.1k
推薦によるプロダクト改善とマイクロサービスが噛み合った話
hazumirr
2
4.8k
ChatGPTで僕が知っていることまとめ
hazumirr
3
3.1k
プロダクトチームとどう 協業し分析環境を改善するか
hazumirr
2
1.6k
Other Decks in Programming
See All in Programming
Vite+ Unified Toolchain for the Web
naokihaba
0
740
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
800
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
110
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
120
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.3k
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
480
Webフレームワークの ベンチマークについて
yusukebe
0
200
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
160
AIエージェントで 変わるAndroid開発環境
takahirom
2
490
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.8k
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
Featured
See All Featured
Faster Mobile Websites
deanohume
310
32k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
What's in a price? How to price your products and services
michaelherold
247
13k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
The browser strikes back
jonoalderson
0
1.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
It's Worth the Effort
3n
188
29k
How to train your dragon (web standard)
notwaldorf
97
6.7k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Transcript
©2018 Wantedly, Inc. Rails͔ΒProtobufΛ ͍ͨ͘ͳͬͨ Cloud Pub/Sub ͰͷεΩʔϚཧ 2018.9.20 -
@rerost/@hazumirr
©2018 Wantedly, Inc. ࣗݾհ Ұᑍ!IB[VNJSS!SFSPTU 8FC"QQMJDBUJPO&OHJOFFS 3BJMT (P 3FBDUʜ ۴࿏ߴઐஜେֶ8BOUFEMZ
©2018 Wantedly, Inc. ۴࿏ߴઐ
©2018 Wantedly, Inc. 8BOUFEMZ1FPQMF ϦϦʔε ϚΠΫϩαʔϏεʢ(P 3VCZ ʜʣ
8BOUFEMZ7JTJU ϦϦʔε ϞϊϦγοΫͳ3BJMTΞϓϦέʔγϣϯ
©2018 Wantedly, Inc. ืू ϑΟʔυ εΧτ
©2018 Wantedly, Inc.
©2018 Wantedly, Inc. ຖશͯͷεΧτ༻ͷϢʔβʔσʔλΛೖΕ͍ͯ͠Δ ࠩͷσʔλ͚ͩཉ͍͠ WJTJUࣗମͷ։ൃͱผαΠΫϧͰճ͍ͨ͠ σʔλੳ෦ #JH2VFSZͳͲΛѻ͏
©2018 Wantedly, Inc. վળํ๏ ͪΐͬͱͣͭվળ͍ͯ͘͠ ϚΠΫϩαʔϏεʹΓग़͢
©2018 Wantedly, Inc. εΧτͷػೳ ߜΓࠐΈ ਪન Ϣʔβʔใͷදࣔ
ϚΠΫϩαʔϏεʹΓग़ͯ͠ ཧ͍ͨ͠
©2018 Wantedly, Inc. εΧτͷσʔλੳ͢Δਓ
©2018 Wantedly, Inc. ͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ
©2018 Wantedly, Inc. 7JTJUͷ͕͍
©2018 Wantedly, Inc. ͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ ௨ͯ͘͠ΕΔԿ͔
©2018 Wantedly, Inc. $MPVE1VC4VC
©2018 Wantedly, Inc. https://cloud.google.com/pubsub/docs/overview
©2018 Wantedly, Inc. ͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ
©2018 Wantedly, Inc. ϝϦοτ αʔϏε͕ؒૄ݁߹ʹͳΔ σϝϦοτ ૹΔσʔλεΩʔϚͷཧ͕͍͠
©2018 Wantedly, Inc. ͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ
©2018 Wantedly, Inc. ͦ͜Ͱ1SPUPDPM#V⒎FS γϦΞϥΠβʔɾσγϦΞϥΠβʔࣗಈੜ ޓੑ͕͋ΔఔอͨΕΔ ੩తܕ͖ݴޠͰ͏·͘ѻ͑Δ
ࣾͷଞͷνʔϜ͕͍ͬͯͯݟ͕͋Δ
©2018 Wantedly, Inc. ͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ 1SPUPCVG 1SPUPCVG
©2018 Wantedly, Inc. Protocol Buffer
©2018 Wantedly, Inc. syntax = "proto3"; option ruby_package = "Protos::SamplePB";
message User { // ֶྺ message Education { string school_name = 1; } // ৬ྺ message Experience { string company_name = 1; } string user_name = 1; string introduction = 2; int64 age = 3; repeated Education educations = 4; repeated Experience experiences = 5; } TBNQMFQSPUP
©2018 Wantedly, Inc. # Generated by the protocol buffer compiler.
DO NOT EDIT! # source: protos/sample.proto require 'google/protobuf' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "User" do optional :user_name, :string, 1 optional :introduction, :string, 2 optional :age, :int64, 3 repeated :educations, :message, 4, "User.Education" repeated :experiences, :message, 5, "User.Experience" end add_message "User.Education" do optional :school_name, :string, 1 end add_message "User.Experience" do optional :company_name, :string, 1 end end module Protos::SamplePB User = Google::Protobuf::DescriptorPool.generated_pool.lookup("User").msgclass User::Education = Google::Protobuf::DescriptorPool.generated_pool.lookup("User.Education").msgclass User::Experience = Google::Protobuf::DescriptorPool.generated_pool.lookup("User.Experience").msgclass end TBNQMFQCSC
©2018 Wantedly, Inc. def new_sample educations = [ Protos::SamplePB::User::Education.new( school_name:
"۴࿏ߴઐ" ), Protos::SamplePB::User::Education.new( school_name: "ஜେֶ" ), ] experiences = [ Protos::SamplePB::User::Experience.new( company_name: "ΥϯςουϦʔגࣜձࣾ" ), ] Protos::SamplePB::User.new( user_name: 'rerost', introduction: 'δϟεί͔Β110km', educations: educations, experiences: experiences, ) end sample = new_sample puts Protos::SamplePB::User.encode_json(sample) { "userName": "rerost", "introduction": "δϟεί͔Β110km", "educations": [ { "schoolName": "۴࿏ߴઐ" }, { "schoolName": "ஜେֶ" } ], "experiences": [ { "companyName": "ΥϯςουϦʔגࣜձࣾ" } ] }
©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( user_name: 1, # Τϥʔ
user_nameͷܕ͕ҧ͏ͷͰ age: 23, introduction: 'δϟεί͔Β110km', educations: [], experiences: [], ) end sample = new_sample ҧ͏ܕΛೖΕͨ߹ʹ͍ͭͯ
©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new() end sample = new_sample
puts sample.age # 0 ΛೖΕͳ͔ͬͨ߹ʹ͍ͭͯ
©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( age: 23, ) end
sample = new_sample encoded = Protos::SamplePB::User.encode(sample) puts encoded.class # String decoded = Protos::SamplePB::User.decode(encoded) puts decoded.age # 23 CJOBSZͷγϦΞϥΠζσγϦΞϥΠζ
©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( age: 23, ) end
sample = new_sample encoded = Protos::SamplePB::User.encode_json(sample) puts encoded.class # String puts encoded # {"age":23,"educations":[],"experiences":[]} decoded = Protos::SamplePB::User.decode_json(encoded) puts decoded.age # 23 +40/ͷγϦΞϥΠζσγϦΞϥΠζ
©2018 Wantedly, Inc. https://github.com/rerost/sample-protobuf
©2018 Wantedly, Inc. ޓੑʹ͍ͭͯ ࠷ݶཉ͍͠ޓੑɹ ΧϥϜͷՃ ໊લͷมߋ
©2018 Wantedly, Inc. ޓੑʹ͍ͭͯ ࠷ݶཉ͍͠ޓੑɹ ΧϥϜͷՃ ໊લͷมߋ 1SPUPCVGͳΒɾɾɾ
σγϦΞϥΠζෆՄͳΧϥϜແࢹ λάφϯόʔͰࣝผ όΠφϦͳΒ
©2018 Wantedly, Inc. <࠶ܝ>͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ 1SPUPCVG 1SPUPCVG
©2018 Wantedly, Inc. 1SPUPCVGΛ͏͜ͱͰղܾͰ͖ͨɹ σʔλΛ҆ఆͯ͠ΓऔΓͰ͖Δ ੩తܕ͖ݴޠͱ͏·͘ΓͱΓ͕Ͱ͖Δ γϦΞϥΠβʔσγϦΞϥΠβʔ͕ࣗಈੜͰ͖Δ
©2018 Wantedly, Inc. 1SPUPCVGPO1VC4VCͰγϯϓϧʹ ଞͷαʔϏεͱͷίϛϡχέʔγϣϯָ͕ʹ ͕ඞཁ࠷খݶʹ