Merge "v23proxy: Add type argument to FillVDLTarget"
diff --git a/dart-examples/echo/lib/main.dart b/dart-examples/echo/lib/main.dart
index c572b3e..f607fb8 100644
--- a/dart-examples/echo/lib/main.dart
+++ b/dart-examples/echo/lib/main.dart
@@ -67,7 +67,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new Echo.fromHandle(appHandle);
 }
diff --git a/dart-examples/echo_server/lib/main.dart b/dart-examples/echo_server/lib/main.dart
index 4ae298a..0723db5 100644
--- a/dart-examples/echo_server/lib/main.dart
+++ b/dart-examples/echo_server/lib/main.dart
@@ -40,7 +40,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new EchoServer.fromHandle(appHandle);
 }
diff --git a/dart-examples/fortune/lib/main.dart b/dart-examples/fortune/lib/main.dart
index 53cc4f5..ae1a856 100644
--- a/dart-examples/fortune/lib/main.dart
+++ b/dart-examples/fortune/lib/main.dart
@@ -61,7 +61,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new Fortune.fromHandle(appHandle);
 }
diff --git a/dart-examples/fortune_server/lib/main.dart b/dart-examples/fortune_server/lib/main.dart
index f9484f8..1555472 100644
--- a/dart-examples/fortune_server/lib/main.dart
+++ b/dart-examples/fortune_server/lib/main.dart
@@ -54,7 +54,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new FortuneServer.fromHandle(appHandle);
 }
diff --git a/dart-tests/end_to_end_test/lib/client.dart b/dart-tests/end_to_end_test/lib/client.dart
index 3ab62af..23945de 100644
--- a/dart-tests/end_to_end_test/lib/client.dart
+++ b/dart-tests/end_to_end_test/lib/client.dart
@@ -108,7 +108,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new EndToEndTestClient.fromHandle(appHandle);
 }
diff --git a/dart-tests/end_to_end_test/lib/server.dart b/dart-tests/end_to_end_test/lib/server.dart
index 0b356bc..b579efa 100644
--- a/dart-tests/end_to_end_test/lib/server.dart
+++ b/dart-tests/end_to_end_test/lib/server.dart
@@ -85,7 +85,7 @@
   }
 }
 
-main(List args) {
-  MojoHandle appHandle = new MojoHandle(args[0]);
+main(List args, Object handleToken) {
+  MojoHandle appHandle = new MojoHandle(handleToken);
   new EndToEndTestServer.fromHandle(appHandle);
 }
diff --git a/dart-tests/end_to_end_test/pubspec.yaml b/dart-tests/end_to_end_test/pubspec.yaml
index 7904eb0..ce37580 100644
--- a/dart-tests/end_to_end_test/pubspec.yaml
+++ b/dart-tests/end_to_end_test/pubspec.yaml
@@ -4,7 +4,7 @@
 name: v23proxy_end_to_end_test
 version: 0.0.1
 dependencies:
-  mojo_sdk: 0.2.15
+  mojo_sdk: 0.2.16
   v23proxy: '>=0.0.1'
 environment:
   sdk: '>=1.12.0 <2.0.0'
diff --git a/go/src/v.io/x/mojo/proxy/clientproxy/clientproxy.go b/go/src/v.io/x/mojo/proxy/clientproxy/clientproxy.go
index 8b03fbc..9aa5f64 100644
--- a/go/src/v.io/x/mojo/proxy/clientproxy/clientproxy.go
+++ b/go/src/v.io/x/mojo/proxy/clientproxy/clientproxy.go
@@ -18,10 +18,10 @@
 	"v.io/v23/context"
 	"v.io/v23/options"
 	"v.io/v23/security"
+	"v.io/v23/vom"
 	"v.io/x/mojo/proxy/util"
 	"v.io/x/mojo/transcoder"
 	_ "v.io/x/ref/runtime/factories/roaming"
-	"v.io/v23/vom"
 )
 
 //#include "mojo/public/c/system/types.h"
