-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sample with Routing metadata changes
Prior to this commit, changes in the routing metadata mechanism had broken this sample application. The routing metadata is now transmitted over the wire and the metadata must be encoded/decoded according to the MIME type used. See https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md This commit implements a new Serializer that writes the metadata length and then the metadata itself as an UTF8 string. This only supports a single type of metadata. We'll need to use Composite metadata if we want to send other metadata, such as authentication.
- Loading branch information
Showing
2 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
createBuffer, | ||
byteLength | ||
} from 'rsocket-core'; | ||
|
||
/** | ||
* Serializer for Routing metadata | ||
* @see https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md | ||
*/ | ||
export class RoutingMetadataSerializer { | ||
|
||
deserialize(data) { | ||
throw 'Not implemented!'; | ||
} | ||
|
||
serialize(data) { | ||
if (data == null) { | ||
return null; | ||
} | ||
let dataLength = byteLength(data, 'utf8'); | ||
let outBuffer = createBuffer(1 + dataLength); | ||
outBuffer.writeUInt8(dataLength, 0); | ||
outBuffer.write(data, 1, data.length, 'utf8'); | ||
return outBuffer; | ||
} | ||
} | ||
|
||
RoutingMetadataSerializer.MIME_TYPE = "message/x.rsocket.routing.v0"; | ||
RoutingMetadataSerializer.MIME_TYPE_ID = 0x7E; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters