… | |
… | |
198 | =cut |
198 | =cut |
199 | |
199 | |
200 | sub encode_msg($@) { |
200 | sub encode_msg($@) { |
201 | my ($self, @args) = @_; |
201 | my ($self, @args) = @_; |
202 | my $msg = Net::Knuddels::encode join "\0", @args; |
202 | my $msg = Net::Knuddels::encode join "\0", @args; |
|
|
203 | my $len = (length $msg) - 1; |
|
|
204 | |
|
|
205 | if ($len < 0x80) { |
|
|
206 | (chr $len) . $msg |
|
|
207 | } else { |
|
|
208 | (chr 0x80 | 0x40 | ($len & 0x1f)) |
|
|
209 | . (chr +($len >> 5) % 0xff) |
|
|
210 | . (chr +($len >> 13) % 0xff) |
|
|
211 | . $msg |
|
|
212 | } |
203 | } |
213 | } |
204 | |
214 | |
205 | =item $protocol->register ($type => $callback) |
215 | =item $protocol->register ($type => $callback) |
206 | |
216 | |
207 | Register a callback for events of type C<$type>, which is either the name |
217 | Register a callback for events of type C<$type>, which is either the name |