/// <summary>
        /// Encodes field value as RawData
        /// </summary>
        /// <param name="binaryEncoder"></param>
        /// <param name="field"></param>
        private void EncodeFieldAsRawData(BinaryEncoder binaryEncoder, Field field)
        {
            try
            {
                // 01 RawData Field Encoding (TODO: StructuredValue)
                var variant = field.Value.WrappedValue;

                if (variant.TypeInfo == null || variant.TypeInfo.BuiltInType == BuiltInType.Null)
                {
                    return;
                }

                if (field.FieldMetaData.ValueRank == ValueRanks.Scalar)
                {
                    switch ((BuiltInType)field.FieldMetaData.BuiltInType)
                    {
                    case BuiltInType.Boolean:
                        binaryEncoder.WriteBoolean("Bool", Convert.ToBoolean(variant.Value));
                        break;

                    case BuiltInType.SByte:
                        binaryEncoder.WriteSByte("SByte", Convert.ToSByte(variant.Value));
                        break;

                    case BuiltInType.Byte:
                        binaryEncoder.WriteByte("Byte", Convert.ToByte(variant.Value));
                        break;

                    case BuiltInType.Int16:
                        binaryEncoder.WriteInt16("Int16", Convert.ToInt16(variant.Value));
                        break;

                    case BuiltInType.UInt16:
                        binaryEncoder.WriteUInt16("UInt16", Convert.ToUInt16(variant.Value));
                        break;

                    case BuiltInType.Int32:
                        binaryEncoder.WriteInt32("Int32", Convert.ToInt32(variant.Value));
                        break;

                    case BuiltInType.UInt32:
                        binaryEncoder.WriteUInt32("UInt32", Convert.ToUInt32(variant.Value));
                        break;

                    case BuiltInType.Int64:
                        binaryEncoder.WriteInt64("Int64", Convert.ToInt64(variant.Value));
                        break;

                    case BuiltInType.UInt64:
                        binaryEncoder.WriteUInt64("UInt64", Convert.ToUInt64(variant.Value));
                        break;

                    case BuiltInType.Float:
                        binaryEncoder.WriteFloat("Float", Convert.ToSingle(variant.Value));
                        break;

                    case BuiltInType.Double:
                        binaryEncoder.WriteDouble("Double", Convert.ToDouble(variant.Value));
                        break;

                    case BuiltInType.DateTime:
                        binaryEncoder.WriteDateTime("DateTime", Convert.ToDateTime(variant.Value));
                        break;

                    case BuiltInType.Guid:
                        binaryEncoder.WriteGuid("GUID", (Uuid)variant.Value);
                        break;

                    case BuiltInType.String:
                        binaryEncoder.WriteString("String", variant.Value as string);
                        break;

                    case BuiltInType.ByteString:
                        binaryEncoder.WriteByteString("ByteString", (byte[])variant.Value);
                        break;

                    case BuiltInType.QualifiedName:
                        binaryEncoder.WriteQualifiedName("QualifiedName", variant.Value as QualifiedName);
                        break;

                    case BuiltInType.LocalizedText:
                        binaryEncoder.WriteLocalizedText("LocalizedText", variant.Value as LocalizedText);
                        break;

                    case BuiltInType.NodeId:
                        binaryEncoder.WriteNodeId("NodeId", variant.Value as NodeId);
                        break;

                    case BuiltInType.ExpandedNodeId:
                        binaryEncoder.WriteExpandedNodeId("ExpandedNodeId", variant.Value as ExpandedNodeId);
                        break;

                    case BuiltInType.StatusCode:
                        binaryEncoder.WriteStatusCode("StatusCode", (StatusCode)variant.Value);
                        break;

                    case BuiltInType.XmlElement:
                        binaryEncoder.WriteXmlElement("XmlElement", variant.Value as XmlElement);
                        break;

                    case BuiltInType.Enumeration:
                        binaryEncoder.WriteInt32("Enumeration", Convert.ToInt32(variant.Value));
                        break;

                    case BuiltInType.ExtensionObject:
                        binaryEncoder.WriteExtensionObject("ExtensionObject", variant.Value as ExtensionObject);
                        break;
                    }
                }
                else
                {
                    switch ((BuiltInType)field.FieldMetaData.BuiltInType)
                    {
                    case BuiltInType.Boolean:
                        binaryEncoder.WriteBooleanArray("BooleanArray", (bool[])variant.Value);
                        break;

                    case BuiltInType.SByte:
                        binaryEncoder.WriteSByteArray("SByteArray", (sbyte[])variant.Value);
                        break;

                    case BuiltInType.Byte:
                        binaryEncoder.WriteByteArray("ByteArray", (byte[])variant.Value);
                        break;

                    case BuiltInType.Int16:
                        binaryEncoder.WriteInt16Array("ByteArray", (short[])variant.Value);
                        break;

                    case BuiltInType.UInt16:
                        binaryEncoder.WriteUInt16Array("UInt16Array", (ushort[])variant.Value);
                        break;

                    case BuiltInType.Int32:
                        binaryEncoder.WriteInt32Array("Int32Array", (int[])variant.Value);
                        break;

                    case BuiltInType.UInt32:
                        binaryEncoder.WriteUInt32Array("UInt32Array", (uint[])variant.Value);
                        break;

                    case BuiltInType.Int64:
                        binaryEncoder.WriteInt64Array("Int64Array", (long[])variant.Value);
                        break;

                    case BuiltInType.UInt64:
                        binaryEncoder.WriteUInt64Array("UInt64Array", (ulong[])variant.Value);
                        break;

                    case BuiltInType.Float:
                        binaryEncoder.WriteFloatArray("FloatArray", (float[])variant.Value);
                        break;

                    case BuiltInType.Double:
                        binaryEncoder.WriteDoubleArray("DoubleArray", (double[])variant.Value);
                        break;

                    case BuiltInType.DateTime:
                        binaryEncoder.WriteDateTimeArray("DateTimeArray", (DateTime[])variant.Value);
                        break;

                    case BuiltInType.Guid:
                        binaryEncoder.WriteGuidArray("GuidArray", (Uuid[])variant.Value);
                        break;

                    case BuiltInType.String:
                        binaryEncoder.WriteStringArray("StringArray", (string[])variant.Value);
                        break;

                    case BuiltInType.ByteString:
                        binaryEncoder.WriteByteStringArray("StringArray", (byte[][])variant.Value);
                        break;

                    case BuiltInType.QualifiedName:
                        binaryEncoder.WriteQualifiedNameArray("QualifiedNameArray", (QualifiedName[])variant.Value);
                        break;

                    case BuiltInType.LocalizedText:
                        binaryEncoder.WriteLocalizedTextArray("LocalizedTextArray", (LocalizedText[])variant.Value);
                        break;

                    case BuiltInType.NodeId:
                        binaryEncoder.WriteNodeIdArray("NodeIdArray", (NodeId[])variant.Value);
                        break;

                    case BuiltInType.ExpandedNodeId:
                        binaryEncoder.WriteExpandedNodeIdArray("ExpandedNodeIdArray", (ExpandedNodeId[])variant.Value);
                        break;

                    case BuiltInType.StatusCode:
                        binaryEncoder.WriteStatusCodeArray("StatusCodeArray", (StatusCode[])variant.Value);
                        break;

                    case BuiltInType.XmlElement:
                        binaryEncoder.WriteXmlElementArray("XmlElementArray", (System.Xml.XmlElement[])variant.Value);
                        break;

                    case BuiltInType.Variant:
                        binaryEncoder.WriteVariantArray("VariantArray", (Variant[])variant.Value);
                        break;

                    case BuiltInType.Enumeration:
                        //TODO make this work
                        //binaryEncoder.WriteInt32Array("EnumerationArray", Convert.ToInt32(variant.Value));
                        binaryEncoder.WriteVariantArray("EnumerationArray", (Variant[])variant.Value);
                        break;

                    case BuiltInType.ExtensionObject:
                        binaryEncoder.WriteExtensionObjectArray("ExtensionObjectArray", (ExtensionObject[])variant.Value);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.Trace("Error encoding field {0} - {1}", field.FieldMetaData.Name, ex);
            }
        }