• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ffjson.Marshal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pquerna/ffjson/ffjson.Marshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Marshal函数的具体用法?Golang Marshal怎么用?Golang Marshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Marshal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: HandleAddCustomEventHandlers

func HandleAddCustomEventHandlers(e *tree_event.Event, api_cmd Command) {
	var (
		out          = &WriterCallback{BufferMaxSize: 1024}
		handler_data map[string]interface{}
		err          tree_lib.TreeError
		ev_data      []byte
	)
	err.From = tree_lib.FROM_ADD_CUSTOM_EVENT
	err.Err = ffjson.Unmarshal(api_cmd.Data, &handler_data)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}

	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := api_cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(e, ev_data)
	}
	defer out.End()

	event_name := handler_data["name"].(string)
	handles_interfaces := handler_data["handlers"].([]interface{})
	var (
		handles_interfaces_data []byte
		handlers                []custom_event.Handler
	)
	handles_interfaces_data, err.Err = ffjson.Marshal(handles_interfaces)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}

	err.Err = ffjson.Unmarshal(handles_interfaces_data, &handlers)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}

	err = custom_event.ON(event_name, handlers...)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:50,代码来源:handle_event.go


示例2: main

func main() {
	r := new(RetNode)
	r.Name = "sunsc"
	r.Sex = "male"
	r.Age = 36
	buf, err := json.Marshal(r)
	log.Println("err==>", err, "| buf=>", string(buf))

	secr := new(ReqCardInfoType)
	secr.ApiName = "test"
	secr.Id = "72789765231"
	secr.BizApiCode = "0005000400000001"
	buf, err = json.Marshal(secr)
	log.Println("err==>", err, "| buf=>", string(buf))
}
开发者ID:sunvim,项目名称:codelab,代码行数:15,代码来源:main.go


示例3: HandleExecCommand

// Executing some commands using exec.Command functionality from Go in OS
func HandleExecCommand(e *tree_event.Event, api_cmd Command) {
	var (
		out         = &WriterCallback{BufferMaxSize: 1024}
		cmd_str     = string(api_cmd.Data)
		cmd_options = strings.Split(cmd_str, " ")
		cmd         = exec.Command(cmd_options[0], cmd_options[1:]...)
		err         tree_lib.TreeError
		ev_data     []byte
	)
	err.From = tree_lib.FROM_HANDLE_EXEC_COMMAND
	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := api_cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(e, ev_data)
	}

	defer out.End()

	cmd.Stdout = out
	cmd.Stderr = out
	err.Err = cmd.Run()
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:32,代码来源:handle_exec.go


示例4: SendCommand

func SendCommand(cmd *Command, path *tree_graph.Path, cb func(*tree_event.Event, Command) bool) (err tree_lib.TreeError) {
	// If command ID not set just setting random string
	if len(cmd.ID) == 0 {
		cmd.ID = tree_lib.RandomString(10)
	}

	var (
		cmd_data []byte
	)

	cmd_data, err.Err = ffjson.Marshal(cmd)
	if !err.IsNull() {
		err.From = tree_lib.FROM_SEND_COMMAND
		return
	}

	e := &tree_event.Event{
		Name:    tree_event.ON_API_COMMAND,
		Data:    cmd_data,
		FromApi: node_info.CurrentNodeInfo.Value,
		From:    path.From,
	}

	tree_event.Emit(e, path)

	if cb != nil {
		subscribed_command_callbacks[cmd.ID] = cb_str{f: cb, c: make(chan bool)}
		<-subscribed_command_callbacks[cmd.ID].c
	}

	return
}
开发者ID:treescale,项目名称:treescale,代码行数:32,代码来源:api_command.go


示例5: HandleContainerCommand

func HandleContainerCommand(ev *tree_event.Event, cmd Command) {
	var (
		out        = &WriterCallback{BufferMaxSize: 1024}
		docker_cmd = tree_docker.DockerCmd{}
		err        tree_lib.TreeError
		ev_data    []byte
	)
	err.From = tree_lib.FROM_HANDLE_CONTAINER_COMMAND
	err.Err = ffjson.Unmarshal(cmd.Data, &docker_cmd)
	if !err.IsNull() {
		tree_log.Error(err.From, "unable to unmarshal command data as a docker command -> ", err.Error())
		return
	}
	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(ev, ev_data)
	}

	defer out.End()

	tree_docker.ContainerCommands(&docker_cmd, out)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:handle_container.go


