Пример #1
0
        //Encode string.
        private void writeString(byte[] buffer, ref int offset, IJsonNode value)
        {
            int le = Encoding.UTF8.GetByteCount(value.AsString());

            offset = writeBytes(buffer, offset, Encoder.encodeUInt32((uint)le));
            byte[] bytes = Encoding.UTF8.GetBytes(value.ToString());
            this.writeBytes(buffer, offset, bytes);
            offset += le;
        }
Пример #2
0
        /// <summary>
        /// Encode each item in message.
        /// </summary>
        private int encodeProp(IJsonNode value, string type, int offset, byte[] buffer, JsonNode_Object proto)
        {
            switch (type)
            {
            case "uInt32":
                this.writeUInt32(buffer, ref offset, value);
                break;

            case "int32":
            case "sInt32":
                this.writeInt32(buffer, ref offset, value);
                break;

            case "float":
                this.writeFloat(buffer, ref offset, value);
                break;

            case "double":
                this.writeDouble(buffer, ref offset, value);
                break;

            case "string":
                this.writeString(buffer, ref offset, value);
                break;

            default:
                IJsonNode __messages;
                IJsonNode __message_type;

                if (proto.TryGetValue("__messages", out __messages))
                {
                    if (((JsonNode_Object)__messages).TryGetValue(type, out __message_type) || protos.TryGetValue("message " + type, out __message_type))
                    {
                        byte[] tembuff = new byte[Encoder.byteLength(value.ToString()) * 3];
                        int    length  = 0;
                        length = this.encodeMsg(tembuff, length, (JsonNode_Object)__message_type, (JsonNode_Object)value);
                        offset = writeBytes(buffer, offset, Encoder.encodeUInt32((uint)length));
                        for (int i = 0; i < length; i++)
                        {
                            buffer[offset] = tembuff[i];
                            offset++;
                        }
                    }
                }
                break;
            }
            return(offset);
        }