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


Golang vdl.Type类代码示例

本文整理汇总了Golang中v/io/v23/vdl.Type的典型用法代码示例。如果您正苦于以下问题:Golang Type类的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: FromEnumLabel

func (t target) FromEnumLabel(src string, tt *vdl.Type) error {
	// enums in mojo are treated as an int32 on the wire (but have gaps in their values).
	// This implementation assumes that we will use generated VDL values and not have gaps.
	index := tt.EnumIndex(src)
	binary.LittleEndian.PutUint32(t.current.Bytes(), uint32(index))
	return nil
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:7,代码来源:target.go

示例2: neededStructAllocationSize

func neededStructAllocationSize(vt *vdl.Type) uint32 {
	var totalBits uint32
	for fi := 0; fi < vt.NumField(); fi++ {
		field := vt.Field(fi)
		totalBits += baseTypeSizeBits(field.Type)
	}
	return roundBitsTo64Alignment(totalBits)
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:8,代码来源:allocation_size.go

示例3: FromFloat

func (t target) FromFloat(src float64, tt *vdl.Type) error {
	switch tt.Kind() {
	case vdl.Float32:
		binary.LittleEndian.PutUint32(t.current.Bytes(), math.Float32bits(float32(src)))
	case vdl.Float64:
		binary.LittleEndian.PutUint64(t.current.Bytes(), math.Float64bits(src))
	default:
		return fmt.Errorf("invalid FromFloat(%v, %v)", src, tt)
	}
	return nil
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:11,代码来源:target.go

示例4: FromInt

func (t target) FromInt(src int64, tt *vdl.Type) error {
	switch tt.Kind() {
	case vdl.Int8:
		t.current.Bytes()[0] = byte(src)
	case vdl.Int16:
		binary.LittleEndian.PutUint16(t.current.Bytes(), uint16(src))
	case vdl.Int32:
		binary.LittleEndian.PutUint32(t.current.Bytes(), uint32(src))
	case vdl.Int64:
		binary.LittleEndian.PutUint64(t.current.Bytes(), uint64(src))
	default:
		return fmt.Errorf("invalid FromInt(%v, %v)", src, tt)
	}
	return nil
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:15,代码来源:target.go

示例5: baseTypeSizeBits

func baseTypeSizeBits(vt *vdl.Type) uint32 {
	switch vt.Kind() {
	case vdl.Bool:
		return 1
	case vdl.Byte, vdl.Int8:
		return 8
	case vdl.Uint16, vdl.Int16:
		return 16
	case vdl.Uint32, vdl.Int32, vdl.Float32, vdl.Enum:
		return 32
	case vdl.Union:
		return 128 // Header + value / pointer to inner union
	default: // Either Uint64, Int64, Float64 or pointer.
		return 64
	}
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:16,代码来源:allocation_size.go

示例6: StartSet

// TODO(bprosnitz) This uses list, should we use map instead?
func (t target) StartSet(tt *vdl.Type, len int) (vdl.SetTarget, error) {
	if tt.Kind() == vdl.Optional {
		tt = tt.Elem()
	}
	bitsNeeded := baseTypeSizeBits(tt.Key()) * uint32(len)
	block := t.allocator().Allocate((bitsNeeded+7)/8, uint32(len))
	t.writePointer(block)
	if tt.Key().Kind() == vdl.Bool {
		return &bitListTarget{
			block: block,
		}, nil
	} else {
		return &listTarget{
			incrementSize: baseTypeSizeBits(tt.Key()) / 8,
			block:         block,
		}, nil
	}
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:19,代码来源:target.go

示例7: structType

func structType(t *vdl.Type, mp map[string]mojom_types.UserDefinedType) mojom_types.UserDefinedType {
	structFields := make([]mojom_types.StructField, t.NumField())
	for i := 0; i < t.NumField(); i++ {
		structFields[i] = mojom_types.StructField{
			DeclData: &mojom_types.DeclarationData{ShortName: strPtr(t.Field(i).Name)},
			Type:     vdlToMojomTypeInternal(t.Field(i).Type, false, false, mp),
			Offset:   0, // Despite the fact that we can calculated the offset, set it to zero to match the generator
		}
	}
	_, name := vdl.SplitIdent(t.Name())
	return &mojom_types.UserDefinedTypeStructType{
		mojom_types.MojomStruct{
			DeclData: &mojom_types.DeclarationData{
				ShortName:      strPtr(name),
				FullIdentifier: strPtr(mojomIdentifier(t)),
			},
			Fields: structFields,
		},
	}
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:20,代码来源:type.go

示例8: unionType

func unionType(t *vdl.Type, mp map[string]mojom_types.UserDefinedType) mojom_types.UserDefinedType {
	unionFields := make([]mojom_types.UnionField, t.NumField())
	for i := 0; i < t.NumField(); i++ {
		unionFields[i] = mojom_types.UnionField{
			DeclData: &mojom_types.DeclarationData{ShortName: strPtr(t.Field(i).Name)},
			Type:     vdlToMojomTypeInternal(t.Field(i).Type, false, false, mp),
			Tag:      uint32(i),
		}
	}
	_, name := vdl.SplitIdent(t.Name())
	return &mojom_types.UserDefinedTypeUnionType{
		mojom_types.MojomUnion{
			DeclData: &mojom_types.DeclarationData{
				ShortName:      strPtr(name),
				FullIdentifier: strPtr(mojomIdentifier(t)),
			},
			Fields: unionFields,
		},
	}
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:20,代码来源:type.go

示例9: computeStructLayout

// computeStructLayout computes a representation of the fields in a struct, as
// a list ordered by mojom byte field order.
func computeStructLayout(t *vdl.Type) (layout structLayout) {
	a := structBitAllocation{}

	for i := 0; i < t.NumField(); i++ {
		bits := baseTypeSizeBits(t.Field(i).Type)
		a = allocateStructBits(a, i+1, int(bits))
	}

	lastVal := 0
	for i, v := range a {
		if v != lastVal && v != 0 {
			layout = append(layout, structLayoutField{
				vdlStructIndex: v - 1,
				byteOffset:     uint32(i / 8),
				bitOffset:      uint8(i % 8),
			})
			lastVal = v
		}
	}

	return
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:24,代码来源:struct_layout.go

示例10: addUserDefinedType

func addUserDefinedType(t *vdl.Type, mp map[string]mojom_types.UserDefinedType) string {
	key := mojomTypeKey(t)
	if _, ok := mp[key]; ok {
		return key
	}
	mp[key] = nil // placeholder to stop recursion

	var udt mojom_types.UserDefinedType
	switch t.Kind() {
	case vdl.Struct:
		udt = structType(t, mp)
	case vdl.Union:
		udt = unionType(t, mp)
	case vdl.Enum:
		udt = enumType(t)
	default:
		panic(fmt.Sprintf("conversion from VDL kind %v to mojom user defined type not implemented", t.Kind()))
	}

	mp[key] = udt
	return key
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:22,代码来源:type.go

示例11: enumType

func enumType(t *vdl.Type) mojom_types.UserDefinedType {
	enumValues := make([]mojom_types.EnumValue, t.NumEnumLabel())
	for i := 0; i < t.NumEnumLabel(); i++ {
		enumValues[i] = mojom_types.EnumValue{
			DeclData: &mojom_types.DeclarationData{ShortName: strPtr(t.EnumLabel(i))},
			IntValue: int32(i),
		}
	}
	_, name := vdl.SplitIdent(t.Name())
	return &mojom_types.UserDefinedTypeEnumType{
		mojom_types.MojomEnum{
			DeclData: &mojom_types.DeclarationData{
				ShortName:      strPtr(name),
				FullIdentifier: strPtr(mojomIdentifier(t)),
			},
			Values: enumValues,
		},
	}
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:19,代码来源:type.go

示例12: StartFields

func (t target) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) {
	if tt.Kind() == vdl.Optional {
		tt = tt.Elem()
	}
	if tt.Kind() == vdl.Union {
		return unionFieldsTarget{
			vdlType: tt,
			block:   t.current,
		}, nil
	}
	fieldsTarget, block, err := structFieldShared(tt, t.allocator(), true)
	t.writePointer(block)
	return fieldsTarget, err

}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:15,代码来源:target.go

示例13: StartMap

func (t target) StartMap(tt *vdl.Type, len int) (vdl.MapTarget, error) {
	if tt.Kind() == vdl.Optional {
		tt = tt.Elem()
	}
	pointerBlock := t.allocator().Allocate(16, 0)
	t.writePointer(pointerBlock)

	st := target{
		current: pointerBlock.Slice(0, 8),
	}
	keys, err := st.StartSet(vdl.SetType(tt.Key()), len)
	if err != nil {
		return nil, err
	}
	valuePlaceholder := target{
		current: pointerBlock.Slice(8, 16),
	}
	return &mapTarget{
		keys:             keys,
		valuePlaceholder: valuePlaceholder,
		valueType:        tt.Elem(),
	}, nil
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:23,代码来源:target.go

示例14: JoinRawBytesAsStruct

func JoinRawBytesAsStruct(targ vdl.Target, structType *vdl.Type, fields []*vom.RawBytes) error {
	st, err := targ.StartFields(structType)
	if err != nil {
		return err
	}
	if structType.NumField() != len(fields) {
		return fmt.Errorf("received %d fields, but %v has %d fields", len(fields), structType, structType.NumField())
	}
	for i := 0; i < structType.NumField(); i++ {
		f := structType.Field(i)
		k, t, err := st.StartField(f.Name)
		if err != nil {
			return err
		}
		if err := fields[i].FillVDLTarget(t, f.Type); err != nil {
			return err
		}
		if err := st.FinishField(k, t); err != nil {
			return err
		}
	}
	return targ.FinishFields(st)
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:23,代码来源:util.go

示例15: mojomIdentifier

func mojomIdentifier(t *vdl.Type) string {
	return strings.Replace(t.Name(), "/", ".", -1)
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:3,代码来源:type.go


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