示例6: FillDatabase

func FillDatabase(listApps []App) {

	for _, app := range listApps {
		appdb.Update(func(tx *bolt.Tx) error {
			b, err := tx.CreateBucketIfNotExists([]byte("AppBucket"))
			if err != nil {
				return fmt.Errorf("create bucket: %s", err)
			}

			serialize, err := json.Marshal(app)

			if err != nil {
				return fmt.Errorf("Error Marshaling data: %s", err)
			}
			err = b.Put([]byte(app.Guid), serialize)

			if err != nil {
				return fmt.Errorf("Error inserting data: %s", err)
			}
			return nil
		})

	}

}
开发者ID:shinji62,项目名称:firehose-to-fluentd,代码行数:25,代码来源:caching.go


示例7: GetMsgHandler

///从数据库pull消息
func GetMsgHandler(w http.ResponseWriter, req *http.Request) {
	//获取客户端通过GET/POST方式传递的参数
	var retmsg string
	req.ParseForm()
	param1, found1 := req.Form["topic"]
	param2, _ := req.Form["limit"]

	if !found1 {
		retmsg = "请勿非法访问"
	}

	topic := param1[0]
	limit, err := strconv.Atoi(param2[0])
	if err != nil {
		retmsg = "请勿非法访问"
	}

	if topic != "" {

		dblist := models.GetMessagesForField("topic", topic, limit)
		msgjson, _ := ffjson.Marshal(dblist)
		retmsg = string(msgjson)
	} else {

		retmsg = "topic is null"
	}
	io.WriteString(w, retmsg)

}
开发者ID:aimicm,项目名称:nsqclient,代码行数:30,代码来源:NsqController.go


示例8: main

func main() {
	fmt.Println("helloworld")
	DbaEnvrEx := buildEnvr()

	var listCard = make([]TCARD, 0)
	DbaEnvrEx.Select(&listCard, "SELECT  * FROM TBL_CARD")

	t0 := time.Now()
	//result, _ := json.Marshal(listCard)
	result, _ := ffjson.Marshal(listCard)
	t1 := time.Since(t0)
	fmt.Println(t1)
	fmt.Println(string(result))

	/*
		icount, ERR := DbaEnvrEx.SelectInt("SELECT COUNT(*) AS ICOUNT FROM TBL_CARD") //select count(*) as icount from tbl_card

		checkErr(ERR, "NULL")
		fmt.Println(icount)
	*/

	/*
		var listData = make([]TCARD, 0)
		_, eror := DbaEnvrEx.Select(&listData, "SELECT CARD_CODE,CARD_NAME,CARD_ZCTM,CARD_ZCYZ FROM TBL_CARD ORDER BY CARD_CODE")
		if eror != nil {
			fmt.Println(len(listData))
		}
	*/

}
开发者ID:kazarus,项目名称:GoDemo,代码行数:30,代码来源:main.go


示例9: PostMsgHandler

func PostMsgHandler(w http.ResponseWriter, req *http.Request) {
	//获取客户端通过GET/POST方式传递的参数
	req.ParseForm()
	param1, found1 := req.Form["sendmsg"]
	result := NewBaseJsonBean()

	if !found1 {
		result.Code = -99
		result.Message = "请勿非法访问"
	}

	fdata := param1[0]

	if fdata != "" {
		faction := "POST"
		furl := "http://nsq-ttthzygi35.tenxcloud.net:20157/put?topic=test"
		result.Code = 100
		result.Message = lib.HttpDo_NSQ(faction, furl, fdata)
	} else {
		result.Code = 101
		result.Message = "消息不能为空,请重新发送!"
	}

	//向客户端返回JSON数据,用到了ffjson包,据说比自带的json效率高3倍
	//bytes, _ := json.Marshal(result)
	bytes, _ := ffjson.Marshal(result)
	io.WriteString(w, string(bytes))

}
开发者ID:aimicm,项目名称:nsqclient,代码行数:29,代码来源:NsqController.go


示例10: NetworkEmmit

