-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename InvokeConfig to RunnableConfig
work on #20
- Loading branch information
1 parent
deabff6
commit fe9ff01
Showing
5 changed files
with
424 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
8 changes: 0 additions & 8 deletions
8
core-jdk8/src/main/java/org/bsc/langgraph4j/checkpoint/CheckpointConfig.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
core-jdk8/src/main/java/org/bsc/langgraph4j/serializer/MapSerializer.java
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,73 @@ | ||
package org.bsc.langgraph4j.serializer; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.*; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
public class StateSerializer implements Serializer<Map<String,Object>> { | ||
public static final StateSerializer INSTANCE = new StateSerializer(); | ||
private StateSerializer() {} | ||
|
||
@Override | ||
public void write(Map<String,Object> object, ObjectOutput out) throws IOException { | ||
try( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { | ||
int actualSize = 0; | ||
|
||
final ObjectOutputStream tupleStream = new ObjectOutputStream( baos ); | ||
for( Map.Entry<String,Object> e : object.entrySet() ) { | ||
try { | ||
tupleStream.writeUTF(e.getKey()); | ||
tupleStream.writeObject(e.getValue()); | ||
++actualSize; | ||
} catch (IOException ex) { | ||
log.error( "Error writing state key '{}' - {}", e.getKey(), ex.getMessage() ); | ||
throw ex; | ||
} | ||
} | ||
|
||
out.writeInt( object.size() ); | ||
out.writeInt( actualSize ); // actual size | ||
byte[] data = baos.toByteArray(); | ||
out.writeInt( data.length ); | ||
out.write( data ); | ||
|
||
} | ||
|
||
} | ||
|
||
@Override | ||
public Map<String, Object> read(ObjectInput in) throws IOException, ClassNotFoundException { | ||
Map<String, Object> data = new HashMap<>(); | ||
|
||
int expectedSize = in.readInt(); | ||
int actualSize = in.readInt(); | ||
if( expectedSize > 0 && actualSize > 0 ) { | ||
|
||
if( expectedSize != actualSize ) { | ||
final String message = String.format( "Deserialize State: Expected size %d and actual size %d do not match!", expectedSize, actualSize ) ; | ||
log.error( message ) ; | ||
throw new IOException( message ) ; | ||
} | ||
|
||
int byteLen = in.readInt(); | ||
byte[] bytes = new byte[byteLen]; | ||
in.readFully(bytes); | ||
|
||
try( ByteArrayInputStream bais = new ByteArrayInputStream( bytes ) ) { | ||
ObjectInputStream ois = new ObjectInputStream( bais ); | ||
|
||
for( int i = 0; i < actualSize; i++ ) { | ||
String key = ois.readUTF(); | ||
Object value = ois.readObject(); | ||
data.put(key, value); | ||
} | ||
} | ||
|
||
} | ||
return data; | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
core-jdk8/src/main/java/org/bsc/langgraph4j/state/StateSnapshot.java
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,2 @@ | ||
package org.bsc.langgraph4j.state;public class StateSnapshot { | ||
} |
Oops, something went wrong.