netstringer

package module
v0.0.0-...-676e636 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2017 License: MIT Imports: 3 Imported by: 2

README

Netstringer

Golang package to encode or decode stream of netstring

To install package:

go get github.com/ragsagar/netstringer

Examples:
To encode a data into netstring
//main.go
package main

import (
	"fmt"
	"github.com/ragsagar/netstringer"
)

func main() {
	input := []byte("hello world!")
	output := netstringer.Encode(input)
	fmt.Println(string(output)) // 12:hello world!,
}
$go run main.go
12:hello world!,
To decode a stream of incoming data into netstring
// main.go
package main

import (
	"fmt"
	"github.com/ragsagar/netstringer"
)

func main() {
        // To mock the incoming stream of data.
	inputs := []string{
		"12:hello world!,",
		"17:5:hello,6:world!,,",
		"12:hello ",
		"world!,",
	}
	decoder := netstringer.NewDecoder()
	go func() {
		for _, input := range inputs {
			decoder.FeedData([]byte(input))
		}
		close(decoder.DataOutput)
	}()

	for output := range decoder.DataOutput {
		fmt.Println(string(output))

	}
}
$go run main.go 
hello world!
5:hello,6:world!,
hello world!

Documentation

Index

Constants

View Source
const (
	PARSE_LENGTH = iota
	PARSE_SEPARATOR
	PARSE_DATA
	PARSE_END
)
View Source
const BUFFER_COUNT = 10

Variables

This section is empty.

Functions

func Encode

func Encode(data []byte) []byte

Types

type NetStringDecoder

type NetStringDecoder struct {
	DataOutput chan []byte
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder() NetStringDecoder

Caller receives the parsed parsedData through the output channel.

func (NetStringDecoder) DebugLog

func (decoder NetStringDecoder) DebugLog(v ...interface{})

func (*NetStringDecoder) FeedData

func (decoder *NetStringDecoder) FeedData(data []byte)

func (*NetStringDecoder) SetDebugMode

func (decoder *NetStringDecoder) SetDebugMode(mode bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL