File: codec.rb

package info (click to toggle)
ruby-stomp 1.4.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: ruby: 8,595; sh: 77; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- encoding: utf-8 -*-

module Stomp
  #
  # == Purpose
  #
  # A general CODEC for STOMP 1.1 header keys and values.
  #
  # See:
  #
  # * http://stomp.github.com/index.html
  #
  # for encode/decode rules.
  #
  class HeaderCodec

    public

    # encode encodes header data per the STOMP 1.1 specification.
    def self.encode(in_string = nil)
      return in_string unless in_string
      ev = Stomp::ENCODE_VALUES # avoid typing below
      os = in_string + ""
      0.step(ev.length-2,2) do |i| # [encoded, decoded]
        os.gsub!(ev[i+1], ev[i])
      end
      os
    end

    # decode decodes header data per the STOMP 1.1 specification.
    def self.decode(in_string = nil)
      return in_string unless in_string
      ev = Stomp::DECODE_VALUES # avoid typing below
      os = in_string + ""
      0.step(ev.length-2,2) do |i| # [encoded, decoded]
        os.gsub!(ev[i], ev[i+1])
      end
      os
    end

  end # of class HeaderCodec

end # of module Stomp