本文整理汇总了Golang中github.com/golang/protobuf/proto.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: write
func write(conn *net.TCPConn) {
n := protocol.Mode(5)
reg := &protocol.WMessage{
MsgType: proto.String("sendMsg"),
MsgTypeId: proto.Int32(8),
UserInfo: &protocol.User{
Username: proto.String("jim"),
//Password: proto.String("123456"),
},
SendMsg: &protocol.SendMessage{
Receiver: proto.String("zhang"),
MsgType: &n,
Msg: proto.String("吃了吗?"),
},
}
buf, err := proto.Marshal(reg)
if err != nil {
fmt.Println("failed: %s\n", err)
return
}
fmt.Println("buf: ", len(buf))
length := len(buf)
buffer := append(common.IntToBytes(length), buf...)
conn.Write(buffer)
//return buffer
//conn.Write(common.IntToBytes(length))
}
示例2: keyToProto
func keyToProto(k *Key) *pb.Key {
if k == nil {
return nil
}
// TODO(jbd): Eliminate unrequired allocations.
path := []*pb.Key_PathElement(nil)
for {
el := &pb.Key_PathElement{
Kind: proto.String(k.kind),
}
if k.id != 0 {
el.Id = proto.Int64(k.id)
}
if k.name != "" {
el.Name = proto.String(k.name)
}
path = append([]*pb.Key_PathElement{el}, path...)
if k.parent == nil {
break
}
k = k.parent
}
key := &pb.Key{
PathElement: path,
}
if k.namespace != "" {
key.PartitionId = &pb.PartitionId{
Namespace: proto.String(k.namespace),
}
}
return key
}
示例3: listener
func listener(c <-chan []byte, dst *string) {
for {
msg := <-c
var conAuxSlice []ConAux
json.Unmarshal(msg, &conAuxSlice)
fmt.Println("unmarshalled", conAuxSlice)
connections := new(protobee.Connections)
connections.Connection = []*protobee.Connection{}
for _, value := range conAuxSlice {
con := new(protobee.Connection)
con.Transport = proto.String(value.Transport)
con.LocalAddress = proto.String(value.LocalAddress)
con.LocalPort = proto.Uint32(value.LocalPort)
con.RemoteAddress = proto.String(value.RemoteAddress)
con.RemotePort = proto.Uint32(value.RemotePort)
con.Pid = proto.Uint32(value.Pid)
con.Name = proto.String(value.Name)
connections.Connection = append(connections.Connection, con)
}
//connections
pb, err := proto.Marshal(connections)
if err != nil {
fmt.Println("error", err)
}
sendDataToDest(pb, dst)
//time.Sleep(time.Second * 2)
}
}
示例4: TestStringSave
func TestStringSave(t *testing.T) {
options := MysqlOptions{
Addr: "localhost:3306",
DB: "kite",
Username: "root",
Password: "",
ShardNum: 4,
BatchUpSize: 100,
BatchDelSize: 100,
FlushPeriod: 10 * time.Millisecond,
MaxIdleConn: 10,
MaxOpenConn: 10}
kiteMysql := NewKiteMysql(options, "localhost")
truncate(kiteMysql)
for i := 0; i < 16; i++ {
//创建消息
msg := &protocol.StringMessage{}
msg.Header = &protocol.Header{
MessageId: proto.String("26c03f00665862591f696a980b5a6" + fmt.Sprintf("%x", i)),
Topic: proto.String("trade"),
MessageType: proto.String("pay-succ"),
ExpiredTime: proto.Int64(time.Now().Add(10 * time.Minute).Unix()),
DeliverLimit: proto.Int32(100),
GroupId: proto.String("go-kite-test"),
Commit: proto.Bool(false),
Fly: proto.Bool(false)}
msg.Body = proto.String("hello world")
innerT(kiteMysql, msg, msg.GetHeader().GetMessageId(), t)
}
kiteMysql.Stop()
}
示例5: keyToProto
// keyToProto converts a *Key to a Reference proto.
func keyToProto(defaultAppID string, k *Key) *pb.Reference {
appID := k.appID
if appID == "" {
appID = defaultAppID
}
n := 0
for i := k; i != nil; i = i.parent {
n++
}
e := make([]*pb.Path_Element, n)
for i := k; i != nil; i = i.parent {
n--
e[n] = &pb.Path_Element{
Type: &i.kind,
}
// At most one of {Name,Id} should be set.
// Neither will be set for incomplete keys.
if i.stringID != "" {
e[n].Name = &i.stringID
} else if i.intID != 0 {
e[n].Id = &i.intID
}
}
var namespace *string
if k.namespace != "" {
namespace = proto.String(k.namespace)
}
return &pb.Reference{
App: proto.String(appID),
NameSpace: namespace,
Path: &pb.Path{
Element: e,
},
}
}
示例6: Seal
// Seal encrypts data for the child. This call also zeroes the data parameter.
func (lh *LinuxHost) Seal(child *LinuxHostChild, data []byte, policy string) ([]byte, error) {
defer ZeroBytes(data)
lhsb := &LinuxHostSealedBundle{
Policy: proto.String(policy),
Data: data,
}
switch policy {
case SharedSecretPolicyDefault, SharedSecretPolicyConservative:
// We are using a master key-deriving key shared among all
// similar LinuxHost instances. For LinuxHost, the default
// and conservative policies means any process running the same
// program binary as the caller hosted on a similar
// LinuxHost.
lhsb.PolicyInfo = proto.String(child.ChildSubprin.String())
case SharedSecretPolicyLiberal:
// The most liberal we can do is allow any hosted process
// running on a similar LinuxHost instance. So, we don't set
// any policy info.
default:
// Try to parse this statement as a tao/auth policy. If it
// parses, then use it as the policy statement.
return nil, newError("policy not supported for Seal: " + policy)
}
m, err := proto.Marshal(lhsb)
if err != nil {
return nil, err
}
defer ZeroBytes(m)
return lh.Host.Encrypt(m)
}
示例7: TestAttribute
func TestAttribute(t *testing.T) {
attr := Attribute(&mesos.Attribute{
Name: proto.String("rack"),
Type: mesos.Value_SCALAR.Enum(),
Scalar: &mesos.Value_Scalar{Value: proto.Float64(2)},
})
if attr != "rack:2.00" {
t.Errorf(`Attribute(&mesos.Attribute{
Name: proto.String("rack"),
Type: mesos.Value_SCALAR.Enum(),
Scalar: &mesos.Value_Scalar{Value: proto.Float64(2)},
}) != "rack:2.00"; actual %s`, attr)
}
attr = Attribute(&mesos.Attribute{
Name: proto.String("datacenter"),
Type: mesos.Value_TEXT.Enum(),
Text: &mesos.Value_Text{Value: proto.String("DC-1")},
})
if attr != "datacenter:DC-1" {
t.Errorf(`Attribute(&mesos.Attribute{
Name: proto.String("datacenter"),
Type: mesos.Value_TEXT.Enum(),
Text: proto.String("DC-1"),
}) != "datacenter:DC-1"; actual %s`, attr)
}
}
示例8: TestToVerifyXmlContentForDataTableDrivenExecution
func (s *MySuite) TestToVerifyXmlContentForDataTableDrivenExecution(c *C) {
value := gauge_messages.ProtoItem_TableDrivenScenario
scenario := gauge_messages.ProtoScenario{Failed: proto.Bool(false), ScenarioHeading: proto.String("Scenario")}
scenario1 := gauge_messages.ProtoScenario{Failed: proto.Bool(false), ScenarioHeading: proto.String("Scenario")}
item := &gauge_messages.ProtoItem{TableDrivenScenario: &gauge_messages.ProtoTableDrivenScenario{Scenarios: []*gauge_messages.ProtoScenario{&scenario, &scenario1}}, ItemType: &value}
spec := &gauge_messages.ProtoSpec{SpecHeading: proto.String("HEADING"), FileName: proto.String("FILENAME"), Items: []*gauge_messages.ProtoItem{item}}
specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: proto.Int(1), Failed: proto.Bool(false)}
suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}
message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}
builder := &XmlBuilder{currentId: 0}
bytes, err := builder.getXmlContent(message)
var suites JUnitTestSuites
xml.Unmarshal(bytes, &suites)
c.Assert(err, Equals, nil)
c.Assert(len(suites.Suites), Equals, 1)
c.Assert(suites.Suites[0].Errors, Equals, 0)
c.Assert(suites.Suites[0].Failures, Equals, 0)
c.Assert(suites.Suites[0].Package, Equals, "FILENAME")
c.Assert(suites.Suites[0].Name, Equals, "HEADING")
c.Assert(suites.Suites[0].Tests, Equals, 2)
c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)
c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")
c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")
c.Assert(len(suites.Suites[0].TestCases), Equals, 2)
c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario 0")
c.Assert(suites.Suites[0].TestCases[1].Name, Equals, "Scenario 1")
}
示例9: TestToVerifyXmlContentForFailingExecutionResult
func (s *MySuite) TestToVerifyXmlContentForFailingExecutionResult(c *C) {
value := gauge_messages.ProtoItem_Scenario
item := &gauge_messages.ProtoItem{Scenario: &gauge_messages.ProtoScenario{Failed: proto.Bool(true), ScenarioHeading: proto.String("Scenario1")}, ItemType: &value}
spec := &gauge_messages.ProtoSpec{SpecHeading: proto.String("HEADING"), FileName: proto.String("FILENAME"), Items: []*gauge_messages.ProtoItem{item}}
specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: proto.Int(1), Failed: proto.Bool(true), ScenarioFailedCount: proto.Int(1)}
suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}
message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}
builder := &XmlBuilder{currentId: 0}
bytes, err := builder.getXmlContent(message)
var suites JUnitTestSuites
xml.Unmarshal(bytes, &suites)
c.Assert(err, Equals, nil)
c.Assert(len(suites.Suites), Equals, 1)
// spec1 || testSuite
c.Assert(suites.Suites[0].Errors, Equals, 0)
c.Assert(suites.Suites[0].Failures, Equals, 1)
c.Assert(suites.Suites[0].Package, Equals, "FILENAME")
c.Assert(suites.Suites[0].Name, Equals, "HEADING")
c.Assert(suites.Suites[0].Tests, Equals, 1)
c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)
c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")
c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")
// scenario1 of spec1 || testCase
c.Assert(len(suites.Suites[0].TestCases), Equals, 1)
c.Assert(suites.Suites[0].TestCases[0].Classname, Equals, "HEADING")
c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario1")
c.Assert(suites.Suites[0].TestCases[0].Failure.Message, Equals, "")
c.Assert(suites.Suites[0].TestCases[0].Failure.Contents, Equals, "")
}
示例10: GetFailoverLogs
// GetFailoverLogs from projector, for a set vbuckets.
// - return http errors for transport related failures.
// - return couchbase SDK error if any.
func (client *Client) GetFailoverLogs(
pooln, bucketn string,
vbnos []uint32) (*protobuf.FailoverLogResponse, error) {
req := &protobuf.FailoverLogRequest{
Pool: proto.String(pooln),
Bucket: proto.String(bucketn),
Vbnos: vbnos,
}
res := &protobuf.FailoverLogResponse{}
err := client.withRetry(
func() error {
err := client.ap.Request(req, res)
if err != nil {
return err
} else if protoerr := res.GetErr(); protoerr != nil {
return fmt.Errorf(protoerr.GetError())
}
return err // nil
})
if err != nil {
return nil, err
}
return res, nil
}
示例11: convertToProtoStepValue
func convertToProtoStepValue(stepValue *stepValue) *gauge_messages.ProtoStepValue {
return &gauge_messages.ProtoStepValue{
StepValue: proto.String(stepValue.stepValue),
ParameterizedStepValue: proto.String(stepValue.parameterizedStepValue),
Parameters: stepValue.args,
}
}
示例12: CreateFile
// CreateFile opens a new file in HDFS with the given replication, block size,
// and permissions, and returns an io.WriteCloser for writing to it. Because of
// the way that HDFS writes are buffered and acknowledged asynchronously, it is
// very important that Close is called after all data has been written.
func (c *Client) CreateFile(name string, replication int, blockSize int64, perm os.FileMode) (*FileWriter, error) {
createReq := &hdfs.CreateRequestProto{
Src: proto.String(name),
Masked: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
ClientName: proto.String(c.namenode.ClientName()),
CreateFlag: proto.Uint32(1),
CreateParent: proto.Bool(false),
Replication: proto.Uint32(uint32(replication)),
BlockSize: proto.Uint64(uint64(blockSize)),
}
createResp := &hdfs.CreateResponseProto{}
err := c.namenode.Execute("create", createReq, createResp)
if err != nil {
if nnErr, ok := err.(*rpc.NamenodeError); ok {
err = interpretException(nnErr.Exception, err)
}
return nil, &os.PathError{"create", name, err}
}
return &FileWriter{
client: c,
name: name,
replication: replication,
blockSize: blockSize,
}, nil
}
示例13: startNewBlock
func (f *FileWriter) startNewBlock() error {
// TODO: we don't need to wait for previous blocks to ack before continuing
if f.blockWriter != nil {
err := f.blockWriter.Close()
if err != nil {
return err
}
}
var previous *hdfs.ExtendedBlockProto
if f.block != nil {
previous = f.block.GetB()
}
addBlockReq := &hdfs.AddBlockRequestProto{
Src: proto.String(f.name),
ClientName: proto.String(f.client.namenode.ClientName()),
Previous: previous,
}
addBlockResp := &hdfs.AddBlockResponseProto{}
err := f.client.namenode.Execute("addBlock", addBlockReq, addBlockResp)
if err != nil {
if nnErr, ok := err.(*rpc.NamenodeError); ok {
err = interpretException(nnErr.Exception, err)
}
return &os.PathError{"create", f.name, err}
}
f.block = addBlockResp.GetBlock()
f.blockWriter = rpc.NewBlockWriter(f.block, f.client.namenode, f.blockSize)
return nil
}
示例14: Close
// Close closes the file, writing any remaining data out to disk and waiting
// for acknowledgements from the datanodes. It is important that Close is called
// after all data has been written.
func (f *FileWriter) Close() error {
if f.closed {
return io.ErrClosedPipe
}
var lastBlock *hdfs.ExtendedBlockProto
if f.blockWriter != nil {
// Close the blockWriter, flushing any buffered packets.
err := f.blockWriter.Close()
if err != nil {
return err
}
lastBlock = f.block.GetB()
}
completeReq := &hdfs.CompleteRequestProto{
Src: proto.String(f.name),
ClientName: proto.String(f.client.namenode.ClientName()),
Last: lastBlock,
}
completeResp := &hdfs.CompleteResponseProto{}
err := f.client.namenode.Execute("complete", completeReq, completeResp)
if err != nil {
return &os.PathError{"create", f.name, err}
}
return nil
}
示例15: WriteResponse
// WriteResponse encodes and sends a net/rpc response header r with body x.
func (c *serverCodec) WriteResponse(r *rpc.Response, x interface{}) error {
// This is similar to WriteRequest(), above.
var encodeErr error
var hdr ProtoRPCResponseHeader
hdr.Op = proto.String(r.ServiceMethod)
hdr.Seq = proto.Uint64(r.Seq)
var body proto.Message
var ok bool
if r.Error != "" {
// Error responses have empty body. In this case, x can be an empty struct
// from net/rpc.Server, and net/rpc.Client will discard the body in any
// case, so leave body == nil.
hdr.Error = proto.String(r.Error)
} else if body, ok = x.(proto.Message); !ok || body == nil {
// If x isn't a protobuf, or is a nil protobuf, turn reply into an error and
// leave body == nil.
encodeErr = ErrBadResponseType
msg := encodeErr.Error()
hdr.Error = &msg
}
c.sending.Lock()
_, err := c.m.WriteMessage(&hdr) // writes htonl(length), marshal(hdr)
if err == nil {
_, err = c.m.WriteMessage(body) // writes htonl(length), marshal(body)
}
c.sending.Unlock()
if encodeErr != nil {
err = encodeErr
}
return util.Logged(err)
}