-
-
Save hiroeorz/11517270 to your computer and use it in GitHub Desktop.
ツナでもわかるmruby [4回目:バイナリデータフォーマットの実装] ref: http://qiita.com/hiroeorz@github/items/27e0866f493e0e7a65c5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fixed_header(params) | |
message_type = params[:message_type] || 1 | |
dup = params[:dup] || 0 | |
qos = params[:qos] || 0 | |
retain = params[:retain] || 0 | |
remaining_size = params[:remaining_size] || 0 | |
data_1 = (message_type << 4) | (dup << 3) | (qos << 1) | retain | |
data_2 = remaining_size | |
data_1.chr + data_2.chr | |
end | |
fixed_header(message_type:1, dup:0, qos:1, retain:1, remaining_size:20) #=> "\023\024" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment