Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Rails から Protobuf を使いたくなった話
Hazumi Ichijo
September 20, 2018
Programming
1
1.3k
Rails から Protobuf を使いたくなった話
銀座Rails#1
https://ginza-rails.connpass.com/event/97820/
Hazumi Ichijo
September 20, 2018
Tweet
Share
More Decks by Hazumi Ichijo
See All by Hazumi Ichijo
bqv速習会
hazumirr
6
3.4k
Protobuf on Rails Tips
hazumirr
1
600
Before Chaos Engineering
hazumirr
1
600
推薦のためのdata pipelineのモニタリングとロギング
hazumirr
3
4.2k
Goサーバをあえて不安定にするパッケージを作った話
hazumirr
1
1k
gRPC-webのここがすごい という話がしたかった
hazumirr
1
1.1k
rake db:test:prepare ができなかった話
hazumirr
2
830
The Go Playgoroundで 外部パッケージ使いたい
hazumirr
1
4.7k
reading rails security guide
hazumirr
0
240
Other Decks in Programming
See All in Programming
ゴーファーくんと辿るプログラミング言語の歴史/history-of-programming-languages-with-gopher
iwasiman
5
3.2k
GoogleI/O2022 LT報告会資料
shinsukefujita1126
0
400
[DevTrends - Jun/2022] Arquitetura baseada em eventos
camilacampos
0
160
【Scrum Fest Osaka 2022】スクラムチームに放り込まれた若手エンジニアの皆さん、どのように技術のキャッチアップをしていくかイメージはついていますか?
miiiki
0
120
Oracle REST Data Service: APEX Office Hours
thatjeffsmith
0
800
開発速度を5倍早くするVSCodeの拡張機能を作った
purp1eeeee
2
160
Meet Swift Regex
usamik26
0
370
Power Automateドリブンのチームマネジメント
hanaseleb
0
190
Java アプリとAWS の良い関係 - AWS でJava アプリを実行する一番簡単な方法教えます / AWS for Javarista
kanamasa
2
1.3k
Reactは何を提供するLibraryなのか?
taro28
3
560
Node.jsデザインパターンを読んで
mmmommm
0
2.8k
データ分析やAIの "運用" について考える
mmorito
0
150
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
85
3.9k
Automating Front-end Workflow
addyosmani
1351
200k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
655
120k
How to name files
jennybc
40
61k
Optimizing for Happiness
mojombo
365
63k
The Invisible Side of Design
smashingmag
290
48k
Raft: Consensus for Rubyists
vanstee
126
5.5k
Building Flexible Design Systems
yeseniaperezcruz
310
34k
Support Driven Design
roundedbygravity
86
8.5k
Unsuck your backbone
ammeep
659
55k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
236
1M
Practical Orchestrator
shlominoach
178
8.6k
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Ͱγϯϓϧʹ ଞͷαʔϏεͱͷίϛϡχέʔγϣϯָ͕ʹ ͕ඞཁ࠷খݶʹ