Netstring: A netstring parser and emitter
See the netstring specification for details.
Usage
require "netstring"
Dump:
netstring = Netstring.dump("xyz") # "3:xyz,"
Load:
string = Netstring.load("3:xyz,") # "xyz"
Get the netstring from which the string was loaded:
string.netstring # "3:xyz,"
Load concatenated netstrings:
netstring = "1:x,3:xyz,"
string1 = Netstring.load(netstring1) # "x"
offset = string1.netstring.size
netstring = netstring[offset..-1]
string2 = Netstring.load(netstring) # "xyz"
Load concatenated netstrings in a loop:
netstring = "1:x,3:xyz,"
strings = []
until netstring.empty?
strings << Netstring.load(netstring)
netstring = netstring[strings.last.netstring.size..-1]
end
Copyright (c) 2014 James McKinney, released under the MIT license