guan404ming commented on code in PR #18683:
URL: https://github.com/apache/tvm/pull/18683#discussion_r2720676830


##########
web/src/rpc_server.ts:
##########
@@ -234,8 +234,15 @@ export class RPCServer {
         if (typeIndex === TypeIndex.kTVMFFIRawStr) {
           const str = Uint8ArrayToString(reader.readByteArray());
           args.push(str);
+        } else if (typeIndex === TypeIndex.kTVMFFIStr) {
+          reader.readU32(); // skip duplicate type_index
+          const str = Uint8ArrayToString(reader.readByteArray());
+          args.push(str);

Review Comment:
   I've confirmed that the C++ side does indeed write the type_index twice for 
\`kTVMFFIStr\` and \`kTVMFFIBytes\`. The flow is:                             
                                                                                
                                                                                
   
   1. `SendPackedSeq` (in `rpc_reference.h:314`) writes `type_index` for each 
argument                                                                 
   2.  For `kTVMFFIStr` `kTVMFFIBytes`, it falls through to the `default` case 
which calls `WriteFFIAny`                                              
   3. `WriteFFIAny` (in `rpc_endpoint.cc:237-243`) writes the type_index again 
before the size and data                                                  
                                                                                
                                                                           
   So the wire format for these types is: `type_index(u32) | type_index(u32) | 
size(u64) | data` The TypeScript fix correctly handles this by reading and 
discarding the duplicate type_index.



##########
web/src/rpc_server.ts:
##########
@@ -234,8 +234,15 @@ export class RPCServer {
         if (typeIndex === TypeIndex.kTVMFFIRawStr) {
           const str = Uint8ArrayToString(reader.readByteArray());
           args.push(str);
+        } else if (typeIndex === TypeIndex.kTVMFFIStr) {
+          reader.readU32(); // skip duplicate type_index
+          const str = Uint8ArrayToString(reader.readByteArray());
+          args.push(str);
         } else if (typeIndex === TypeIndex.kTVMFFIByteArrayPtr) {
           args.push(reader.readByteArray());
+        } else if (typeIndex === TypeIndex.kTVMFFIBytes) {
+          reader.readU32(); // skip duplicate type_index
+          args.push(reader.readByteArray());

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to