本文整理匯總了Golang中github.com/gogo/protobuf/proto.Int64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Int64函數的具體用法?Golang Int64怎麽用?Golang Int64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Int64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestProto3SetDefaults
func TestProto3SetDefaults(t *testing.T) {
in := &pb.Message{
Terrain: map[string]*pb.Nested{
"meadow": new(pb.Nested),
},
Proto2Field: new(tpb.SubDefaults),
Proto2Value: map[string]*tpb.SubDefaults{
"badlands": new(tpb.SubDefaults),
},
}
got := proto.Clone(in).(*pb.Message)
proto.SetDefaults(got)
// There are no defaults in proto3. Everything should be the zero value, but
// we need to remember to set defaults for nested proto2 messages.
want := &pb.Message{
Terrain: map[string]*pb.Nested{
"meadow": new(pb.Nested),
},
Proto2Field: &tpb.SubDefaults{N: proto.Int64(7)},
Proto2Value: map[string]*tpb.SubDefaults{
"badlands": {N: proto.Int64(7)},
},
}
if !proto.Equal(got, want) {
t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want)
}
}
示例2: TestUnmarshalPartiallyPopulatedOptionalFieldsFails
func TestUnmarshalPartiallyPopulatedOptionalFieldsFails(t *testing.T) {
// Fill in all fields, then randomly remove one.
dataOut := &test.NinOptNative{
Field1: proto.Float64(0),
Field2: proto.Float32(0),
Field3: proto.Int32(0),
Field4: proto.Int64(0),
Field5: proto.Uint32(0),
Field6: proto.Uint64(0),
Field7: proto.Int32(0),
Field8: proto.Int64(0),
Field9: proto.Uint32(0),
Field10: proto.Int32(0),
Field11: proto.Uint64(0),
Field12: proto.Int64(0),
Field13: proto.Bool(false),
Field14: proto.String("0"),
Field15: []byte("0"),
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
fieldName := "Field" + strconv.Itoa(r.Intn(15)+1)
field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName)
fieldType := field.Type()
field.Set(reflect.Zero(fieldType))
encodedMessage, err := proto.Marshal(dataOut)
if err != nil {
t.Fatalf("Unexpected error when marshalling dataOut: %v", err)
}
dataIn := NidOptNative{}
err = proto.Unmarshal(encodedMessage, &dataIn)
if err.Error() != `proto: required field "`+fieldName+`" not set` {
t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error())
}
}
示例3: createStartStopMessage
func createStartStopMessage(requestId uint64, peerType events.PeerType) *events.Envelope {
return &events.Envelope{
Origin: proto.String("fake-origin-2"),
EventType: events.Envelope_HttpStartStop.Enum(),
HttpStartStop: &events.HttpStartStop{
StartTimestamp: proto.Int64(1),
StopTimestamp: proto.Int64(100),
RequestId: &events.UUID{
Low: proto.Uint64(requestId),
High: proto.Uint64(requestId + 1),
},
PeerType: &peerType,
Method: events.Method_GET.Enum(),
Uri: proto.String("fake-uri-1"),
RemoteAddress: proto.String("fake-remote-addr-1"),
UserAgent: proto.String("fake-user-agent-1"),
StatusCode: proto.Int32(103),
ContentLength: proto.Int64(104),
ParentRequestId: &events.UUID{
Low: proto.Uint64(2),
High: proto.Uint64(3),
},
ApplicationId: &events.UUID{
Low: proto.Uint64(105),
High: proto.Uint64(106),
},
InstanceIndex: proto.Int32(6),
InstanceId: proto.String("fake-instance-id-1"),
},
}
}
示例4: NewHttpStartStop
func NewHttpStartStop(req *http.Request, statusCode int, contentLength int64, peerType events.PeerType, requestId *uuid.UUID) *events.HttpStartStop {
now := proto.Int64(time.Now().UnixNano())
httpStartStop := &events.HttpStartStop{
StartTimestamp: now,
StopTimestamp: now,
RequestId: NewUUID(requestId),
PeerType: &peerType,
Method: events.Method(events.Method_value[req.Method]).Enum(),
Uri: proto.String(fmt.Sprintf("%s://%s%s", scheme(req), req.Host, req.URL.Path)),
RemoteAddress: proto.String(req.RemoteAddr),
UserAgent: proto.String(req.UserAgent()),
StatusCode: proto.Int(statusCode),
ContentLength: proto.Int64(contentLength),
}
if applicationId, err := uuid.ParseHex(req.Header.Get("X-CF-ApplicationID")); err == nil {
httpStartStop.ApplicationId = NewUUID(applicationId)
}
if instanceIndex, err := strconv.Atoi(req.Header.Get("X-CF-InstanceIndex")); err == nil {
httpStartStop.InstanceIndex = proto.Int(instanceIndex)
}
if instanceId := req.Header.Get("X-CF-InstanceID"); instanceId != "" {
httpStartStop.InstanceId = proto.String(instanceId)
}
allForwards := req.Header[http.CanonicalHeaderKey("X-Forwarded-For")]
for _, forwarded := range allForwards {
httpStartStop.Forwarded = append(httpStartStop.Forwarded, parseXForwarded(forwarded)...)
}
return httpStartStop
}
示例5: createDomain
func createDomain(fields []string, in *pb.Domain) error {
if len(fields) > 5 {
return fmt.Errorf("Too many argumets, expected 4 got %d", len(fields))
}
// FIXME make last 2 arguments optional
capa, err := strconv.Atoi(fields[3])
if err != nil {
return fmt.Errorf("Expected 3rd argument to be of type int: %q", err)
}
size, err := strconv.Atoi(fields[4])
if err != nil {
return fmt.Errorf("Expected last argument to be of type int: %q", err)
}
types := []pb.SketchType{pb.SketchType_MEMB, pb.SketchType_FREQ, pb.SketchType_RANK, pb.SketchType_CARD}
for _, ty := range types {
sketch := &pb.Sketch{}
sketch.Name = proto.String("")
sketch.Type = &ty
sketch.Properties = &pb.SketchProperties{
Size: proto.Int64(int64(size)),
MaxUniqueItems: proto.Int64(int64(capa)),
}
in.Sketches = append(in.Sketches, sketch)
}
_, err = client.CreateDomain(context.Background(), in)
return err
}
示例6: encodeLogMessage
func (d *DroppedCounter) encodeLogMessage(droppedCount int64) []byte {
now := time.Now()
message := &events.Envelope{
Origin: proto.String(d.origin),
Timestamp: proto.Int64(now.UnixNano()),
Ip: proto.String(d.ip),
Deployment: proto.String(d.conf.Deployment),
Index: proto.String(d.conf.Index),
Job: proto.String(d.conf.Job),
EventType: events.Envelope_LogMessage.Enum(),
LogMessage: &events.LogMessage{
MessageType: events.LogMessage_ERR.Enum(),
Timestamp: proto.Int64(now.UnixNano()),
AppId: proto.String(envelope_extensions.SystemAppId),
Message: []byte(fmt.Sprintf("Dropped %d message(s) from MetronAgent to Doppler", droppedCount)),
SourceType: metSourceType,
},
}
bytes, err := message.Marshal()
if err != nil {
d.incrementer.BatchIncrementCounter("droppedCounter.sendErrors")
d.timer.Reset(time.Millisecond)
return nil
}
return prefixMessage(bytes)
}
示例7: TestCreateAddDeleteAddSketch
func TestCreateAddDeleteAddSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
client, conn := setupClient()
defer tearDownClient(conn)
typ := pb.SketchType_CARD
name := "yoyo"
in := &pb.Sketch{
Name: proto.String(name),
Type: &typ,
Properties: &pb.SketchProperties{
MaxUniqueItems: proto.Int64(1337), // FIXME: Allow default as -1
Size: proto.Int64(7),
},
}
addReq := &pb.AddRequest{
Sketch: in,
Values: []string{"a", "b", "c", "d", "a", "b"},
}
if _, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
typ = pb.SketchType_RANK
if _, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
if _, err := client.Add(context.Background(), addReq); err != nil {
t.Error("Did not expect error, got", err)
}
if res, err := client.ListAll(context.Background(), &pb.Empty{}); err != nil {
t.Error("Did not expect error, got", err)
} else if len(res.GetSketches()) != 2 {
t.Error("Expected len(res) == 2, got ", len(res.GetSketches()))
}
if _, err := client.DeleteSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
if _, err := client.Add(context.Background(), addReq); err == nil {
t.Error("Expected error, got", err)
}
if res, err := client.ListAll(context.Background(), &pb.Empty{}); err != nil {
t.Error("Did not expect error, got", err)
} else if len(res.GetSketches()) != 1 {
t.Error("Expected len(res) == 1, got ", len(res.GetSketches()))
}
}
示例8: getSketchInfo
func getSketchInfo(in *pb.Sketch) error {
in.Properties = &pb.SketchProperties{
MaxUniqueItems: proto.Int64(0),
Size: proto.Int64(0),
}
reply, err := client.GetSketch(context.Background(), in)
fmt.Println(reply)
return err
}
示例9: TestAddGetFreqSketch
func TestAddGetFreqSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
client, conn := setupClient()
defer tearDownClient(conn)
typ := pb.SketchType_FREQ
name := "yoyo"
in := &pb.Sketch{
Name: proto.String(name),
Type: &typ,
Properties: &pb.SketchProperties{
MaxUniqueItems: proto.Int64(1337), // FIXME: Allow default as -1
Size: proto.Int64(7),
},
}
if res, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
} else if res.GetName() != in.GetName() {
t.Errorf("Expected name == %s, got %s", in.GetName(), res.GetName())
} else if res.GetType() != in.GetType() {
t.Errorf("Expected name == %q, got %q", in.GetType(), res.GetType())
}
addReq := &pb.AddRequest{
Sketch: in,
Values: []string{"a", "a", "b", "c", "d"},
}
expected := map[string]int64{
"a": 2, "b": 1, "c": 1, "d": 1, "e": 0,
}
if _, err := client.Add(context.Background(), addReq); err != nil {
t.Error("Did not expect error, got", err)
}
getReq := &pb.GetRequest{
Sketches: []*pb.Sketch{in},
Values: []string{"a", "b", "c", "d", "e", "b"},
}
if res, err := client.GetFrequency(context.Background(), getReq); err != nil {
t.Error("Did not expect error, got", err)
} else {
for _, v := range res.GetResults()[0].GetFrequencies() {
if expected[v.GetValue()] != v.GetCount() {
t.Errorf("Expected %s == %d, got", v.GetValue(), v.GetCount())
}
}
}
}
示例10: Send
// Send sends the log message with the envelope timestamp set to now and the
// log message timestamp set to now if none was provided by SetTimestamp.
func (c logChainer) Send() error {
metrics.BatchIncrementCounter("logSenderTotalMessagesRead")
c.envelope.Timestamp = proto.Int64(time.Now().UnixNano())
if c.envelope.LogMessage.Timestamp == nil {
c.envelope.LogMessage.Timestamp = proto.Int64(time.Now().UnixNano())
}
return c.emitter.EmitEnvelope(c.envelope)
}
示例11: EventToPbEvent
// Code taken from github.com/bigdatadev/goryman
func EventToPbEvent(event *Event) (*proto.Event, error) {
var e proto.Event
t := reflect.ValueOf(&e).Elem()
s := reflect.ValueOf(event).Elem()
typeOfEvent := s.Type()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
value := reflect.ValueOf(f.Interface())
if reflect.Zero(f.Type()) != value && f.Interface() != nil {
name := typeOfEvent.Field(i).Name
switch name {
case "State", "Service", "Host", "Description":
tmp := reflect.ValueOf(pb.String(value.String()))
t.FieldByName(name).Set(tmp)
case "Ttl":
tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
t.FieldByName(name).Set(tmp)
case "Time":
tmp := reflect.ValueOf(pb.Int64(value.Int()))
t.FieldByName(name).Set(tmp)
case "Tags":
tmp := reflect.ValueOf(value.Interface().([]string))
t.FieldByName(name).Set(tmp)
case "Metric":
switch reflect.TypeOf(f.Interface()).Kind() {
case reflect.Int:
tmp := reflect.ValueOf(pb.Int64(int64(value.Int())))
t.FieldByName("MetricSint64").Set(tmp)
case reflect.Float32:
tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
t.FieldByName("MetricF").Set(tmp)
case reflect.Float64:
tmp := reflect.ValueOf(pb.Float64(value.Float()))
t.FieldByName("MetricD").Set(tmp)
default:
return nil, fmt.Errorf("Metric of invalid type (type %v)",
reflect.TypeOf(f.Interface()).Kind())
}
case "Attributes":
var attrs []*proto.Attribute
for k, v := range value.Interface().(map[string]string) {
k_, v_ := k, v
attrs = append(attrs, &proto.Attribute{
Key: &k_,
Value: &v_,
})
}
t.FieldByName(name).Set(reflect.ValueOf(attrs))
}
}
}
return &e, nil
}
示例12: encodeIntegerPoint
func encodeIntegerPoint(p *IntegerPoint) *internal.Point {
return &internal.Point{
Name: proto.String(p.Name),
Tags: proto.String(p.Tags.ID()),
Time: proto.Int64(p.Time),
Nil: proto.Bool(p.Nil),
Aux: encodeAux(p.Aux),
IntegerValue: proto.Int64(p.Value),
}
}
示例13: MarshalBinary
// MarshalBinary encodes r to a binary format.
func (r *CreateIteratorResponse) MarshalBinary() ([]byte, error) {
var pb internal.CreateIteratorResponse
if r.Err != nil {
pb.Err = proto.String(r.Err.Error())
}
pb.Type = proto.Int32(int32(r.Type))
pb.Stats = &internal.IteratorStats{
SeriesN: proto.Int64(int64(r.Stats.SeriesN)),
PointN: proto.Int64(int64(r.Stats.PointN)),
}
return proto.Marshal(&pb)
}
示例14: init
func init() {
f := float64(0.123)
if err := proto.SetExtension(AContainer, E_FieldA, &f); err != nil {
panic(err)
}
if err := proto.SetExtension(AContainer, E_FieldB, &Small{SmallField: proto.Int64(456)}); err != nil {
panic(err)
}
if err := proto.SetExtension(AContainer, E_FieldC, &Big{BigField: proto.Int64(789)}); err != nil {
panic(err)
}
}
示例15: createLogEnvelope
func createLogEnvelope(message, appId string) *events.Envelope {
return &events.Envelope{
EventType: events.Envelope_LogMessage.Enum(),
Origin: proto.String(helpers.ORIGIN_NAME),
Timestamp: proto.Int64(time.Now().UnixNano()),
LogMessage: &events.LogMessage{
Message: []byte(message),
MessageType: events.LogMessage_OUT.Enum(),
Timestamp: proto.Int64(time.Now().UnixNano()),
AppId: proto.String(appId),
},
}
}