@@ -148,7 +148,6 @@
 
 func (s *messageReceiver) call(name, method string, value []byte, inParamsType mojom_types.MojomStruct, outParamsType *mojom_types.MojomStruct) ([]byte, error) {
 	s.ctx.Infof("server: %s.%s: %#v", name, method, inParamsType)
-
 	inVType, err := transcoder.MojomStructToVDLType(inParamsType, s.header.desc)
 	if err != nil {
 		return nil, err
diff --git a/go/src/v.io/x/mojo/transcoder/type.go b/go/src/v.io/x/mojo/transcoder/type.go
index ab5bec0..6acf064 100644
--- a/go/src/v.io/x/mojo/transcoder/type.go
+++ b/go/src/v.io/x/mojo/transcoder/type.go
@@ -7,12 +7,23 @@
 import (
 	"fmt"
 	"strings"
+	"unicode"
+	"unicode/utf8"
 
 	"mojo/public/interfaces/bindings/mojom_types"
 
 	"v.io/v23/vdl"
 )
 
+// upperCamelCase converts thisString to ThisString.
+func upperCamelCase(s string) string {
+	if s == "" {
+		return ""
+	}
+	r, n := utf8.DecodeRuneInString(s)
+	return string(unicode.ToUpper(r)) + s[n:]
+}
+
 func MojomStructToVDLType(ms mojom_types.MojomStruct, mp map[string]mojom_types.UserDefinedType) (*vdl.Type, error) {
 	builder := &vdl.TypeBuilder{}
 	// Note: The type key is "" below because if there is a cycle, it will have a separate reference under a separate
@@ -35,10 +46,14 @@
 
 func mojomStructToVDLType(typeKey string, ms mojom_types.MojomStruct, mp map[string]mojom_types.UserDefinedType, builder *vdl.TypeBuilder, pendingUdts map[string]vdl.TypeOrPending) (vt vdl.PendingType) {
 	strct := builder.Struct()
-	vt = builder.Named(mojomToVdlPath(*ms.DeclData.FullIdentifier)).AssignBase(strct)
+	if ms.DeclData.FullIdentifier != nil {
+		vt = builder.Named(mojomToVdlPath(*ms.DeclData.FullIdentifier)).AssignBase(strct)
+	} else {
+		vt = strct
+	}
 	pendingUdts[typeKey] = vt
 	for _, mfield := range ms.Fields {
-		strct.AppendField(*mfield.DeclData.ShortName, mojomToVDLType(mfield.Type, mp, builder, pendingUdts))
+		strct.AppendField(upperCamelCase(*mfield.DeclData.ShortName), mojomToVDLType(mfield.Type, mp, builder, pendingUdts))
 	}
 	return
 }
@@ -54,7 +69,7 @@
 		for _, ev := range me.Values { // per EnumValue...
 			// EnumValue has DeclData, EnumTypeKey, and IntValue.
 			// We just need the first and last.
-			labels[int(ev.IntValue)] = *ev.DeclData.ShortName
+			labels[int(ev.IntValue)] = upperCamelCase(*ev.DeclData.ShortName)
 		}
 
 		vt = vdl.NamedType(mojomToVdlPath(*me.DeclData.FullIdentifier), vdl.EnumType(labels...))
@@ -68,7 +83,7 @@
 		vt = builder.Named(mojomToVdlPath(*mu.DeclData.FullIdentifier)).AssignBase(union)
 		pendingUdts[typeKey] = vt
 		for _, mfield := range mu.Fields {
-			union = union.AppendField(*mfield.DeclData.ShortName, mojomToVDLType(mfield.Type, mp, builder, pendingUdts))
+			union = union.AppendField(upperCamelCase(*mfield.DeclData.ShortName), mojomToVDLType(mfield.Type, mp, builder, pendingUdts))
 		}
 	case *mojom_types.UserDefinedTypeInterfaceType: // interface
 		panic("interfaces don't exist in vdl")
@@ -352,9 +367,7 @@
 // mojomTypeKey creates a key from the vdl type's name that matches the generator's key.
 // The reason for exactly matching the generator is to simplify the tests.
 func mojomTypeKey(t *vdl.Type) string {
-	pkgPath, name := vdl.SplitIdent(t.Name())
-	pathComponents := strings.Split(pkgPath, "/")
-	return fmt.Sprintf("%s_%s__", pathComponents[len(pathComponents)-1], name)
+	return fmt.Sprintf("TYPE_KEY:%s", mojomIdentifier(t))
 }
 
 func mojomIdentifier(t *vdl.Type) string {
diff --git a/go/src/v.io/x/mojo/transcoder/type_test.go b/go/src/v.io/x/mojo/transcoder/type_test.go
index fd46fd5..c717fb6 100644
--- a/go/src/v.io/x/mojo/transcoder/type_test.go
+++ b/go/src/v.io/x/mojo/transcoder/type_test.go
@@ -17,13 +17,13 @@
 func TestVdlAndMojoTypeConversion(t *testing.T) {
 	// Create types.
 	enumType := vdl.NamedType("v23proxy/tests/transcoder_testcases.TestEnum", vdl.EnumType("A", "B", "C"))
-	basicStructType := vdl.NamedType("v23proxy/tests/transcoder_testcases.TestBasicStruct", vdl.StructType(vdl.Field{"TestEnum", enumType}, vdl.Field{"A", vdl.Int32Type}))
+	basicStructType := vdl.NamedType("v23proxy/tests/transcoder_testcases.TestBasicStruct", vdl.StructType(vdl.Field{"Enum", enumType}, vdl.Field{"A", vdl.Int32Type}))
 
 	builder := vdl.TypeBuilder{}
 	strct := builder.Struct()
-	strct.AppendField("TestEnum", enumType)
+	strct.AppendField("Enum", enumType)
 	namedStruct := builder.Named("v23proxy/tests/transcoder_testcases.TestCyclicStruct").AssignBase(strct)
-	strct.AppendField("TestCyclicStruct", builder.Optional().AssignElem(namedStruct))
+	strct.AppendField("CyclicStruct", builder.Optional().AssignElem(namedStruct))
 	strct.AppendField("A", vdl.Int32Type)
 	builder.Build()
 	cyclicStructType, err := namedStruct.Built()
@@ -117,36 +117,47 @@
 		// ?map[int64]bool is currently disallowed in vdl, so skipping
 		{
 			enumType,
-			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("transcoder_testcases_TestEnum__")}},
+			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum")}},
 			map[string]mojom_types.UserDefinedType{
-				"transcoder_testcases_TestEnum__": transcoder_testcases.GetAllMojomTypeDefinitions()["transcoder_testcases_TestEnum__"],
+				"TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum": transcoder_testcases.GetAllMojomTypeDefinitions()["TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum"],
 			},
 		},
 		{
 			basicStructType,
-			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("transcoder_testcases_TestBasicStruct__")}},
+			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("TYPE_KEY:v23proxy.tests.transcoder_testcases.TestBasicStruct")}},
 			map[string]mojom_types.UserDefinedType{
-				"transcoder_testcases_TestBasicStruct__": transcoder_testcases.GetAllMojomTypeDefinitions()["transcoder_testcases_TestBasicStruct__"],
-				"transcoder_testcases_TestEnum__":        transcoder_testcases.GetAllMojomTypeDefinitions()["transcoder_testcases_TestEnum__"],
+				"TYPE_KEY:v23proxy.tests.transcoder_testcases.TestBasicStruct": transcoder_testcases.GetAllMojomTypeDefinitions()["TYPE_KEY:v23proxy.tests.transcoder_testcases.TestBasicStruct"],
+				"TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum":        transcoder_testcases.GetAllMojomTypeDefinitions()["TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum"],
 			},
 		},
 		{
 			cyclicStructType,
-			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("transcoder_testcases_TestCyclicStruct__")}},
+			&mojom_types.TypeTypeReference{mojom_types.TypeReference{Nullable: false, TypeKey: stringPtr("TYPE_KEY:v23proxy.tests.transcoder_testcases.TestCyclicStruct")}},
 			map[string]mojom_types.UserDefinedType{
-				"transcoder_testcases_TestCyclicStruct__": transcoder_testcases.GetAllMojomTypeDefinitions()["transcoder_testcases_TestCyclicStruct__"],
-				"transcoder_testcases_TestEnum__":         transcoder_testcases.GetAllMojomTypeDefinitions()["transcoder_testcases_TestEnum__"],
+				"TYPE_KEY:v23proxy.tests.transcoder_testcases.TestCyclicStruct": transcoder_testcases.GetAllMojomTypeDefinitions()["TYPE_KEY:v23proxy.tests.transcoder_testcases.TestCyclicStruct"],
+				"TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum":         transcoder_testcases.GetAllMojomTypeDefinitions()["TYPE_KEY:v23proxy.tests.transcoder_testcases.TestEnum"],
 			},
 		},
 	}
 
 	for _, test := range tests {
 		mojomtype, mp := transcoder.VDLToMojomType(test.vdl)
+
+		// Note: Equality is only guaranteed if the casing matches up. Mojom no longer sends out UpperCamelCase values.
 		if !reflect.DeepEqual(mojomtype, test.mojom) {
 			t.Errorf("vdl type %v, when converted to mojo type was %#v. expected %#v", test.vdl, mojomtype, test.mojom)
 		}
-		if !reflect.DeepEqual(mp, test.mp) {
-			t.Errorf("vdl type %v, when converted to mojo type did not match expected user defined types. got %#v, expected %#v", test.vdl, mojomtype, test.mojom)
+		// Note: Equality of structs is virtually impossible. The DeclarationData of the values in the map contains lots of information we cannot recover from vdl.
+		//if !reflect.DeepEqual(mp, test.mp) {
+		//	t.Errorf("vdl type %v, when converted to mojo type did not match expected user defined types. got %#v, expected %#v", test.vdl, mp, test.mp)
+		//}
+		for k, _ := range test.mp {
+			if _, ok := mp[k]; !ok {
+				t.Errorf("vdl type %v, when converted to mojo type did not create an entry for %s", test.vdl, k)
+			}
+		}
+		if len(mp) != len(test.mp) {
+			t.Errorf("vdl type %v, when converted to mojo type created %d map entries, expected %d", test.vdl, len(mp), len(test.mp))
 		}
 
 		vt, err := transcoder.MojomToVDLType(test.mojom, test.mp)
diff --git a/mojom/mojom/tests/transcoder_testcases.mojom b/mojom/mojom/tests/transcoder_testcases.mojom
index a3e9072..93db836 100644
--- a/mojom/mojom/tests/transcoder_testcases.mojom
+++ b/mojom/mojom/tests/transcoder_testcases.mojom
@@ -44,14 +44,14 @@
 };
 
 struct TestBasicStruct {
-  TestEnum testEnum;
-  int32 a;
+  TestEnum Enum;
+  int32 A;
 };
 
 struct TestCyclicStruct {
-    TestEnum testEnum;
-    TestCyclicStruct? testCyclicStruct;
-    int32 a;
+    TestEnum Enum;
+    TestCyclicStruct? CyclicStruct;
+    int32 A;
 };
 
 
diff --git a/pubspec.yaml b/pubspec.yaml
index 299b0a9..b9eadff 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -4,7 +4,7 @@
 name: v23proxy
 version: 0.0.1
 dependencies:
-  mojo_sdk: 0.2.15
+  mojo_sdk: 0.2.16
 dev_dependencies:
   dart_style: any
   test: any