| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // This file was auto-generated by the vanadium vdl tool. |
| // Package: uniqueid |
| |
| package uniqueid |
| |
| import ( |
| "fmt" |
| "v.io/v23/vdl" |
| ) |
| |
| var _ = __VDLInit() // Must be first; see __VDLInit comments for details. |
| |
| ////////////////////////////////////////////////// |
| // Type definitions |
| |
| // An Id is a likely globally unique identifier. |
| type Id [16]byte |
| |
| func (Id) __VDLReflect(struct { |
| Name string `vdl:"v.io/v23/uniqueid.Id"` |
| }) { |
| } |
| |
| func (m *Id) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| if err := t.FromBytes([]byte((*m)[:]), tt); err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func (m *Id) MakeVDLTarget() vdl.Target { |
| return &IdTarget{Value: m} |
| } |
| |
| type IdTarget struct { |
| Value *Id |
| vdl.TargetBase |
| } |
| |
| func (t *IdTarget) FromBytes(src []byte, tt *vdl.Type) error { |
| |
| if ttWant := vdl.TypeOf((*Id)(nil)); !vdl.Compatible(tt, ttWant) { |
| return fmt.Errorf("type %v incompatible with %v", tt, ttWant) |
| } |
| copy((*t.Value)[:], src) |
| |
| return nil |
| } |
| |
| func (x *Id) VDLRead(dec vdl.Decoder) error { |
| var err error |
| if err = dec.StartValue(); err != nil { |
| return err |
| } |
| bytes := x[:] |
| if err = dec.DecodeBytes(16, &bytes); err != nil { |
| return err |
| } |
| return dec.FinishValue() |
| } |
| |
| func (x Id) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(vdl.TypeOf((*Id)(nil))); err != nil { |
| return err |
| } |
| if err := enc.EncodeBytes([]byte(x[:])); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| var __VDLInitCalled bool |
| |
| // __VDLInit performs vdl initialization. It is safe to call multiple times. |
| // If you have an init ordering issue, just insert the following line verbatim |
| // into your source files in this package, right after the "package foo" clause: |
| // |
| // var _ = __VDLInit() |
| // |
| // The purpose of this function is to ensure that vdl initialization occurs in |
| // the right order, and very early in the init sequence. In particular, vdl |
| // registration and package variable initialization needs to occur before |
| // functions like vdl.TypeOf will work properly. |
| // |
| // This function returns a dummy value, so that it can be used to initialize the |
| // first var in the file, to take advantage of Go's defined init order. |
| func __VDLInit() struct{} { |
| if __VDLInitCalled { |
| return struct{}{} |
| } |
| __VDLInitCalled = true |
| |
| // Register types. |
| vdl.Register((*Id)(nil)) |
| |
| return struct{}{} |
| } |