{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/61350878","id":61350878,"diff_hunk":"@@ -0,0 +1,117 @@\n+/**\n+ * Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>\n+ */\n+package akka.remote.serialization\n+\n+import akka.actor._\n+import akka.protobuf.ByteString\n+import akka.remote.ContainerFormats\n+import akka.serialization.{ Serialization, BaseSerializer, SerializationExtension, SerializerWithStringManifest }\n+\n+class MiscMessageSerializer(val system: ExtendedActorSystem) extends SerializerWithStringManifest with BaseSerializer {\n+\n+  private lazy val serialization = SerializationExtension(system)\n+\n+  def toBinary(obj: AnyRef): Array[Byte] = obj match {\n+    case identify: Identify      ⇒ serializeIdentify(identify)\n+    case identity: ActorIdentity ⇒ serializeActorIdentity(identity)\n+    case _                       ⇒ throw new IllegalArgumentException(s\"Cannot serialize object of type [${obj.getClass.getName}]\")\n+  }\n+\n+  private def serializeIdentify(identify: Identify): Array[Byte] =\n+    ContainerFormats.Identify.newBuilder()\n+      .setMessageId(payloadBuilder(identify.messageId))\n+      .build()\n+      .toByteArray\n+\n+  private def serializeActorIdentity(actorIdentity: ActorIdentity): Array[Byte] = {\n+    val builder =\n+      ContainerFormats.ActorIdentity.newBuilder()\n+        .setCorrelationId(payloadBuilder(actorIdentity.correlationId))\n+\n+    actorIdentity.ref.foreach { actorRef ⇒\n+      builder.setRef(actorRefBuilder(actorRef))\n+    }\n+\n+    builder\n+      .build()\n+      .toByteArray\n+  }\n+\n+  private def actorRefBuilder(actorRef: ActorRef): ContainerFormats.ActorRef.Builder =\n+    ContainerFormats.ActorRef.newBuilder()\n+      .setPath(Serialization.serializedActorPath(actorRef))\n+\n+  private def payloadBuilder(input: Any): ContainerFormats.Payload.Builder = {\n+    val payload = input.asInstanceOf[AnyRef]\n+    val builder = ContainerFormats.Payload.newBuilder()\n+    val serializer = serialization.findSerializerFor(payload)\n+\n+    builder\n+      .setEnclosedMessage(ByteString.copyFrom(serializer.toBinary(payload)))\n+      .setSerializerId(serializer.identifier)\n+\n+    serializer match {\n+      case ser2: SerializerWithStringManifest ⇒\n+        val manifest = ser2.manifest(payload)\n+        if (manifest != \"\")\n+          builder.setMessageManifest(ByteString.copyFromUtf8(manifest))\n+      case _ ⇒\n+        if (serializer.includeManifest)\n+          builder.setMessageManifest(ByteString.copyFromUtf8(payload.getClass.getName))\n+    }\n+\n+    builder\n+  }\n+\n+  private val IdentifyManifest = \"A\"\n+  private val ActorIdentifyManifest = \"B\"\n+\n+  private val fromBinaryMap = Map[String, Array[Byte] ⇒ AnyRef](\n+    IdentifyManifest -> deserializeIdentify,\n+    ActorIdentifyManifest -> deserializeActorIdentity)\n+\n+  override def manifest(o: AnyRef): String =\n+    o match {\n+      case _: Identify      ⇒ IdentifyManifest\n+      case _: ActorIdentity ⇒ ActorIdentifyManifest\n+      case _ ⇒\n+        throw new IllegalArgumentException(s\"Can't serialize object of type ${o.getClass} in [${getClass.getName}]\")\n+    }\n+\n+  override def fromBinary(bytes: Array[Byte], manifest: String): AnyRef =\n+    fromBinaryMap.get(manifest) match {\n+      case Some(deserializer) ⇒ deserializer(bytes)\n+      case None ⇒ throw new IllegalArgumentException(\n+        s\"Unimplemented deserialization of message with manifest [$manifest] in [${getClass.getName}]\")\n+    }\n+\n+  private def deserializeIdentify(bytes: Array[Byte]): Identify = {\n+    val identifyProto = ContainerFormats.Identify.parseFrom(bytes)\n+    val messageId = deserializePayload(identifyProto.getMessageId)\n+    Identify(messageId)\n+  }\n+\n+  private def deserializeActorIdentity(bytes: Array[Byte]): ActorIdentity = {\n+    val actorIdentityProto = ContainerFormats.ActorIdentity.parseFrom(bytes)\n+    val correlationId = deserializePayload(actorIdentityProto.getCorrelationId)\n+    val actorRef =\n+      if (actorIdentityProto.hasRef)","path":"akka-remote/src/main/scala/akka/remote/serialization/MiscMessageSerializer.scala","position":99,"original_position":99,"commit_id":"4daf17ae1906c572edc372e21abb37055d985a0f","original_commit_id":"4daf17ae1906c572edc372e21abb37055d985a0f","user":{"login":"fsat","id":1665611,"avatar_url":"https://avatars.githubusercontent.com/u/1665611?v=3","gravatar_id":"","url":"https://api.github.com/users/fsat","html_url":"https://github.com/fsat","followers_url":"https://api.github.com/users/fsat/followers","following_url":"https://api.github.com/users/fsat/following{/other_user}","gists_url":"https://api.github.com/users/fsat/gists{/gist_id}","starred_url":"https://api.github.com/users/fsat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsat/subscriptions","organizations_url":"https://api.github.com/users/fsat/orgs","repos_url":"https://api.github.com/users/fsat/repos","events_url":"https://api.github.com/users/fsat/events{/privacy}","received_events_url":"https://api.github.com/users/fsat/received_events","type":"User","site_admin":false},"body":"@patriknw - using `hasRef` now which is definitely better than before","created_at":"2016-04-27T22:56:43Z","updated_at":"2016-04-27T22:56:43Z","html_url":"https://github.com/akka/akka/pull/20380#discussion_r61350878","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/20380","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/61350878"},"html":{"href":"https://github.com/akka/akka/pull/20380#discussion_r61350878"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/20380"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/20380","id":67459892,"html_url":"https://github.com/akka/akka/pull/20380","diff_url":"https://github.com/akka/akka/pull/20380.diff","patch_url":"https://github.com/akka/akka/pull/20380.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/20380","number":20380,"state":"open","locked":false,"title":"WIP - DON'T MERGE - More Protobuf Serialization","user":{"login":"fsat","id":1665611,"avatar_url":"https://avatars.githubusercontent.com/u/1665611?v=3","gravatar_id":"","url":"https://api.github.com/users/fsat","html_url":"https://github.com/fsat","followers_url":"https://api.github.com/users/fsat/followers","following_url":"https://api.github.com/users/fsat/following{/other_user}","gists_url":"https://api.github.com/users/fsat/gists{/gist_id}","starred_url":"https://api.github.com/users/fsat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsat/subscriptions","organizations_url":"https://api.github.com/users/fsat/orgs","repos_url":"https://api.github.com/users/fsat/repos","events_url":"https://api.github.com/users/fsat/events{/privacy}","received_events_url":"https://api.github.com/users/fsat/received_events","type":"User","site_admin":false},"body":"Add support for protobuf serialization for\r\n* `akka.actor.Identify`\r\n* `akka.actor.ActorIdentity`","created_at":"2016-04-22T05:04:00Z","updated_at":"2016-04-27T22:56:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c454cdc6cad75408fb434725e5922de8f6d08837","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/20380/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/20380/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/20380/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/4daf17ae1906c572edc372e21abb37055d985a0f","head":{"label":"fsat:more-protobuf-serialization","ref":"more-protobuf-serialization","sha":"4daf17ae1906c572edc372e21abb37055d985a0f","user":{"login":"fsat","id":1665611,"avatar_url":"https://avatars.githubusercontent.com/u/1665611?v=3","gravatar_id":"","url":"https://api.github.com/users/fsat","html_url":"https://github.com/fsat","followers_url":"https://api.github.com/users/fsat/followers","following_url":"https://api.github.com/users/fsat/following{/other_user}","gists_url":"https://api.github.com/users/fsat/gists{/gist_id}","starred_url":"https://api.github.com/users/fsat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsat/subscriptions","organizations_url":"https://api.github.com/users/fsat/orgs","repos_url":"https://api.github.com/users/fsat/repos","events_url":"https://api.github.com/users/fsat/events{/privacy}","received_events_url":"https://api.github.com/users/fsat/received_events","type":"User","site_admin":false},"repo":{"id":44372211,"name":"akka","full_name":"fsat/akka","owner":{"login":"fsat","id":1665611,"avatar_url":"https://avatars.githubusercontent.com/u/1665611?v=3","gravatar_id":"","url":"https://api.github.com/users/fsat","html_url":"https://github.com/fsat","followers_url":"https://api.github.com/users/fsat/followers","following_url":"https://api.github.com/users/fsat/following{/other_user}","gists_url":"https://api.github.com/users/fsat/gists{/gist_id}","starred_url":"https://api.github.com/users/fsat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsat/subscriptions","organizations_url":"https://api.github.com/users/fsat/orgs","repos_url":"https://api.github.com/users/fsat/repos","events_url":"https://api.github.com/users/fsat/events{/privacy}","received_events_url":"https://api.github.com/users/fsat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fsat/akka","description":"Akka Project","fork":true,"url":"https://api.github.com/repos/fsat/akka","forks_url":"https://api.github.com/repos/fsat/akka/forks","keys_url":"https://api.github.com/repos/fsat/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fsat/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fsat/akka/teams","hooks_url":"https://api.github.com/repos/fsat/akka/hooks","issue_events_url":"https://api.github.com/repos/fsat/akka/issues/events{/number}","events_url":"https://api.github.com/repos/fsat/akka/events","assignees_url":"https://api.github.com/repos/fsat/akka/assignees{/user}","branches_url":"https://api.github.com/repos/fsat/akka/branches{/branch}","tags_url":"https://api.github.com/repos/fsat/akka/tags","blobs_url":"https://api.github.com/repos/fsat/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fsat/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fsat/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/fsat/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fsat/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/fsat/akka/languages","stargazers_url":"https://api.github.com/repos/fsat/akka/stargazers","contributors_url":"https://api.github.com/repos/fsat/akka/contributors","subscribers_url":"https://api.github.com/repos/fsat/akka/subscribers","subscription_url":"https://api.github.com/repos/fsat/akka/subscription","commits_url":"https://api.github.com/repos/fsat/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/fsat/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/fsat/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/fsat/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/fsat/akka/contents/{+path}","compare_url":"https://api.github.com/repos/fsat/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fsat/akka/merges","archive_url":"https://api.github.com/repos/fsat/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fsat/akka/downloads","issues_url":"https://api.github.com/repos/fsat/akka/issues{/number}","pulls_url":"https://api.github.com/repos/fsat/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/fsat/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/fsat/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fsat/akka/labels{/name}","releases_url":"https://api.github.com/repos/fsat/akka/releases{/id}","deployments_url":"https://api.github.com/repos/fsat/akka/deployments","created_at":"2015-10-16T08:24:35Z","updated_at":"2016-04-21T07:05:09Z","pushed_at":"2016-04-27T22:55:37Z","git_url":"git://github.com/fsat/akka.git","ssh_url":"git@github.com:fsat/akka.git","clone_url":"https://github.com/fsat/akka.git","svn_url":"https://github.com/fsat/akka","homepage":"http://akka.io","size":192921,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"akka:master","ref":"master","sha":"fd89f3694064f0e5a343dec98feda559b48a2c0d","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","deployments_url":"https://api.github.com/repos/akka/akka/deployments","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-04-27T18:56:04Z","pushed_at":"2016-04-27T22:55:39Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":204892,"stargazers_count":5430,"watchers_count":5430,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1685,"mirror_url":null,"open_issues_count":723,"forks":1685,"open_issues":723,"watchers":5430,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/20380"},"html":{"href":"https://github.com/akka/akka/pull/20380"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/20380"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/20380/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/20380/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/20380/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/4daf17ae1906c572edc372e21abb37055d985a0f"}}}}