Beispiel #1
0
func (d *decoder) decodeStruct(src hl7.Data, dst reflect.Value) {
	typ := dst.Type()
	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)
		fieldName := field.Name
		fieldValue := dst.FieldByName(fieldName)

		// So just skip it.
		if !fieldValue.CanSet() {
			d.err.append(fmt.Errorf("%s.%s is not settable", typ.Name(), fieldName))
			continue
		}

		index := i
		if _, ok := src.(hl7.Segment); ok {
			index += 1
		}

		newSrc, ok := src.Index(index)
		if !ok {
			//d.err.append(fmt.Errorf("could not find src index for %s.%s", typ.Name(), fieldName))
			continue
		}

		d.decode(newSrc, fieldValue)
	}
}
Beispiel #2
0
func stringIndex(data hl7.Data, n int) string {
	if v, ok := data.Index(n); ok {
		if v2, ok2 := v.(hl7.Field); ok2 {
			return string(v2)
		}
	}

	return ""
}
Beispiel #3
0
func (d *decoder) decodeSlice(src hl7.Data, dst reflect.Value) {
	dstType := dst.Type()
	dstElemType := dstType.Elem()
	sliceType := reflect.SliceOf(dstElemType)

	srcLen := src.Len()
	dstSlice := reflect.MakeSlice(sliceType, srcLen, srcLen)
	for i := 0; i < srcLen; i++ {
		currentField := dstSlice.Index(i)
		if newSrc, ok := src.Index(i); ok {
			d.decode(newSrc, currentField)
		}
	}

	dst.Set(dstSlice)
}