public static Message message( byte[] bytes ) throws IOException { PackStreamMessageFormatV1.Reader unpacker = reader( bytes ); RecordingMessageHandler consumer = new RecordingMessageHandler(); try { if ( unpacker.hasNext() ) { unpacker.read( consumer ); return consumer.asList().get( 0 ); } throw new IllegalArgumentException( "Expected a message in " + HexPrinter.hex( bytes ) ); } catch ( Throwable e ) { throw new IOException( "Failed to deserialize response, '" + e.getMessage() + "'. Messages read so " + "far: \n" + consumer.asList() + "\n" + "Raw data: \n" + HexPrinter.hex( bytes ), e ); } }
for ( int j = 0; j < size; j++ ) vals.add( unpackValue() ); Object val = unpackValue(); map.put( key, val ); Map<String,Object> props = unpackProperties(); String relTypeName = unpacker.unpackString(); Map<String,Object> props = unpackProperties(); for ( int i = 0; i < length; i++ ) entities[i] = (PropertyContainer) unpackValue();
private <E extends Exception> void unpackFailureMessage( MessageHandler<E> output ) throws E, IOException { Map<String,Object> map = unpackRawMap(); String codeStr = map.containsKey( "code" ) ? (String) map.get( "code" ) : Status.General.UnknownFailure.name(); String msg = map.containsKey( "message" ) ? (String) map.get( "message" ) : "<No message supplied>"; output.handleFailureMessage( new Neo4jError( codeFromString( codeStr ), msg ) ); }
unpackRunMessage( output ); break; case MessageTypes.MSG_DISCARD_ALL: unpackDiscardAllMessage( output ); break; case MessageTypes.MSG_PULL_ALL: unpackPullAllMessage( output ); break; case MessageTypes.MSG_RECORD: unpackRecordMessage( output ); break; case MessageTypes.MSG_SUCCESS: unpackSuccessMessage( output ); break; case MessageTypes.MSG_FAILURE: unpackFailureMessage( output ); break; case MessageTypes.MSG_ACK_FAILURE: unpackAckFailureMessage( output ); break; case MessageTypes.MSG_IGNORED: unpackIgnoredMessage( output ); break; default:
public static List<Message> messages( byte[] bytes ) throws IOException { PackStreamMessageFormatV1.Reader unpacker = reader( bytes ); RecordingMessageHandler consumer = new RecordingMessageHandler(); try { while ( unpacker.hasNext() ) { unpacker.read( consumer ); } return consumer.asList(); } catch ( Throwable e ) { throw new IOException( "Failed to deserialize response, '" + e.getMessage() + "'. Messages read so " + "far: \n" + consumer.asList() + "\n" + "Raw data: \n" + HexPrinter.hex( bytes ) ); } }
public SocketProtocolV1( final LogService logging, Session session, Channel channel ) { this.log = logging.getInternalLog( getClass() ); this.session = session; this.errorTranslator = new ErrorTranslator( logging ); this.output = new ChunkedOutput( channel, DEFAULT_BUFFER_SIZE ); this.input = new ChunkedInput(); this.packer = new PackStreamMessageFormatV1.Writer( new PackStream.Packer( output ), output.messageBoundaryHook() ); this.unpacker = new PackStreamMessageFormatV1.Reader( new PackStream.Unpacker( input ) ); this.bridge = new TransportBridge( log ).reset( session, packer, new Runnable() { @Override public void run() { onMessagDone(); } } ); }
private static PackStreamMessageFormatV1.Reader reader( byte[] bytes ) { return new PackStreamMessageFormatV1.Reader( new PackStream.Unpacker( new BufferedChannelInput( 128 ).reset( new ArrayByteChannel( bytes ) ) ) ); }
private <E extends Exception> void unpackSuccessMessage( MessageHandler<E> output ) throws E, IOException { Map<String,Object> map = unpackRawMap(); output.handleSuccessMessage( map ); }
private <T extends Message> T serializeAndDeserialize( T msg ) throws IOException { RecordingByteChannel channel = new RecordingByteChannel(); MessageFormat.Reader reader = new PackStreamMessageFormatV1.Reader( new PackStream.Unpacker( new BufferedChannelInput( 16 ).reset( channel ) ) ); MessageFormat.Writer writer = new PackStreamMessageFormatV1.Writer( new PackStream.Packer( new BufferedChannelOutput( channel ) ), NO_OP ); writer.write( msg ).flush(); channel.eof(); return unpack( reader, channel ); }
private <E extends Exception> void unpackRunMessage( MessageHandler<E> output ) throws E, IOException { String statement = unpacker.unpackString(); Map<String,Object> params = unpackRawMap(); output.handleRunMessage( statement, params ); }