ivandasch commented on a change in pull request #252:
URL: https://github.com/apache/ignite-3/pull/252#discussion_r680844338



##########
File path: 
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableCommon.java
##########
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client.handler.requests.table;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.BitSet;
+import java.util.UUID;
+import org.apache.ignite.client.proto.ClientDataType;
+import org.apache.ignite.client.proto.ClientMessagePacker;
+import org.apache.ignite.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.SchemaAware;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.table.IgniteTablesInternal;
+import org.apache.ignite.internal.table.TableImpl;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.table.TupleBuilder;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.msgpack.core.MessageFormat;
+
+/**
+ * Common table functionality.
+ */
+class ClientTableCommon {
+    /**
+     * Writes a schema.
+     *
+     * @param packer Packer.
+     * @param schemaVer Schema version.
+     * @param schema Schema.
+     * @throws IOException When serialization fails.
+     */
+    public static void writeSchema(
+            ClientMessagePacker packer,
+            int schemaVer,
+            SchemaDescriptor schema) throws IOException {
+        packer.packInt(schemaVer);
+
+        if (schema == null) {
+            packer.packNil();
+
+            return;
+        }
+
+        var colCnt = schema.columnNames().size();
+        packer.packArrayHeader(colCnt);
+
+        for (var colIdx = 0; colIdx < colCnt; colIdx++) {
+            var col = schema.column(colIdx);
+
+            packer.packArrayHeader(4);
+            packer.packString(col.name());
+            packer.packInt(getClientDataType(col.type().spec()));
+            packer.packBoolean(schema.isKeyColumn(colIdx));
+            packer.packBoolean(col.nullable());
+        }
+    }
+
+    /**
+     * Writes a tuple.
+     *
+     * @param packer Packer.
+     * @param tuple Tuple.
+     * @throws IgniteException on failed serialization.
+     */
+    public static void writeTuple(ClientMessagePacker packer, Tuple tuple) {
+        try {
+            if (tuple == null) {
+                packer.packNil();
+
+                return;
+            }
+
+            var schema = ((SchemaAware) tuple).schema();
+
+            packer.packInt(schema.version());
+
+            for (var col : schema.keyColumns().columns())
+                writeColumnValue(packer, tuple, col);
+
+            for (var col : schema.valueColumns().columns())
+                writeColumnValue(packer, tuple, col);
+        }
+        catch (Throwable t) {
+            throw new IgniteException("Failed to serialize tuple", t);
+        }
+    }
+
+    /**
+     * Reads a tuple.
+     *
+     * @param unpacker Unpacker.
+     * @param table Table.
+     * @param keyOnly Whether only key fields are expected.
+     * @return Tuple.
+     * @throws IOException When deserialization fails.
+     */
+    public static Tuple readTuple(ClientMessageUnpacker unpacker, TableImpl 
table, boolean keyOnly) throws IOException {
+        var schemaId = unpacker.unpackInt();
+        var schema = table.schemaView().schema(schemaId);
+        var builder = table.tupleBuilder();
+
+        var cnt = keyOnly ? schema.keyColumns().length() : schema.length();
+
+        for (int i = 0; i < cnt; i++) {
+            if (unpacker.getNextFormat() == MessageFormat.NIL) {
+                unpacker.skipValue();
+                continue;
+            }
+
+            readAndSetColumnValue(unpacker, builder, schema.column(i));
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Reads a tuple as a map, without schema.
+     *
+     * @param unpacker Unpacker.
+     * @param table Table.
+     * @return Tuple.
+     * @throws IOException When deserialization fails.
+     */public static Tuple readTupleSchemaless(ClientMessageUnpacker unpacker, 
TableImpl table) throws IOException {
+        var cnt = unpacker.unpackMapHeader();

Review comment:
       Oops something wrong with ident




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to