當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Field.GetValueType方法代碼示例

本文整理匯總了Golang中github.com/mozilla-services/heka/message.Field.GetValueType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Field.GetValueType方法的具體用法?Golang Field.GetValueType怎麽用?Golang Field.GetValueType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mozilla-services/heka/message.Field的用法示例。


在下文中一共展示了Field.GetValueType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
開發者ID:hellcoderz,項目名稱:heka,代碼行數:48,代碼來源:lua_sandbox.go

示例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 ""
}
開發者ID:Nitro,項目名稱:heka,代碼行數:42,代碼來源:kafka_output.go

示例3: writeField

func writeField(first bool, b *bytes.Buffer, f *message.Field, raw bool) {
	if !first {
		b.WriteString(`,`)
	}

	writeQuotedString(b, f.GetName())
	b.WriteString(`:`)

	switch f.GetValueType() {
	case message.Field_STRING:
		values := f.GetValueString()
		if len(values) > 1 {
			b.WriteString(`[`)
			for i, value := range values {
				if raw {
					b.WriteString(value)
				} else {
					writeQuotedString(b, value)
				}
				if i < len(values)-1 {
					b.WriteString(`,`)
				}
			}
			b.WriteString(`]`)
		} else {
			if raw {
				b.WriteString(values[0])
			} else {
				writeQuotedString(b, values[0])
			}
		}
	case message.Field_BYTES:
		values := f.GetValueBytes()
		if len(values) > 1 {
			b.WriteString(`[`)
			for i, value := range values {
				if raw {
					b.WriteString(string(value))
				} else {
					writeQuotedString(b, base64.StdEncoding.EncodeToString(value))
				}
				if i < len(values)-1 {
					b.WriteString(`,`)
				}
			}
			b.WriteString(`]`)
		} else {
			if raw {
				b.WriteString(string(values[0]))
			} else {
				writeQuotedString(b, string(values[0]))
			}
		}
	case message.Field_INTEGER:
		values := f.GetValueInteger()
		if len(values) > 1 {
			b.WriteString(`[`)
			for i, value := range values {
				b.WriteString(strconv.FormatInt(value, 10))
				if i < len(values)-1 {
					b.WriteString(`,`)
				}
			}
			b.WriteString(`]`)
		} else {
			b.WriteString(strconv.FormatInt(values[0], 10))
		}
	case message.Field_DOUBLE:
		values := f.GetValueDouble()
		if len(values) > 1 {
			b.WriteString(`[`)
			for i, value := range values {
				b.WriteString(strconv.FormatFloat(value, 'g', -1, 64))
				if i < len(values)-1 {
					b.WriteString(`,`)
				}
			}
			b.WriteString(`]`)
		} else {
			b.WriteString(strconv.FormatFloat(values[0], 'g', -1, 64))
		}
	case message.Field_BOOL:
		values := f.GetValueBool()
		if len(values) > 1 {
			b.WriteString(`[`)
			for i, value := range values {
				b.WriteString(strconv.FormatBool(value))
				if i < len(values)-1 {
					b.WriteString(`,`)
				}
			}
			b.WriteString(`]`)
		} else {
			b.WriteString(strconv.FormatBool(values[0]))
		}
	}
}
開發者ID:orangemi,項目名稱:heka,代碼行數:97,代碼來源:encoders.go


注:本文中的github.com/mozilla-services/heka/message.Field.GetValueType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。