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


Golang Type.Key方法代碼示例

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


在下文中一共展示了Type.Key方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: vdlToMojomTypeInternal

func vdlToMojomTypeInternal(t *vdl.Type, outermostType bool, nullable bool, mp map[string]mojom_types.UserDefinedType) (mojomtype mojom_types.Type) {
	switch t.Kind() {
	case vdl.Bool, vdl.Float64, vdl.Float32, vdl.Int8, vdl.Int16, vdl.Int32, vdl.Int64, vdl.Byte, vdl.Uint16, vdl.Uint32, vdl.Uint64:
		return &mojom_types.TypeSimpleType{
			simpleTypeCode(t.Kind()),
		}
	case vdl.String:
		return &mojom_types.TypeStringType{
			stringType(nullable),
		}
	case vdl.Array:
		elem := vdlToMojomTypeInternal(t.Elem(), false, false, mp)
		return &mojom_types.TypeArrayType{
			arrayType(elem, nullable, t.Len()),
		}
	case vdl.List:
		elem := vdlToMojomTypeInternal(t.Elem(), false, false, mp)
		return &mojom_types.TypeArrayType{
			listType(elem, nullable),
		}
	case vdl.Map:
		key := vdlToMojomTypeInternal(t.Key(), false, false, mp)
		elem := vdlToMojomTypeInternal(t.Elem(), false, false, mp)
		return &mojom_types.TypeMapType{
			mapType(key, elem, nullable),
		}
	case vdl.Struct, vdl.Union, vdl.Enum:
		udtKey := addUserDefinedType(t, mp)
		ret := &mojom_types.TypeTypeReference{
			mojom_types.TypeReference{
				Nullable: nullable,
				TypeKey:  &udtKey,
			},
		}
		if !outermostType {
			// This is needed to match the output of the generator exactly, the outermost type
			// is not given an identifier.
			ret.Value.Identifier = ret.Value.TypeKey
		}
		return ret
	case vdl.Optional:
		return vdlToMojomTypeInternal(t.Elem(), false, true, mp)
	default:
		panic(fmt.Sprintf("conversion from VDL kind %v to mojom type not implemented", t.Kind()))
	}
}
開發者ID:vanadium,項目名稱:mojo.v23proxy,代碼行數:46,代碼來源:type.go

示例2: 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

示例3: 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

示例4: transcodeValue


//.........這裏部分代碼省略.........
				return err
			}
			listTarget, err := target.StartList(vt, int(numElems))
			if err != nil {
				return err
			}
			for i := 0; i < int(numElems); i++ {
				elemTarget, err := listTarget.StartElem(i)
				if err != nil {
					return err
				}
				if err := mtv.transcodeValue(vt.Elem(), elemTarget, false, false); err != nil {
					return err
				}
				if err := listTarget.FinishElem(elemTarget); err != nil {
					return err
				}
			}
			if err := target.FinishList(listTarget); err != nil {
				return err
			}
		}
		return mtv.modec.Finish()
	case vdl.Set:
		panic("unimplemented")
		/*switch ptr, err := d.dec.ReadPointer(); {
		case err != nil:
			return err
		case ptr == 0 && isNullable:
			return target.FromNil(vdl.OptionalType(vt))
		case ptr == 0 && !isNullable:
			return fmt.Errorf("invalid null struct pointer")
		}
		keyBitSize := baseTypeSizeBits(vt.Key())
		numKeys, err := d.dec.StartArray(keyBitSize)
		if err != nil {
			return err
		}
		setTarget, err := target.StartSet(vt, int(numKeys))
		if err != nil {
			return err
		}
		for i := 0; i < int(numKeys); i++ {
			keyTarget, err := setTarget.StartKey()
			if err != nil {
				return err
			}
			if err := d.decodeValue(mt.Key, keyTarget, false, false); err != nil {
				return err
			}
			if err := setTarget.FinishKey(keyTarget); err != nil {
				return err
			}
		}
		if err := target.FinishSet(setTarget); err != nil {
			return err
		}
		return d.dec.Finish()*/
	case vdl.Map:
		switch ptr, err := mtv.modec.ReadPointer(); {
		case err != nil:
			return err
		case ptr == 0 && isNullable:
			return target.FromNil(vdl.OptionalType(vt))
		case ptr == 0 && !isNullable:
			return fmt.Errorf("invalid null struct pointer")
開發者ID:vanadium,項目名稱:mojo.v23proxy,代碼行數:67,代碼來源:from_mojom.go


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