Esempio n. 1
0
func (t *TupleSpaceClient) do(method string, req interface{}, resp interface{}) error {
	reqBytes, err := msgpack.Marshal(req)
	if err != nil {
		return err
	}
	hreq, err := http.NewRequest(method, t.url, bytes.NewReader(reqBytes))
	if err != nil {
		return err
	}
	hreq.Header["Accept"] = []string{"application/x-msgpack"}
	hreq.Header["Content-Type"] = []string{"application/x-msgpack"}

	hresp, err := t.client.Do(hreq)
	if hresp != nil && hresp.Body != nil {
		defer hresp.Body.Close()
	}
	if err != nil {
		return err
	}
	decoder := msgpack.NewDecoder(hresp.Body)
	if hresp.StatusCode < 200 || hresp.StatusCode > 299 {
		if hresp.StatusCode == http.StatusGatewayTimeout {
			return tuplespace.ReaderTimeout
		}
		herr := &tuplespace.ErrorResponse{}
		err := decoder.Decode(herr)
		if err != nil {
			return err
		}
		return errors.New(herr.Error)
	}

	return decoder.Decode(resp)
}
Esempio n. 2
0
func (msg *Message) InsertMessage(message interface{}) {
	marshalled, err := msgpack.Marshal(message)
	if err != nil {
		// do something about it
	}
	msg.Message = marshalled
}
Esempio n. 3
0
func (self *MemdClient) Set(key string, value interface{}, expires int32) error {
	b, err := msgpack.Marshal(value)
	if err != nil {
		log.Fatalf("Failed to encode value: %s", err)
	}
	item := &memcache.Item{Key: key, Value: b, Flags: 4, Expiration: expires}
	return self.client.Set(item)
}
Esempio n. 4
0
func SendMsg(conn *net.UDPConn, returnAddress *net.UDPAddr, msg Message) {
	b, err := msgpack.Marshal(msg)
	if err != nil {
		// do something!
	}
	bytesWritten, networkErr := conn.WriteToUDP(b, returnAddress)

	if networkErr != nil {
		log.Fatalf("FAILED TO WRITE %d BYTES. Reason: %v", bytesWritten, networkErr)
	}
}
Esempio n. 5
0
func sendMsg(conn *net.UDPConn, returnAddress *net.UDPAddr, msg Message) {
	b, err := msgpack.Marshal(msg)
	if err != nil {
		// do something!
	}
	log.Printf("Conn: %#v\nReturnAddr: %#v\n", conn, returnAddress)
	bytesWritten, networkErr := conn.Write(b)

	if networkErr != nil {
		log.Fatalf("FAILED TO WRITE %d BYTES. Reason: %v", bytesWritten, networkErr)
		return
	}
}
Esempio n. 6
0
func ChatMessage(from *Player, message string) []byte {
	var c ChatMsg
	c.MessageType = MESSAGE_CHAT
	if from == nil {
		c.Server = true
	} else {
		c.Server = false
		c.Name = from.User.Name
	}
	c.Message = message

	b, _ := msgpack.Marshal(c)
	return b
}
Esempio n. 7
0
// RecordHit will store an AnalyticsRecord in Redis
func (r RedisAnalyticsHandler) RecordHit(thisRecord AnalyticsRecord) error {
	encoded, err := msgpack.Marshal(thisRecord)
	u5, _ := uuid.NewV4()

	keyName := fmt.Sprintf("%d%d%d%d-%s", thisRecord.Year, thisRecord.Month, thisRecord.Day, thisRecord.Hour, u5.String())

	if err != nil {
		log.Error("Error encoding analytics data:")
		log.Error(err)
		return AnalyticsError{}
	}

	r.Store.SetKey(keyName, string(encoded), 0)

	return nil
}
Esempio n. 8
0
func fnVMsgpackEncodeFn(ts interface{}) ([]byte, error) {
	return vmsgpack.Marshal(ts)
}
Esempio n. 9
0
func fnVMsgpackEncodeFn(ts *TestStruc) ([]byte, error) {
	return vmsgpack.Marshal(ts)
}
Esempio n. 10
0
func (m msgpackEncoder) Marshal(v interface{}) ([]byte, error) {
	return msgpack.Marshal(v)
}
Esempio n. 11
0
func EncodeMsgPack(message map[string]interface{}) []byte {
	b, _ := msgpack.Marshal(message)
	return b
}