Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpmckinney/netstring
A netstring parser and emitter
https://github.com/jpmckinney/netstring
Last synced: about 2 months ago
JSON representation
A netstring parser and emitter
- Host: GitHub
- URL: https://github.com/jpmckinney/netstring
- Owner: jpmckinney
- License: mit
- Created: 2015-01-24T18:16:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-23T04:22:22.000Z (over 6 years ago)
- Last Synced: 2024-11-18T01:48:12.292Z (2 months ago)
- Language: Ruby
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Netstring: A netstring parser and emitter
[![Gem Version](https://badge.fury.io/rb/netstring.svg)](https://badge.fury.io/rb/netstring)
[![Build Status](https://secure.travis-ci.org/jpmckinney/netstring.png)](https://travis-ci.org/jpmckinney/netstring)
[![Coverage Status](https://coveralls.io/repos/jpmckinney/netstring/badge.png)](https://coveralls.io/r/jpmckinney/netstring)
[![Code Climate](https://codeclimate.com/github/jpmckinney/netstring.png)](https://codeclimate.com/github/jpmckinney/netstring)See the [netstring](http://cr.yp.to/proto/netstrings.txt) specification for details.
## Usage
```ruby
require "netstring"
```Dump:
```ruby
netstring = Netstring.dump("xyz") # "3:xyz,"
```Load:
```ruby
string = Netstring.load("3:xyz,") # "xyz"
```Get the netstring from which the string was loaded:
```ruby
string.netstring # "3:xyz,"
```Load concatenated netstrings:
```ruby
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:
```ruby
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