tnetstring 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tnetstring/version.rb +5 -0
- data/lib/tnetstring.rb +20 -2
- metadata +21 -5
data/lib/tnetstring.rb
CHANGED
@@ -8,12 +8,17 @@ module TNetstring
|
|
8
8
|
value = case payload_type
|
9
9
|
when '#'
|
10
10
|
payload.to_i
|
11
|
-
when '
|
11
|
+
when ','
|
12
12
|
payload
|
13
13
|
when ']'
|
14
14
|
parse_list(payload)
|
15
15
|
when '}'
|
16
16
|
parse_dictionary(payload)
|
17
|
+
when '~'
|
18
|
+
assert payload.length == 0, "Payload must be 0 length for null."
|
19
|
+
nil
|
20
|
+
when '!'
|
21
|
+
parse_boolean(payload)
|
17
22
|
else
|
18
23
|
assert false, "Invalid payload type: #{payload_type}"
|
19
24
|
end
|
@@ -24,10 +29,12 @@ module TNetstring
|
|
24
29
|
assert data, "Invalid data to parse, it's empty."
|
25
30
|
length, extra = data.split(':', 2)
|
26
31
|
length = length.to_i
|
32
|
+
assert length <= 999_999_999, "Data is longer than the specification allows"
|
33
|
+
assert length >= 0, "Data length cannot be negative!"
|
27
34
|
|
28
35
|
payload, extra = extra[0, length], extra[length..-1]
|
29
36
|
assert extra, "No payload type: %s, %s" % [payload, extra]
|
30
|
-
payload_type, remain = extra[0], extra[1..-1]
|
37
|
+
payload_type, remain = extra[0,1], extra[1..-1]
|
31
38
|
|
32
39
|
assert payload.length == length, "Data is wrong length %d vs %d" % [length, payload.length]
|
33
40
|
[payload, payload_type, remain]
|
@@ -68,6 +75,17 @@ module TNetstring
|
|
68
75
|
[key, value, extra]
|
69
76
|
end
|
70
77
|
|
78
|
+
def self.parse_boolean(data)
|
79
|
+
case data
|
80
|
+
when "false"
|
81
|
+
false
|
82
|
+
when "true"
|
83
|
+
true
|
84
|
+
else
|
85
|
+
raise "Boolean wasn't 'true' or 'false'"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
71
89
|
def self.assert(truthy, message)
|
72
90
|
raise message unless truthy
|
73
91
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matt Yoho
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-13 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,22 @@ dependencies:
|
|
32
32
|
version: 2.5.0
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 12
|
47
|
+
version: 1.0.12
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Ruby implementation of the typed netstring specification, a simple data interchange format better suited to low-level network communication than JSON. See http://tnetstrings.org/ for more details.
|
36
51
|
email: mby@mattyoho.com
|
37
52
|
executables: []
|
38
53
|
|
@@ -41,6 +56,7 @@ extensions: []
|
|
41
56
|
extra_rdoc_files: []
|
42
57
|
|
43
58
|
files:
|
59
|
+
- lib/tnetstring/version.rb
|
44
60
|
- lib/tnetstring.rb
|
45
61
|
has_rdoc: true
|
46
62
|
homepage: http://github.com/mattyoho/tnetstring-rb
|
@@ -77,6 +93,6 @@ rubyforge_project:
|
|
77
93
|
rubygems_version: 1.3.7
|
78
94
|
signing_key:
|
79
95
|
specification_version: 3
|
80
|
-
summary: Ruby implementation of
|
96
|
+
summary: Ruby implementation of the typed netstring specification.
|
81
97
|
test_files: []
|
82
98
|
|