[ 
https://issues.apache.org/jira/browse/TINKERPOP-3219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18045306#comment-18045306
 ] 

ASF GitHub Bot commented on TINKERPOP-3219:
-------------------------------------------

andreachild commented on code in PR #3285:
URL: https://github.com/apache/tinkerpop/pull/3285#discussion_r2621073975


##########
gremlin-go/driver/resultSet.go:
##########
@@ -211,3 +211,48 @@ func newChannelResultSetCapacity(requestID string, 
container *synchronizedMap, c
 func newChannelResultSet(requestID string, container *synchronizedMap) 
ResultSet {
        return newChannelResultSetCapacity(requestID, container, 
defaultCapacity)
 }
+
+// NewResultSet creates a new ResultSet from a slice of Result objects.
+// This function enables custom transport implementations to create ResultSets 
from
+// results collected via alternative protocols.
+//
+// The function creates a channel-based ResultSet, pre-populates it with the 
provided results,
+// and closes the channel to indicate completion.
+//
+// Parameters:
+//   - results: A slice of Result objects to include in the ResultSet
+//
+// Returns:
+//   - ResultSet: A ResultSet containing all the provided results
+//
+// Example usage:
+//
+//     var results []*Result
+//     // Collect results from custom transport
+//     for _, responseBytes := range responses {
+//         result, _ := DeserializeResult(responseBytes)
+//         results = append(results, result)
+//     }
+//     resultSet := NewResultSet(results)
+//     allResults, _ := resultSet.All()
+func NewResultSet(results []*Result) ResultSet {
+       // Create a channel-based result set with capacity for all results
+       channelSize := len(results)
+       if channelSize == 0 {
+               channelSize = 1 // Ensure at least size 1
+       }
+       rs := newChannelResultSetCapacity("", 
&synchronizedMap{make(map[string]ResultSet), sync.Mutex{}}, 
channelSize).(*channelResultSet)

Review Comment:
   Should the `requestID` be passed in as a parameter instead of hardcoded to 
empty string?





> Add public serialization API in gremlin-go for alternative transport protocols
> ------------------------------------------------------------------------------
>
>                 Key: TINKERPOP-3219
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3219
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: go
>    Affects Versions: 4.0.0, 3.8.1
>            Reporter: Haiyu Wang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.0, 3.8.1
>
>
> According to maintainers' comments, the title is changed to `Expose 
> serialization functions for alternative transport protocols in gremlin-go`
> /*
> Currently, gremlin-go only supports WebSocket transport. The serialization 
> logic (GraphBinary) is internal/private, preventing developers from building 
> custom transport implementations (gRPC, HTTP/2, etc.) while maintaining 
> Gremlin API compatibility.
> This improvement adds a new file gremlin-go/driver/serializer_export.go with 
> 5 exported wrapper functions around existing internal serialization logic:
>  - SerializeRequest() - Serialize bytecode with traversal source
>  - SerializeBytecode() - Convenience wrapper using default source
>  - SerializeStringQuery() - Serialize string queries
>  - DeserializeResult() - Deserialize response bytes
>  - NewResultSet() - Create ResultSet from collected results
> These are thin wrappers with zero modifications to existing code, fully 
> backward compatible, and enable the ecosystem to build alternative transports.
> */
> Use case: Building gRPC-based Gremlin clients for production deployments.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to