class Netstring

Overview

The primary namespace for netstring.cr.

Defined in:

netstring.cr

Constant Summary

NETSTRING_MAX = 999999999_u32

The default maximum netstring size, taken from the reference implementation.

VERSION = "0.1.0"

The current version of netstring.cr.

Class Method Summary

Instance Method Summary

Class Method Detail

def self.parse(input : String, max : UInt32 = NETSTRING_MAX) #

Returns a new Netstring based on input.

max is a user-specifiable maximum size for input, which can be set either above or below the default NETSTRING_MAX.

Raises a ParseError on any parser failure.

ns = Netstring.parse "3:foo,"
ns.size # => 3
ns.data # => Bytes[102, 111, 111]
ns.to_s # => "foo"

[View source]
def self.parse(input : IO, max : UInt32 = NETSTRING_MAX) #

Like the other .parse, but takes an IO instead. See .parse.


[View source]

Instance Method Detail

def data : Slice(UInt8) #

Returns the body of the netstring, as a slice.


[View source]
def size #

Returns the size of the parsed netstring.


[View source]
def to_s(io) #

Returns a string containing the encoded contents of the netstring.

NOTE This will not fix or deduce the correct encoding for you. It assumes UTF-8.


[View source]