func NetworkEmmit(e *tree_event.Event, path *tree_graph.Path) (err tree_lib.TreeError) {
	var (
		sdata []byte
		p     *big.Int
	)
	err.From = tree_lib.FROM_NETWORK_EMIT

	// Calling get value, because maybe some one will calculate this path before calling this functions
	// If path is not calculated yet, it will be automatically calculated in GetValue function
	p, err = path.GetValue()
	if !err.IsNull() {
		return
	}

	// If we emitting from API then we need to multiply path with connected node
	// For sending data through him
	if strings.Contains(node_info.CurrentNodeInfo.Name, tree_api.API_NAME_PREFIX) {
		p.Mul(p, node_info.ChildsNodeValue[path.From])
	}

	// If from not set, setting it before network sending
	if len(e.From) == 0 {
		e.From = node_info.CurrentNodeInfo.Name
	}

	sdata, err.Err = ffjson.Marshal(e)
	if !err.IsNull() {
		return
	}

	SendToPath(sdata, p)
	return
}
开发者ID:treescale,项目名称:treescale,代码行数:33,代码来源:network.go


示例11: SetPathValues

func SetPathValues() (err tree_lib.TreeError) {
	var (
		nodes []node_info.NodeInfo
		prime int64
		value []byte
	)
	err.From = tree_lib.FROM_SET_PATH_VALUES
	nodes, err = ListNodeInfos()
	if !err.IsNull() {
		return
	}
	prime = 2
	for _, n := range nodes {
		n.Value = prime
		value, err.Err = ffjson.Marshal(n)
		if !err.IsNull() {
			return
		}
		err = Set(DB_NODE, []byte(n.Name), value)
		if !err.IsNull() {
			return
		}
		prime = tree_lib.NextPrimeNumber(prime)
	}
	return
}
开发者ID:treescale,项目名称:treescale,代码行数:26,代码来源:node_db.go


示例12: apiRequest

// Perform a B2 API request with the provided request and response objects
func (c *B2) apiRequest(apiPath string, request interface{}, response interface{}) error {
	body, err := ffjson.Marshal(request)
	if err != nil {
		return err
	}
	defer ffjson.Pool(body)

	if c.Debug {
		log.Println("----")
		log.Printf("apiRequest: %s %s", apiPath, body)
	}

	err = c.tryAPIRequest(apiPath, body, response)

	// Retry after non-fatal errors
	if b2err, ok := err.(*B2Error); ok {
		if !b2err.IsFatal() && !c.NoRetry {
			if c.Debug {
				log.Printf("Retrying request %q due to error: %v", apiPath, err)
			}

			return c.tryAPIRequest(apiPath, body, response)
		}
	}
	return err
}
开发者ID:hack4impact,项目名称:transcribe4all,代码行数:27,代码来源:backblaze.go


示例13: HandleTriggerCustomEvent

func HandleTriggerCustomEvent(e *tree_event.Event, api_cmd Command) {
	var (
		out        = &WriterCallback{BufferMaxSize: 1024}
		event_name = string(api_cmd.Data)
		err        tree_lib.TreeError
		ev_data    []byte
	)
	err.From = tree_lib.FROM_TRIGGER_CUSTOM_EVENT
	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := api_cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(e, ev_data)
	}
	defer out.End()
	err = custom_event.Trigger(event_name, out)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:handle_event.go


示例14: toJSON

func toJSON(o interface{}) string {
	bytes, err := ffjson.Marshal(o)
	if err != nil {
		log.Fatal(err)
	}
	return string(bytes)
}
开发者ID:kothar,项目名称:go-backblaze,代码行数:7,代码来源:backblaze_test.go


示例15: SendDockerCommand

