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) }
func (msg *Message) InsertMessage(message interface{}) { marshalled, err := msgpack.Marshal(message) if err != nil { // do something about it } msg.Message = marshalled }
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) }
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) } }
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 } }
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 }
// 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 }
func fnVMsgpackEncodeFn(ts interface{}) ([]byte, error) { return vmsgpack.Marshal(ts) }
func fnVMsgpackEncodeFn(ts *TestStruc) ([]byte, error) { return vmsgpack.Marshal(ts) }
func (m msgpackEncoder) Marshal(v interface{}) ([]byte, error) { return msgpack.Marshal(v) }
func EncodeMsgPack(message map[string]interface{}) []byte { b, _ := msgpack.Marshal(message) return b }