rsocket / rsocket-dart

Dart implementation of RSocket
Apache License 2.0
31 stars 25 forks source link

Custom metadata via CompositeMetadata not working. #31

Closed digows closed 3 months ago

digows commented 3 months ago

Hi,

I have created a custom Mimetype. Using Javascript rsocket client is working as expected.

But using the dart package, the metadata is being malformed.

Looks like this method is not working well for not well known mime types.

_file: compositemetadata.dart

void addExplicitMimeType(String? mimeType, Uint8List? content) {
if (WellKnownMimeType.isWellKnownType(mimeType)) { addWellKnownMimeType( WellKnownMimeType.getMimeTypeId(mimeType)!, content!); } else { var mimeTypeArray = utf8.encode(mimeType!); buffer.writeI8(mimeTypeArray.length); buffer.writeBytes(mimeTypeArray); buffer.writeI24(content!.length); buffer.writeUint8List(content); } }

if I send a well known type, it works.

digows commented 3 months ago

I found a fix for this method:

`
void addExplicitMimeType(String? mimeType, Uint8List? content) { if (WellKnownMimeType.isWellKnownType(mimeType)) { addWellKnownMimeType( WellKnownMimeType.getMimeTypeId(mimeType)!, content!); } else {

  final mimeTypeArray = utf8.encode(mimeType!);
  buffer.writeI8(mimeTypeArray.length-1);
  buffer.writeBytes(mimeTypeArray);

  buffer.writeI24(content!.length);
  buffer.writeUint8List(content);
}

}

`

For some reason, the mime type length should be -1.