func SendDockerCommand(cmd tree_docker.DockerCmd, node string, target []string, tag []string, group []string) {
	var err tree_lib.TreeError
	if !tree_api.API_INIT(node) {
		fmt.Println("Unable to init api client")
		fmt.Println("Exiting ...")
		return
	}
	err.From = tree_lib.FROM_SEND_DOCKER_COMMAND
	var (
		api_cmd = tree_api.Command{}
		wait    = make(chan bool)
	)

	api_cmd.ID = tree_lib.RandomString(20)
	api_cmd.Data, err.Err = ffjson.Marshal(cmd)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}
	api_cmd.CommandType = tree_api.COMMAND_CONTAINER

	tree_event.ON(tree_event.ON_CHILD_CONNECTED, func(ev *tree_event.Event) {
		path := &tree_graph.Path{From: node, Nodes: target, Groups: group, Tags: tag}
		tree_api.SendCommand(&api_cmd, path, func(e *tree_event.Event, c tree_api.Command) bool {
			fmt.Println(string(c.Data))
			fmt.Println(c.Ended)
			if c.Ended {
				return false
			}
			return true
		})
		wait <- true
	})
	<-wait
}
开发者ID:treescale,项目名称:treescale,代码行数:35,代码来源:api.go


示例16: String

func (this *Bucket) String() string {
	str, err := ffjson.Marshal(this)
	if err != nil {
		return "Error encoding to JSON: " + err.Error()
	} else {
		return string(str)
	}
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:8,代码来源:bucket.go


示例17: StartMQTTSender

func StartMQTTSender(MQTTServerAddress string, MQTTSendChan chan *lib.PostMessage, channel_name string) chan bool {
	close_chan := make(chan bool)
	go func() {
		defer func() {
			if err := recover(); err != nil {
				utils.Log.Println(err)
				debug.PrintStack()
			}
		}()

		var post_message *lib.PostMessage
		var cli *client.Client
		var err error

		cli, err = ConnectToMQTTServer(MQTTServerAddress)
		if err != nil {
			utils.Log.Println("Connect to MQTT Server failed:", err)
			return
		}

		for {
			select {
			case <-close_chan:
				close_chan <- true
				utils.Log.Printf("Quit MQTT Sender worker.")
				return

			case post_message = <-MQTTSendChan:
				message_json_buffer, err := ffjson.Marshal(post_message)
				if err != nil {
					utils.Log.Println()
				}

				err = cli.Publish(&client.PublishOptions{
					QoS:       mqtt.QoS0,
					TopicName: []byte(channel_name),
					Message:   []byte(message_json_buffer),
				})

				if err != nil {
					utils.Log.Println("Publish to MQTT Failed:", err)
					utils.Log.Println("Try to connect MQTT Server.")
					cli, err = ConnectToMQTTServer(MQTTServerAddress)
					if err != nil {
						utils.Log.Println("Connect to MQTT Server failed:", err)
					}
				}

				utils.Log.Printf("Send message to MQTT Server: %s, Length: %d\n", MQTTServerAddress, len(message_json_buffer))

				ffjson.Pool(message_json_buffer)
			}
		}
	}()

	return close_chan
}
开发者ID:amghost,项目名称:message_service,代码行数:57,代码来源:mqtt.go


示例18: RevMsgHandler

///ESM推送
func RevMsgHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/event-stream")
	w.Header().Set("Cache-Control", "no-cache")
	//

	bytes, _ := ffjson.Marshal(lib.RevMsg)
	msg := "data:" + string(bytes) + "\n\n"
	io.WriteString(w, msg)

}
开发者ID:aimicm,项目名称:nsqclient,代码行数:11,代码来源:NsqController.go


示例19: TestMarshalFaster

func TestMarshalFaster(t *testing.T) {
	record := newLogFFRecord()
	_, err := ffjson.MarshalFast(record)
	require.NoError(t, err)

	r2 := newLogRecord()
	_, err = ffjson.MarshalFast(r2)
	require.Error(t, err, "Record should not support MarshalFast")
	_, err = ffjson.Marshal(r2)
	require.NoError(t, err)
}
开发者ID:gooops,项目名称:ffjson,代码行数:11,代码来源:ff_test.go


示例20: main

func main() {
	t1 := time.Now()
	defer func() {
		fmt.Println(time.Now().Sub(t1))
	}()
	m := mould.Input("input1.xml", "text1.htm")
	json, err := ffjson.Marshal(m)
	fmt.Println(string(json), err)
	mould.Output(m, "output.xml", "test2.html")

}
开发者ID:slygo,项目名称:360baosdk,代码行数:11,代码来源:main.go



注:本文中的github.com/pquerna/ffjson/ffjson.Marshal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ffjson.Pool函数代码示例发布时间:2022-05-28
下一篇:
Golang ros.SerializeMessageField函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap