Java Code Examples for io.rsocket.Payload#hasMetadata()
The following examples show how to use
io.rsocket.Payload#hasMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GatewayExchange.java From spring-cloud-rsocket with Apache License 2.0 | 6 votes |
public static GatewayExchange fromPayload(Type type, Payload payload, MetadataExtractor metadataExtractor) { if (payload == null || !payload.hasMetadata()) { return null; } // TODO: deal with payload mimetype Map<String, Object> metadataMap = metadataExtractor.extract(payload, Metadata.COMPOSITE_MIME_TYPE); GatewayExchange exchange = new GatewayExchange(type, getForwardingMetadata(metadataMap)); // TODO: custm metadata extractors // Adds routing metadata to exchange if (metadataMap.containsKey("route")) { exchange.getAttributes().put("route-metadata", metadataMap.get("route")); } return exchange; }
Example 2
Source File: MetadataPushFrameCodec.java From rsocket-java with Apache License 2.0 | 6 votes |
public static ByteBuf encodeReleasingPayload(ByteBufAllocator allocator, Payload payload) { if (!payload.hasMetadata()) { throw new IllegalStateException( "Metadata push requires to have metadata present" + " in the given Payload"); } final ByteBuf metadata = payload.metadata().retain(); // releasing payload safely since it can be already released wheres we have to release retained // data and metadata as well try { payload.release(); } catch (IllegalReferenceCountException e) { metadata.release(); throw e; } return encode(allocator, metadata); }
Example 3
Source File: PayloadValidationUtils.java From rsocket-java with Apache License 2.0 | 6 votes |
static boolean isValid(int mtu, Payload payload) { if (mtu > 0) { return true; } if (payload.hasMetadata()) { return (((FrameHeaderCodec.size() + FrameLengthCodec.FRAME_LENGTH_SIZE + FrameHeaderCodec.size() + payload.data().readableBytes() + payload.metadata().readableBytes()) & ~FrameLengthCodec.FRAME_LENGTH_MASK) == 0); } else { return (((FrameHeaderCodec.size() + payload.data().readableBytes() + FrameLengthCodec.FRAME_LENGTH_SIZE) & ~FrameLengthCodec.FRAME_LENGTH_MASK) == 0); } }
Example 4
Source File: SetupFrameCodec.java From rsocket-java with Apache License 2.0 | 4 votes |
public static ByteBuf encode( final ByteBufAllocator allocator, final boolean lease, final int keepaliveInterval, final int maxLifetime, final ByteBuf resumeToken, final String metadataMimeType, final String dataMimeType, final Payload setupPayload) { final ByteBuf data = setupPayload.sliceData(); final boolean hasMetadata = setupPayload.hasMetadata(); final ByteBuf metadata = hasMetadata ? setupPayload.sliceMetadata() : null; int flags = 0; if (resumeToken.readableBytes() > 0) { flags |= FLAGS_RESUME_ENABLE; } if (lease) { flags |= FLAGS_WILL_HONOR_LEASE; } if (hasMetadata) { flags |= FrameHeaderCodec.FLAGS_M; } final ByteBuf header = FrameHeaderCodec.encodeStreamZero(allocator, FrameType.SETUP, flags); header.writeInt(CURRENT_VERSION).writeInt(keepaliveInterval).writeInt(maxLifetime); if ((flags & FLAGS_RESUME_ENABLE) != 0) { resumeToken.markReaderIndex(); header.writeShort(resumeToken.readableBytes()).writeBytes(resumeToken); resumeToken.resetReaderIndex(); } // Write metadata mime-type int length = ByteBufUtil.utf8Bytes(metadataMimeType); header.writeByte(length); ByteBufUtil.writeUtf8(header, metadataMimeType); // Write data mime-type length = ByteBufUtil.utf8Bytes(dataMimeType); header.writeByte(length); ByteBufUtil.writeUtf8(header, dataMimeType); return FrameBodyCodec.encode(allocator, header, metadata, hasMetadata, data); }