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
400
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.7k
ChatGPTで僕が知っていることまとめ
hazumirr
3
3.1k
プロダクトチームとどう 協業し分析環境を改善するか
hazumirr
2
1.6k
Other Decks in Programming
See All in Programming
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
150
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
310
dRuby over BLE
makicamel
2
330
ふつうのFeature Flag実践入門
irof
7
3.7k
Inside Stream API
skrb
1
670
AIエージェントの隔離技術の徹底比較
kawayu
0
470
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
OSもどきOS
arkw
0
470
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
740
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
230
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
150
Featured
See All Featured
The Language of Interfaces
destraynor
162
27k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
140
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
We Are The Robots
honzajavorek
0
240
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
720
Automating Front-end Workflow
addyosmani
1370
210k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Leo the Paperboy
mayatellez
7
1.8k
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Ͱγϯϓϧʹ ଞͷαʔϏεͱͷίϛϡχέʔγϣϯָ͕ʹ ͕ඞཁ࠷খݶʹ