本文整理匯總了Golang中github.com/mozilla-services/heka/message.Message.FindAllFields方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.FindAllFields方法的具體用法?Golang Message.FindAllFields怎麽用?Golang Message.FindAllFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/message.Message
的用法示例。
在下文中一共展示了Message.FindAllFields方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: lookup_field
func lookup_field(msg *message.Message, fn string, fi int, ai int) (int,
unsafe.Pointer, int) {
var field *message.Field
if fi != 0 {
fields := msg.FindAllFields(fn)
if fi >= len(fields) {
return 0, unsafe.Pointer(nil), 0
}
field = fields[fi]
} else {
if field = msg.FindFirstField(fn); field == nil {
return 0, unsafe.Pointer(nil), 0
}
}
fieldType := int(field.GetValueType())
switch field.GetValueType() {
case message.Field_STRING:
if ai >= len(field.ValueString) {
return fieldType, unsafe.Pointer(nil), 0
}
value := field.ValueString[ai]
cs := C.CString(value) // freed by the caller
return fieldType, unsafe.Pointer(cs), len(value)
case message.Field_BYTES:
if ai >= len(field.ValueBytes) {
return fieldType, unsafe.Pointer(nil), 0
}
value := field.ValueBytes[ai]
return fieldType, unsafe.Pointer(&field.ValueBytes[ai][0]), len(value)
case message.Field_INTEGER:
if ai >= len(field.ValueInteger) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueInteger[ai]), 0
case message.Field_DOUBLE:
if ai >= len(field.ValueDouble) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueDouble[ai]), 0
case message.Field_BOOL:
if ai >= len(field.ValueBool) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueBool[ai]), 0
}
return 0, unsafe.Pointer(nil), 0
}
示例2: getFieldAsString
func getFieldAsString(msg *message.Message, mvar *messageVariable) string {
var field *message.Field
if mvar.fi != 0 {
fields := msg.FindAllFields(mvar.name)
if mvar.fi >= len(fields) {
return ""
}
field = fields[mvar.fi]
} else {
if field = msg.FindFirstField(mvar.name); field == nil {
return ""
}
}
switch field.GetValueType() {
case message.Field_STRING:
if mvar.ai >= len(field.ValueString) {
return ""
}
return field.ValueString[mvar.ai]
case message.Field_BYTES:
if mvar.ai >= len(field.ValueBytes) {
return ""
}
return string(field.ValueBytes[mvar.ai])
case message.Field_INTEGER:
if mvar.ai >= len(field.ValueInteger) {
return ""
}
return fmt.Sprintf("%d", field.ValueInteger[mvar.ai])
case message.Field_DOUBLE:
if mvar.ai >= len(field.ValueDouble) {
return ""
}
return fmt.Sprintf("%g", field.ValueDouble[mvar.ai])
case message.Field_BOOL:
if mvar.ai >= len(field.ValueBool) {
return ""
}
return fmt.Sprintf("%t", field.ValueBool[mvar.ai])
}
return ""
}