仿真平台内核初版 -tlib库 包含<sparc arm riscv powerPC>

This commit is contained in:
liuwb
2026-02-07 20:43:43 +08:00
parent de61f9e2b0
commit b3117648be
9748 changed files with 4309137 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
// Telenor Inpli TFTP Server Module
//
// Copyright 2018 Telenor Inpli AS Norway
using System;
internal static class BufferPrimitives
{
/// <summary>
/// Read a 16-bit big endian value from a buffer at a given offset
/// </summary>
/// <param name="buffer">The buffer to read from</param>
/// <param name="offset">The offset in the buffer</param>
/// <returns>A 16 bit value</returns>
/// <exception cref="IndexOutOfRangeException">If reading past the end of the buffer</exception>
public static int Get16BE(this byte [] buffer, long offset)
{
if ((offset + 2) >= buffer.Length)
throw new IndexOutOfRangeException();
return ((int)(buffer[offset]) << 8) | (int)buffer[offset+1];
}
/// <summary>
/// Writes a 16-bit big endian to a buffer at a given offset
/// </summary>
/// <param name="buffer">The buffer to write into</param>
/// <param name="offset">The offset within the buffer to write to</param>
/// <param name="value">The value to write</param>
/// <exception cref="IndexOutOfRangeException">If attempting to write past the end</exception>
public static void Write16BE(this byte [] buffer, long offset, int value)
{
if ((offset + 2) >= buffer.Length)
throw new IndexOutOfRangeException();
buffer[offset] = (byte)((value >> 8) & 0xff);
buffer[offset + 1] = (byte)(value & 0xff);
}
}