/// <summary>LoadContent /// </summary> public override void LoadContent(ClusterConfiguration configuration, byte[] data) { MetaData = new Dictionary <string, string>(); int startIndex = 0; int itemSeparaterIndex; do { int keyValueSeparaterIndex = Array.IndexOf <byte>(data, Consts.METADATA_KEY_VALUE_SEPARATOR, startIndex); if (keyValueSeparaterIndex < 0) { throw new ArgumentException("invalid metadata buffer format"); } string key = ByteUtil.ByteToString(data, startIndex, keyValueSeparaterIndex - startIndex, configuration.Charset); startIndex = keyValueSeparaterIndex + 1; itemSeparaterIndex = Array.IndexOf <byte>(data, Consts.METADATA_PAIR_SEPARATER, startIndex); string value; if (itemSeparaterIndex < 0) { value = ByteUtil.ByteToString(data, startIndex, (data.Length - 1) - startIndex, configuration.Charset); } else { value = ByteUtil.ByteToString(data, startIndex, itemSeparaterIndex - startIndex, configuration.Charset); } startIndex = itemSeparaterIndex + 1; MetaData.Add(key, value); } while (itemSeparaterIndex >= 0); }
public void Dump() { Debug.WriteLine("PollingCommandResponse"); Debug.WriteLine("ResponseCode=" + ByteUtil.ByteToString(ResponseCode())); Debug.WriteLine("IDm=" + ByteUtil.ByteArrayToString(IDm())); Debug.WriteLine("PMm=" + ByteUtil.ByteArrayToString(PMm())); Debug.WriteLine("ResponseData=" + ByteUtil.ByteArrayToString(RequestData())); }
/// <summary>LoadContent /// </summary> public override void LoadContent(ClusterConfiguration configuration, byte[] data) { byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN]; Array.Copy(data, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN); GroupName = ByteUtil.ByteToString(groupNameBuffer, configuration.Charset).TrimEnd('\0'); byte[] fileNameBuffer = new byte[data.Length - Consts.FDFS_GROUP_NAME_MAX_LEN]; Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN, fileNameBuffer, 0, fileNameBuffer.Length); FileId = ByteUtil.ByteToString(fileNameBuffer, configuration.Charset).TrimEnd('\0'); }
/// <summary>LoadContent /// </summary> public override void LoadContent(FastDFSOption option, byte[] data) { byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN]; Array.Copy(data, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN); GroupName = ByteUtil.ByteToString(groupNameBuffer, option.Charset).TrimEnd('\0'); byte[] ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1]; Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1); IPAddress = new string(Encoding.GetEncoding(option.Charset).GetChars(ipAddressBuffer)).TrimEnd('\0'); byte[] portBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE]; Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN + Consts.IP_ADDRESS_SIZE - 1, portBuffer, 0, Consts.FDFS_PROTO_PKG_LEN_SIZE); Port = (int)ByteUtil.BufferToLong(portBuffer, 0); }
/// <summary>LoadContent /// </summary> public override void LoadContent(FastDFSOption option, byte[] data) { var dataSpan = data.AsSpan(); var groupNameBufferSpan = dataSpan.Slice(0, Consts.FDFS_GROUP_NAME_MAX_LEN); GroupName = ByteUtil.ByteToString(groupNameBufferSpan.ToArray(), option.Charset).TrimEnd('\0'); var fileNameBufferSpan = dataSpan.Slice(Consts.FDFS_GROUP_NAME_MAX_LEN); FileId = ByteUtil.ByteToString(fileNameBufferSpan.ToArray(), option.Charset).TrimEnd('\0'); //byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN]; //Array.Copy(data, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN); //GroupName = ByteUtil.ByteToString(groupNameBuffer, option.Charset).TrimEnd('\0'); //byte[] fileNameBuffer = new byte[data.Length - Consts.FDFS_GROUP_NAME_MAX_LEN]; //Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN, fileNameBuffer, 0, fileNameBuffer.Length); //FileId = ByteUtil.ByteToString(fileNameBuffer, option.Charset).TrimEnd('\0'); }