public void TestGeneratorAndDispose() { ByteArrayWrapper arrayWrapper = new ByteArrayWrapper(new ByteArray(new byte[0])); Assert.IsNotNull(arrayWrapper); Action action = () => arrayWrapper.Dispose(); action.Should().NotThrow <Exception>(); }
public void TestNext() { ByteArrayWrapper arrayWrapper = new ByteArrayWrapper(new byte[] { 0x01, 0x02 }); Assert.AreEqual(true, arrayWrapper.Next()); Assert.AreEqual(0x01, arrayWrapper.Value()); Assert.AreEqual(true, arrayWrapper.Next()); Assert.AreEqual(0x02, arrayWrapper.Value()); Assert.AreEqual(false, arrayWrapper.Next()); }
public void TestKeyAndValue() { ByteArrayWrapper arrayWrapper = new ByteArrayWrapper(new byte[] { 0x01, 0x02 }); Action action2 = () => arrayWrapper.Value(); action2.Should().Throw <InvalidOperationException>(); arrayWrapper.Next(); Assert.AreEqual(0x01, arrayWrapper.Value()); arrayWrapper.Next(); Assert.AreEqual(0x02, arrayWrapper.Value()); }
private static void EnsureAppendCapacity(ByteArrayWrapper sink, int minCapacity, int desiredCapacity) { int remainingCapacity = sink.Bytes.Length - sink.Length; if (remainingCapacity >= minCapacity) { return; } if (desiredCapacity < minCapacity) { desiredCapacity = minCapacity; } sink.EnsureCapacity(sink.Length + desiredCapacity); }
public static void Send(TcpClient client, ByteArrayWrapper binaryData) { if (client == null) { return; } NetworkStream stream = client.GetStream(); byte[] writeBuffer = binaryData.binaryData; int msgSize = writeBuffer.Length; byte[] bufferLegnth = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(msgSize)); stream.Write(bufferLegnth, 0, bufferLegnth.Length); stream.Write(writeBuffer, 0, msgSize); }
public void TestByteArrayWrapper() { byte[] ba = { 0x00, 0x01, 0x02 }; sbyte[] bb = { 0x00, 0x01, 0x02, -1 }; ByteBuffer buffer = ByteBuffer.Wrap(ba); ByteArrayWrapper x = new ByteArrayWrapper(buffer); ByteArrayWrapper y = new ByteArrayWrapper(ba, 3); ByteArrayWrapper z = new ByteArrayWrapper((byte[])(Array)bb, 3); if (!y.ToString().Equals("00 01 02")) { Errln("FAIL: test toString : Failed!"); } // test equality if (!x.Equals(y) || !x.Equals(z)) { Errln("FAIL: test (operator ==): Failed!"); } if (x.GetHashCode() != y.GetHashCode()) { Errln("FAIL: identical objects have different hash codes."); } // test non-equality y = new ByteArrayWrapper((byte[])(Array)bb, 4); if (x.Equals(y)) { Errln("FAIL: test (operator !=): Failed!"); } // test sign of unequal comparison if ((x.CompareTo(y) > 0) != (y.CompareTo(x) < 0)) { Errln("FAIL: comparisons not opposite sign"); } }
/** * Compare this RawCollationKey to another, which must not be null. This overrides * the inherited implementation to ensure the returned values are -1, 0, or 1. * @param rhs the RawCollationKey to compare to. * @return -1, 0, or 1 as this compares less than, equal to, or * greater than rhs. * @throws ClassCastException if the other object is not a RawCollationKey. * @stable ICU 4.4 */ public override int CompareTo(ByteArrayWrapper rhs) { int result = base.CompareTo(rhs); return(result < 0 ? -1 : result == 0 ? 0 : 1); }
public static Task <ByteArrayWrapper> RoundTripByteArrayWrapperObjectAsync(ByteArrayWrapper byteArrayWrapper) { return(Task.FromResult(byteArrayWrapper)); }
public static ByteArrayWrapper RoundTripByteArrayWrapperObject(ByteArrayWrapper byteArrayWrapper) { return(byteArrayWrapper); }
// public methods ------------------------------------------------------- /// <summary> /// Encode the code points of a string as /// a sequence of byte-encoded differences (slope detection), /// preserving lexical order. /// </summary> /// <remarks> /// Optimize the difference-taking for runs of Unicode text within /// small scripts: /// <para/> /// Most small scripts are allocated within aligned 128-blocks of Unicode /// code points. Lexical order is preserved if "prev" is always moved /// into the middle of such a block. /// <para/> /// Additionally, "prev" is moved from anywhere in the Unihan /// area into the middle of that area. /// Note that the identical-level run in a sort key is generated from /// NFD text - there are never Hangul characters included. /// </remarks> public static int WriteIdenticalLevelRun(int prev, ICharSequence s, int i, int length, ByteArrayWrapper sink) { while (i < length) { // We must have capacity>=SLOPE_MAX_BYTES in case writeDiff() writes that much, // but we do not want to force the sink to allocate // for a large min_capacity because we might actually only write one byte. EnsureAppendCapacity(sink, 16, s.Length * 2); byte[] buffer = sink.Bytes; int capacity = buffer.Length; int p = sink.Length; int lastSafe = capacity - SLOPE_MAX_BYTES_; while (i < length && p <= lastSafe) { if (prev < 0x4e00 || prev >= 0xa000) { prev = (prev & ~0x7f) - SLOPE_REACH_NEG_1_; } else { // Unihan U+4e00..U+9fa5: // double-bytes down from the upper end prev = 0x9fff - SLOPE_REACH_POS_2_; } int c = Character.CodePointAt(s, i); i += Character.CharCount(c); if (c == 0xfffe) { buffer[p++] = 2; // merge separator prev = 0; } else { p = WriteDiff(c - prev, buffer, p); prev = c; } } sink.Length = p; } return(prev); }