Adding readable disk storage with minimalistic tests
This commit is contained in:
		@@ -7,8 +7,43 @@ import (
 | 
			
		||||
	"bitbucket.org/nicdex/adaptech-goes"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Serializer struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewSerializer() goes.Serializer {
 | 
			
		||||
	return &Serializer{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (me Serializer) Serialize(input interface{}) (output []byte, typeId string, err error) {
 | 
			
		||||
	content, ok := input.([]byte)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		err = errors.New("input should be []byte")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sep := bytes.IndexByte(content, ' ')
 | 
			
		||||
	if sep == -1 {
 | 
			
		||||
		err = errors.New("missing split char.")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	output = content[sep+1:]
 | 
			
		||||
	typeId = string(content[0:sep])
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (me Serializer) Deserialize(input []byte, typeId string) (interface{}, error) {
 | 
			
		||||
	output := []byte(typeId)
 | 
			
		||||
	output = append(output, ' ')
 | 
			
		||||
	output = append(output, input...)
 | 
			
		||||
 | 
			
		||||
	return output, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	fmt.Println("Simple ZeroMQ server for goes.")
 | 
			
		||||
 | 
			
		||||
@@ -16,8 +51,8 @@ func main() {
 | 
			
		||||
	storagePath := path.Join(os.TempDir(), uuid.NewV4().String())
 | 
			
		||||
	storagePath = "c:\\dev\\go\\events"
 | 
			
		||||
 | 
			
		||||
	goes.SetStorage(goes.NewDiskStorage(storagePath))
 | 
			
		||||
	goes.SetSerializer(goes.NewPassthruSerializer())
 | 
			
		||||
	goes.SetStorage(goes.NewReadableDiskStorage(storagePath))
 | 
			
		||||
	goes.SetSerializer(NewSerializer())
 | 
			
		||||
 | 
			
		||||
	context, err := zmq4.NewContext()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user