当前位置: 首页>>代码示例>>Golang>>正文


Golang Writer.WriteFloat方法代码示例

本文整理汇总了Golang中gopkg/in/istreamdata/orientgo/v2/obinary/rw.Writer.WriteFloat方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.WriteFloat方法的具体用法?Golang Writer.WriteFloat怎么用?Golang Writer.WriteFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gopkg/in/istreamdata/orientgo/v2/obinary/rw.Writer的用法示例。


在下文中一共展示了Writer.WriteFloat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: writeSingleValue

func (f binaryRecordFormatV0) writeSingleValue(w *rw.Writer, off int, o interface{}, tp, linkedType orient.OType) (err error) {
	defer func() {
		if r := recover(); r != nil {
			if ic, ok := r.(*runtime.TypeAssertionError); ok {
				err = fmt.Errorf("writeSingleValue(%T -> %v): %v", o, tp, ic)
			} else {
				panic(r)
			}
		}
	}()
	switch tp {
	case orient.BYTE:
		w.WriteByte(toByte(o))
	case orient.BOOLEAN:
		w.WriteBool(toBool(o))
	case orient.SHORT:
		w.WriteVarint(int64(toInt16(o)))
	case orient.INTEGER:
		w.WriteVarint(int64(toInt32(o)))
	case orient.LONG:
		w.WriteVarint(int64(toInt64(o)))
	case orient.STRING:
		f.writeString(w, toString(o))
	case orient.FLOAT:
		w.WriteFloat(o.(float32))
	case orient.DOUBLE:
		w.WriteDouble(o.(float64))
	case orient.DATETIME: // unix time in milliseconds
		if t, ok := o.(int64); ok {
			w.WriteVarint(t)
		} else {
			t := o.(time.Time)
			it := t.Unix()*1000 + int64(t.Nanosecond())/1e6
			w.WriteVarint(it)
		}
	case orient.DATE:
		if t, ok := o.(int64); ok {
			w.WriteVarint(t)
		} else {
			t := o.(time.Time)
			it := t.Unix()*1000 + int64(t.Nanosecond())/1e6
			var offset int64
			// TODO: int offset = ODateHelper.getDatabaseTimeZone().getOffset(dateValue)
			w.WriteVarint((it + offset) / millisecPerDay)
		}
	case orient.EMBEDDED:
		var edoc *orient.Document
		switch d := o.(type) {
		case orient.Document:
			edoc = &d
		case *orient.Document:
			edoc = d
		case orient.DocumentSerializable:
			edoc, err = o.(orient.DocumentSerializable).ToDocument()
			if err != nil {
				return
			}
			edoc.SetField(documentSerializableClassName, edoc.ClassName()) // TODO: pass empty value as nil?
		default:
			edoc = orient.NewEmptyDocument()
			if err = edoc.From(o); err != nil {
				return err
			}
			// TODO: set classname of struct?
		}
		err = f.Serialize(edoc, w, off, false)
	case orient.EMBEDDEDSET, orient.EMBEDDEDLIST:
		err = f.writeEmbeddedCollection(w, off, o, linkedType)
	case orient.DECIMAL:
		f.writeDecimal(w, o)
	case orient.BINARY:
		_, err = f.writeBinary(w, o.([]byte))
	case orient.LINKSET, orient.LINKLIST:
		err = f.writeLinkCollection(w, o)
	case orient.LINK:
		_, err = f.writeOptimizedLink(w, o.(orient.OIdentifiable))
	case orient.LINKMAP:
		err = f.writeLinkMap(w, o)
	case orient.EMBEDDEDMAP:
		err = f.writeEmbeddedMap(w, off, o)
	case orient.LINKBAG:
		err = o.(*orient.RidBag).ToStream(w)
	case orient.CUSTOM:
		val := o.(orient.CustomSerializable)
		f.writeString(w, val.GetClassName())
		err = val.ToStream(w)
	case orient.TRANSIENT, orient.ANY:
	default:
		panic(fmt.Errorf("unknown type: %v", tp))
	}
	if err == nil {
		err = w.Err()
	}
	return
}
开发者ID:josebalius,项目名称:orientgo,代码行数:95,代码来源:serializer_binary.go


注:本文中的gopkg/in/istreamdata/orientgo/v2/obinary/rw.Writer.WriteFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。